exceljs.js 1.8 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ExcelJS = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. "use strict";
  3. const fs = require('fs');
  4. const fastCsv = require('fast-csv');
  5. const customParseFormat = require('dayjs/plugin/customParseFormat');
  6. const utc = require('dayjs/plugin/utc');
  7. const dayjs = require('dayjs').extend(customParseFormat).extend(utc);
  8. const StreamBuf = require('../utils/stream-buf');
  9. const {
  10. fs: {
  11. exists
  12. }
  13. } = require('../utils/utils');
  14. /* eslint-disable quote-props */
  15. const SpecialValues = {
  16. true: true,
  17. false: false,
  18. '#N/A': {
  19. error: '#N/A'
  20. },
  21. '#REF!': {
  22. error: '#REF!'
  23. },
  24. '#NAME?': {
  25. error: '#NAME?'
  26. },
  27. '#DIV/0!': {
  28. error: '#DIV/0!'
  29. },
  30. '#NULL!': {
  31. error: '#NULL!'
  32. },
  33. '#VALUE!': {
  34. error: '#VALUE!'
  35. },
  36. '#NUM!': {
  37. error: '#NUM!'
  38. }
  39. };
  40. /* eslint-ensable quote-props */
  41. class CSV {
  42. constructor(workbook) {
  43. this.workbook = workbook;
  44. this.worksheet = null;
  45. }
  46. async readFile(filename, options) {
  47. options = options || {};
  48. if (!(await exists(filename))) {
  49. throw new Error(`File not found: ${filename}`);
  50. }
  51. const stream = fs.createReadStream(filename);
  52. const worksheet = await this.read(stream, options);
  53. stream.close();
  54. return worksheet;
  55. }
  56. read(stream, options) {
  57. options = options || {};
  58. return new Promise((resolve, reject) => {
  59. const worksheet = this.workbook.addWorksheet(options.sheetName);
  60. const dateFormats = options.dateFormats || ['YYYY-MM-DD[T]HH:mm:ssZ', 'YYYY-MM-DD[T]HH:mm:ss', 'MM-DD-YYYY', 'YYYY-MM-DD'];
  61. const map = options.map || function (datum) {
  62. if (datum === '') {
  63. return null;
  64. }
  65. const datumNumber = Number(datum);
  66. if (!Number.isNaN(datumNumber) && datumNumber !== Infinity) {
  67. return datumNumber;
  68. }
  69. const dt = dateFormats.reduce((matchingDate, currentDateFormat) => {
  70. if (matchingDate) {
  71. return matchingDate;
  72. }
  73. const dayjsObj = dayjs(datum, currentDateFormat, true);
  74. if (dayjsObj.isValid()) {
  75. return dayjsObj;
  76. }
  77. return null;
  78. }, null);
  79. if (dt) {
  80. return new Date(dt.valueOf());
  81. }
  82. const special = SpecialValues[datum];
  83. if (special !== undefined) {
  84. return special;
  85. }
  86. return datum;
  87. };
  88. const csvStream = fastCsv.parse(options.parserOptions).on('data', data => {
  89. worksheet.addRow(data.map(map));
  90. }).on('end', () => {
  91. csvStream.emit('worksheet', worksheet);
  92. });
  93. csvStream.on('worksheet', resolve).on('error', reject);
  94. stream.pipe(csvStream);
  95. });
  96. }
  97. /**
  98. * @deprecated since version 4.0. You should use `CSV#read` instead. Please follow upgrade instruction: https://github.com/exceljs/exceljs/blob/master/UPGRADE-4.0.md
  99. */
  100. createInputStream() {
  101. throw new Error('`CSV#createInputStream` is deprecated. You should use `CSV#read` instead. This method will be removed in version 5.0. Please follow upgrade instruction: https://github.com/exceljs/exceljs/blob/master/UPGRADE-4.0.md');
  102. }
  103. write(stream, options) {
  104. return new Promise((resolve, reject) => {
  105. options = options || {};
  106. // const encoding = options.encoding || 'utf8';
  107. // const separator = options.separator || ',';
  108. // const quoteChar = options.quoteChar || '\'';
  109. const worksheet = this.workbook.getWorksheet(options.sheetName || options.sheetId);
  110. const csvStream = fastCsv.format(options.formatterOptions);
  111. stream.on('finish', () => {
  112. resolve();
  113. });
  114. csvStream.on('error', reject);
  115. csvStream.pipe(stream);
  116. const {
  117. dateFormat,
  118. dateUTC
  119. } = options;
  120. const map = options.map || (value => {
  121. if (value) {
  122. if (value.text || value.hyperlink) {
  123. return value.hyperlink || value.text || '';
  124. }
  125. if (value.formula || value.result) {
  126. return value.result || '';
  127. }
  128. if (value instanceof Date) {
  129. if (dateFormat) {
  130. return dateUTC ? dayjs.utc(value).format(dateFormat) : dayjs(value).format(dateFormat);
  131. }
  132. return dateUTC ? dayjs.utc(value).format() : dayjs(value).format();
  133. }
  134. if (value.error) {
  135. return value.error;
  136. }
  137. if (typeof value === 'object') {
  138. return JSON.stringify(value);
  139. }
  140. }
  141. return value;
  142. });
  143. const includeEmptyRows = options.includeEmptyRows === undefined || options.includeEmptyRows;
  144. let lastRow = 1;
  145. if (worksheet) {
  146. worksheet.eachRow((row, rowNumber) => {
  147. if (includeEmptyRows) {
  148. while (lastRow++ < rowNumber - 1) {
  149. csvStream.write([]);
  150. }
  151. }
  152. const {
  153. values
  154. } = row;
  155. values.shift();
  156. csvStream.write(values.map(map));
  157. lastRow = rowNumber;
  158. });
  159. }
  160. csvStream.end();
  161. });
  162. }
  163. writeFile(filename, options) {
  164. options = options || {};
  165. const streamOptions = {
  166. encoding: options.encoding || 'utf8'
  167. };
  168. const stream = fs.createWriteStream(filename, streamOptions);
  169. return this.write(stream, options);
  170. }
  171. async writeBuffer(options) {
  172. const stream = new StreamBuf();
  173. await this.write(stream, options);
  174. return stream.read();
  175. }
  176. }
  177. module.exports = CSV;
  178. },{"../utils/stream-buf":24,"../utils/utils":27,"dayjs":391,"dayjs/plugin/customParseFormat":392,"dayjs/plugin/utc":393,"fast-csv":424,"fs":216}],2:[function(require,module,exports){
  179. 'use strict';
  180. const colCache = require('../utils/col-cache');
  181. class Anchor {
  182. constructor(worksheet, address) {
  183. let offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  184. this.worksheet = worksheet;
  185. if (!address) {
  186. this.nativeCol = 0;
  187. this.nativeColOff = 0;
  188. this.nativeRow = 0;
  189. this.nativeRowOff = 0;
  190. } else if (typeof address === 'string') {
  191. const decoded = colCache.decodeAddress(address);
  192. this.nativeCol = decoded.col + offset;
  193. this.nativeColOff = 0;
  194. this.nativeRow = decoded.row + offset;
  195. this.nativeRowOff = 0;
  196. } else if (address.nativeCol !== undefined) {
  197. this.nativeCol = address.nativeCol || 0;
  198. this.nativeColOff = address.nativeColOff || 0;
  199. this.nativeRow = address.nativeRow || 0;
  200. this.nativeRowOff = address.nativeRowOff || 0;
  201. } else if (address.col !== undefined) {
  202. this.col = address.col + offset;
  203. this.row = address.row + offset;
  204. } else {
  205. this.nativeCol = 0;
  206. this.nativeColOff = 0;
  207. this.nativeRow = 0;
  208. this.nativeRowOff = 0;
  209. }
  210. }
  211. static asInstance(model) {
  212. return model instanceof Anchor || model == null ? model : new Anchor(model);
  213. }
  214. get col() {
  215. return this.nativeCol + Math.min(this.colWidth - 1, this.nativeColOff) / this.colWidth;
  216. }
  217. set col(v) {
  218. this.nativeCol = Math.floor(v);
  219. this.nativeColOff = Math.floor((v - this.nativeCol) * this.colWidth);
  220. }
  221. get row() {
  222. return this.nativeRow + Math.min(this.rowHeight - 1, this.nativeRowOff) / this.rowHeight;
  223. }
  224. set row(v) {
  225. this.nativeRow = Math.floor(v);
  226. this.nativeRowOff = Math.floor((v - this.nativeRow) * this.rowHeight);
  227. }
  228. get colWidth() {
  229. return this.worksheet && this.worksheet.getColumn(this.nativeCol + 1) && this.worksheet.getColumn(this.nativeCol + 1).isCustomWidth ? Math.floor(this.worksheet.getColumn(this.nativeCol + 1).width * 10000) : 640000;
  230. }
  231. get rowHeight() {
  232. return this.worksheet && this.worksheet.getRow(this.nativeRow + 1) && this.worksheet.getRow(this.nativeRow + 1).height ? Math.floor(this.worksheet.getRow(this.nativeRow + 1).height * 10000) : 180000;
  233. }
  234. get model() {
  235. return {
  236. nativeCol: this.nativeCol,
  237. nativeColOff: this.nativeColOff,
  238. nativeRow: this.nativeRow,
  239. nativeRowOff: this.nativeRowOff
  240. };
  241. }
  242. set model(value) {
  243. this.nativeCol = value.nativeCol;
  244. this.nativeColOff = value.nativeColOff;
  245. this.nativeRow = value.nativeRow;
  246. this.nativeRowOff = value.nativeRowOff;
  247. }
  248. }
  249. module.exports = Anchor;
  250. },{"../utils/col-cache":19}],3:[function(require,module,exports){
  251. "use strict";
  252. /* eslint-disable max-classes-per-file */
  253. const colCache = require('../utils/col-cache');
  254. const _ = require('../utils/under-dash');
  255. const Enums = require('./enums');
  256. const {
  257. slideFormula
  258. } = require('../utils/shared-formula');
  259. const Note = require('./note');
  260. // Cell requirements
  261. // Operate inside a worksheet
  262. // Store and retrieve a value with a range of types: text, number, date, hyperlink, reference, formula, etc.
  263. // Manage/use and manipulate cell format either as local to cell or inherited from column or row.
  264. class Cell {
  265. constructor(row, column, address) {
  266. if (!row || !column) {
  267. throw new Error('A Cell needs a Row');
  268. }
  269. this._row = row;
  270. this._column = column;
  271. colCache.validateAddress(address);
  272. this._address = address;
  273. // TODO: lazy evaluation of this._value
  274. this._value = Value.create(Cell.Types.Null, this);
  275. this.style = this._mergeStyle(row.style, column.style, {});
  276. this._mergeCount = 0;
  277. }
  278. get worksheet() {
  279. return this._row.worksheet;
  280. }
  281. get workbook() {
  282. return this._row.worksheet.workbook;
  283. }
  284. // help GC by removing cyclic (and other) references
  285. destroy() {
  286. delete this.style;
  287. delete this._value;
  288. delete this._row;
  289. delete this._column;
  290. delete this._address;
  291. }
  292. // =========================================================================
  293. // Styles stuff
  294. get numFmt() {
  295. return this.style.numFmt;
  296. }
  297. set numFmt(value) {
  298. this.style.numFmt = value;
  299. }
  300. get font() {
  301. return this.style.font;
  302. }
  303. set font(value) {
  304. this.style.font = value;
  305. }
  306. get alignment() {
  307. return this.style.alignment;
  308. }
  309. set alignment(value) {
  310. this.style.alignment = value;
  311. }
  312. get border() {
  313. return this.style.border;
  314. }
  315. set border(value) {
  316. this.style.border = value;
  317. }
  318. get fill() {
  319. return this.style.fill;
  320. }
  321. set fill(value) {
  322. this.style.fill = value;
  323. }
  324. get protection() {
  325. return this.style.protection;
  326. }
  327. set protection(value) {
  328. this.style.protection = value;
  329. }
  330. _mergeStyle(rowStyle, colStyle, style) {
  331. const numFmt = rowStyle && rowStyle.numFmt || colStyle && colStyle.numFmt;
  332. if (numFmt) style.numFmt = numFmt;
  333. const font = rowStyle && rowStyle.font || colStyle && colStyle.font;
  334. if (font) style.font = font;
  335. const alignment = rowStyle && rowStyle.alignment || colStyle && colStyle.alignment;
  336. if (alignment) style.alignment = alignment;
  337. const border = rowStyle && rowStyle.border || colStyle && colStyle.border;
  338. if (border) style.border = border;
  339. const fill = rowStyle && rowStyle.fill || colStyle && colStyle.fill;
  340. if (fill) style.fill = fill;
  341. const protection = rowStyle && rowStyle.protection || colStyle && colStyle.protection;
  342. if (protection) style.protection = protection;
  343. return style;
  344. }
  345. // =========================================================================
  346. // return the address for this cell
  347. get address() {
  348. return this._address;
  349. }
  350. get row() {
  351. return this._row.number;
  352. }
  353. get col() {
  354. return this._column.number;
  355. }
  356. get $col$row() {
  357. return `$${this._column.letter}$${this.row}`;
  358. }
  359. // =========================================================================
  360. // Value stuff
  361. get type() {
  362. return this._value.type;
  363. }
  364. get effectiveType() {
  365. return this._value.effectiveType;
  366. }
  367. toCsvString() {
  368. return this._value.toCsvString();
  369. }
  370. // =========================================================================
  371. // Merge stuff
  372. addMergeRef() {
  373. this._mergeCount++;
  374. }
  375. releaseMergeRef() {
  376. this._mergeCount--;
  377. }
  378. get isMerged() {
  379. return this._mergeCount > 0 || this.type === Cell.Types.Merge;
  380. }
  381. merge(master, ignoreStyle) {
  382. this._value.release();
  383. this._value = Value.create(Cell.Types.Merge, this, master);
  384. if (!ignoreStyle) {
  385. this.style = master.style;
  386. }
  387. }
  388. unmerge() {
  389. if (this.type === Cell.Types.Merge) {
  390. this._value.release();
  391. this._value = Value.create(Cell.Types.Null, this);
  392. this.style = this._mergeStyle(this._row.style, this._column.style, {});
  393. }
  394. }
  395. isMergedTo(master) {
  396. if (this._value.type !== Cell.Types.Merge) return false;
  397. return this._value.isMergedTo(master);
  398. }
  399. get master() {
  400. if (this.type === Cell.Types.Merge) {
  401. return this._value.master;
  402. }
  403. return this; // an unmerged cell is its own master
  404. }
  405. get isHyperlink() {
  406. return this._value.type === Cell.Types.Hyperlink;
  407. }
  408. get hyperlink() {
  409. return this._value.hyperlink;
  410. }
  411. // return the value
  412. get value() {
  413. return this._value.value;
  414. }
  415. // set the value - can be number, string or raw
  416. set value(v) {
  417. // special case - merge cells set their master's value
  418. if (this.type === Cell.Types.Merge) {
  419. this._value.master.value = v;
  420. return;
  421. }
  422. this._value.release();
  423. // assign value
  424. this._value = Value.create(Value.getType(v), this, v);
  425. }
  426. get note() {
  427. return this._comment && this._comment.note;
  428. }
  429. set note(note) {
  430. this._comment = new Note(note);
  431. }
  432. get text() {
  433. return this._value.toString();
  434. }
  435. get html() {
  436. return _.escapeHtml(this.text);
  437. }
  438. toString() {
  439. return this.text;
  440. }
  441. _upgradeToHyperlink(hyperlink) {
  442. // if this cell is a string, turn it into a Hyperlink
  443. if (this.type === Cell.Types.String) {
  444. this._value = Value.create(Cell.Types.Hyperlink, this, {
  445. text: this._value.value,
  446. hyperlink
  447. });
  448. }
  449. }
  450. // =========================================================================
  451. // Formula stuff
  452. get formula() {
  453. return this._value.formula;
  454. }
  455. get result() {
  456. return this._value.result;
  457. }
  458. get formulaType() {
  459. return this._value.formulaType;
  460. }
  461. // =========================================================================
  462. // Name stuff
  463. get fullAddress() {
  464. const {
  465. worksheet
  466. } = this._row;
  467. return {
  468. sheetName: worksheet.name,
  469. address: this.address,
  470. row: this.row,
  471. col: this.col
  472. };
  473. }
  474. get name() {
  475. return this.names[0];
  476. }
  477. set name(value) {
  478. this.names = [value];
  479. }
  480. get names() {
  481. return this.workbook.definedNames.getNamesEx(this.fullAddress);
  482. }
  483. set names(value) {
  484. const {
  485. definedNames
  486. } = this.workbook;
  487. definedNames.removeAllNames(this.fullAddress);
  488. value.forEach(name => {
  489. definedNames.addEx(this.fullAddress, name);
  490. });
  491. }
  492. addName(name) {
  493. this.workbook.definedNames.addEx(this.fullAddress, name);
  494. }
  495. removeName(name) {
  496. this.workbook.definedNames.removeEx(this.fullAddress, name);
  497. }
  498. removeAllNames() {
  499. this.workbook.definedNames.removeAllNames(this.fullAddress);
  500. }
  501. // =========================================================================
  502. // Data Validation stuff
  503. get _dataValidations() {
  504. return this.worksheet.dataValidations;
  505. }
  506. get dataValidation() {
  507. return this._dataValidations.find(this.address);
  508. }
  509. set dataValidation(value) {
  510. this._dataValidations.add(this.address, value);
  511. }
  512. // =========================================================================
  513. // Model stuff
  514. get model() {
  515. const {
  516. model
  517. } = this._value;
  518. model.style = this.style;
  519. if (this._comment) {
  520. model.comment = this._comment.model;
  521. }
  522. return model;
  523. }
  524. set model(value) {
  525. this._value.release();
  526. this._value = Value.create(value.type, this);
  527. this._value.model = value;
  528. if (value.comment) {
  529. switch (value.comment.type) {
  530. case 'note':
  531. this._comment = Note.fromModel(value.comment);
  532. break;
  533. }
  534. }
  535. if (value.style) {
  536. this.style = value.style;
  537. } else {
  538. this.style = {};
  539. }
  540. }
  541. }
  542. Cell.Types = Enums.ValueType;
  543. // =============================================================================
  544. // Internal Value Types
  545. class NullValue {
  546. constructor(cell) {
  547. this.model = {
  548. address: cell.address,
  549. type: Cell.Types.Null
  550. };
  551. }
  552. get value() {
  553. return null;
  554. }
  555. set value(value) {
  556. // nothing to do
  557. }
  558. get type() {
  559. return Cell.Types.Null;
  560. }
  561. get effectiveType() {
  562. return Cell.Types.Null;
  563. }
  564. get address() {
  565. return this.model.address;
  566. }
  567. set address(value) {
  568. this.model.address = value;
  569. }
  570. toCsvString() {
  571. return '';
  572. }
  573. release() {}
  574. toString() {
  575. return '';
  576. }
  577. }
  578. class NumberValue {
  579. constructor(cell, value) {
  580. this.model = {
  581. address: cell.address,
  582. type: Cell.Types.Number,
  583. value
  584. };
  585. }
  586. get value() {
  587. return this.model.value;
  588. }
  589. set value(value) {
  590. this.model.value = value;
  591. }
  592. get type() {
  593. return Cell.Types.Number;
  594. }
  595. get effectiveType() {
  596. return Cell.Types.Number;
  597. }
  598. get address() {
  599. return this.model.address;
  600. }
  601. set address(value) {
  602. this.model.address = value;
  603. }
  604. toCsvString() {
  605. return this.model.value.toString();
  606. }
  607. release() {}
  608. toString() {
  609. return this.model.value.toString();
  610. }
  611. }
  612. class StringValue {
  613. constructor(cell, value) {
  614. this.model = {
  615. address: cell.address,
  616. type: Cell.Types.String,
  617. value
  618. };
  619. }
  620. get value() {
  621. return this.model.value;
  622. }
  623. set value(value) {
  624. this.model.value = value;
  625. }
  626. get type() {
  627. return Cell.Types.String;
  628. }
  629. get effectiveType() {
  630. return Cell.Types.String;
  631. }
  632. get address() {
  633. return this.model.address;
  634. }
  635. set address(value) {
  636. this.model.address = value;
  637. }
  638. toCsvString() {
  639. return `"${this.model.value.replace(/"/g, '""')}"`;
  640. }
  641. release() {}
  642. toString() {
  643. return this.model.value;
  644. }
  645. }
  646. class RichTextValue {
  647. constructor(cell, value) {
  648. this.model = {
  649. address: cell.address,
  650. type: Cell.Types.String,
  651. value
  652. };
  653. }
  654. get value() {
  655. return this.model.value;
  656. }
  657. set value(value) {
  658. this.model.value = value;
  659. }
  660. toString() {
  661. return this.model.value.richText.map(t => t.text).join('');
  662. }
  663. get type() {
  664. return Cell.Types.RichText;
  665. }
  666. get effectiveType() {
  667. return Cell.Types.RichText;
  668. }
  669. get address() {
  670. return this.model.address;
  671. }
  672. set address(value) {
  673. this.model.address = value;
  674. }
  675. toCsvString() {
  676. return `"${this.text.replace(/"/g, '""')}"`;
  677. }
  678. release() {}
  679. }
  680. class DateValue {
  681. constructor(cell, value) {
  682. this.model = {
  683. address: cell.address,
  684. type: Cell.Types.Date,
  685. value
  686. };
  687. }
  688. get value() {
  689. return this.model.value;
  690. }
  691. set value(value) {
  692. this.model.value = value;
  693. }
  694. get type() {
  695. return Cell.Types.Date;
  696. }
  697. get effectiveType() {
  698. return Cell.Types.Date;
  699. }
  700. get address() {
  701. return this.model.address;
  702. }
  703. set address(value) {
  704. this.model.address = value;
  705. }
  706. toCsvString() {
  707. return this.model.value.toISOString();
  708. }
  709. release() {}
  710. toString() {
  711. return this.model.value.toString();
  712. }
  713. }
  714. class HyperlinkValue {
  715. constructor(cell, value) {
  716. this.model = {
  717. address: cell.address,
  718. type: Cell.Types.Hyperlink,
  719. text: value ? value.text : undefined,
  720. hyperlink: value ? value.hyperlink : undefined
  721. };
  722. if (value && value.tooltip) {
  723. this.model.tooltip = value.tooltip;
  724. }
  725. }
  726. get value() {
  727. const v = {
  728. text: this.model.text,
  729. hyperlink: this.model.hyperlink
  730. };
  731. if (this.model.tooltip) {
  732. v.tooltip = this.model.tooltip;
  733. }
  734. return v;
  735. }
  736. set value(value) {
  737. this.model = {
  738. text: value.text,
  739. hyperlink: value.hyperlink
  740. };
  741. if (value.tooltip) {
  742. this.model.tooltip = value.tooltip;
  743. }
  744. }
  745. get text() {
  746. return this.model.text;
  747. }
  748. set text(value) {
  749. this.model.text = value;
  750. }
  751. /*
  752. get tooltip() {
  753. return this.model.tooltip;
  754. }
  755. set tooltip(value) {
  756. this.model.tooltip = value;
  757. } */
  758. get hyperlink() {
  759. return this.model.hyperlink;
  760. }
  761. set hyperlink(value) {
  762. this.model.hyperlink = value;
  763. }
  764. get type() {
  765. return Cell.Types.Hyperlink;
  766. }
  767. get effectiveType() {
  768. return Cell.Types.Hyperlink;
  769. }
  770. get address() {
  771. return this.model.address;
  772. }
  773. set address(value) {
  774. this.model.address = value;
  775. }
  776. toCsvString() {
  777. return this.model.hyperlink;
  778. }
  779. release() {}
  780. toString() {
  781. return this.model.text;
  782. }
  783. }
  784. class MergeValue {
  785. constructor(cell, master) {
  786. this.model = {
  787. address: cell.address,
  788. type: Cell.Types.Merge,
  789. master: master ? master.address : undefined
  790. };
  791. this._master = master;
  792. if (master) {
  793. master.addMergeRef();
  794. }
  795. }
  796. get value() {
  797. return this._master.value;
  798. }
  799. set value(value) {
  800. if (value instanceof Cell) {
  801. if (this._master) {
  802. this._master.releaseMergeRef();
  803. }
  804. value.addMergeRef();
  805. this._master = value;
  806. } else {
  807. this._master.value = value;
  808. }
  809. }
  810. isMergedTo(master) {
  811. return master === this._master;
  812. }
  813. get master() {
  814. return this._master;
  815. }
  816. get type() {
  817. return Cell.Types.Merge;
  818. }
  819. get effectiveType() {
  820. return this._master.effectiveType;
  821. }
  822. get address() {
  823. return this.model.address;
  824. }
  825. set address(value) {
  826. this.model.address = value;
  827. }
  828. toCsvString() {
  829. return '';
  830. }
  831. release() {
  832. this._master.releaseMergeRef();
  833. }
  834. toString() {
  835. return this.value.toString();
  836. }
  837. }
  838. class FormulaValue {
  839. constructor(cell, value) {
  840. this.cell = cell;
  841. this.model = {
  842. address: cell.address,
  843. type: Cell.Types.Formula,
  844. shareType: value ? value.shareType : undefined,
  845. ref: value ? value.ref : undefined,
  846. formula: value ? value.formula : undefined,
  847. sharedFormula: value ? value.sharedFormula : undefined,
  848. result: value ? value.result : undefined
  849. };
  850. }
  851. _copyModel(model) {
  852. const copy = {};
  853. const cp = name => {
  854. const value = model[name];
  855. if (value) {
  856. copy[name] = value;
  857. }
  858. };
  859. cp('formula');
  860. cp('result');
  861. cp('ref');
  862. cp('shareType');
  863. cp('sharedFormula');
  864. return copy;
  865. }
  866. get value() {
  867. return this._copyModel(this.model);
  868. }
  869. set value(value) {
  870. this.model = this._copyModel(value);
  871. }
  872. validate(value) {
  873. switch (Value.getType(value)) {
  874. case Cell.Types.Null:
  875. case Cell.Types.String:
  876. case Cell.Types.Number:
  877. case Cell.Types.Date:
  878. break;
  879. case Cell.Types.Hyperlink:
  880. case Cell.Types.Formula:
  881. default:
  882. throw new Error('Cannot process that type of result value');
  883. }
  884. }
  885. get dependencies() {
  886. // find all the ranges and cells mentioned in the formula
  887. const ranges = this.formula.match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g);
  888. const cells = this.formula.replace(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}:[A-Z]{1,3}\d{1,4}/g, '').match(/([a-zA-Z0-9]+!)?[A-Z]{1,3}\d{1,4}/g);
  889. return {
  890. ranges,
  891. cells
  892. };
  893. }
  894. get formula() {
  895. return this.model.formula || this._getTranslatedFormula();
  896. }
  897. set formula(value) {
  898. this.model.formula = value;
  899. }
  900. get formulaType() {
  901. if (this.model.formula) {
  902. return Enums.FormulaType.Master;
  903. }
  904. if (this.model.sharedFormula) {
  905. return Enums.FormulaType.Shared;
  906. }
  907. return Enums.FormulaType.None;
  908. }
  909. get result() {
  910. return this.model.result;
  911. }
  912. set result(value) {
  913. this.model.result = value;
  914. }
  915. get type() {
  916. return Cell.Types.Formula;
  917. }
  918. get effectiveType() {
  919. const v = this.model.result;
  920. if (v === null || v === undefined) {
  921. return Enums.ValueType.Null;
  922. }
  923. if (v instanceof String || typeof v === 'string') {
  924. return Enums.ValueType.String;
  925. }
  926. if (typeof v === 'number') {
  927. return Enums.ValueType.Number;
  928. }
  929. if (v instanceof Date) {
  930. return Enums.ValueType.Date;
  931. }
  932. if (v.text && v.hyperlink) {
  933. return Enums.ValueType.Hyperlink;
  934. }
  935. if (v.formula) {
  936. return Enums.ValueType.Formula;
  937. }
  938. return Enums.ValueType.Null;
  939. }
  940. get address() {
  941. return this.model.address;
  942. }
  943. set address(value) {
  944. this.model.address = value;
  945. }
  946. _getTranslatedFormula() {
  947. if (!this._translatedFormula && this.model.sharedFormula) {
  948. const {
  949. worksheet
  950. } = this.cell;
  951. const master = worksheet.findCell(this.model.sharedFormula);
  952. this._translatedFormula = master && slideFormula(master.formula, master.address, this.model.address);
  953. }
  954. return this._translatedFormula;
  955. }
  956. toCsvString() {
  957. return `${this.model.result || ''}`;
  958. }
  959. release() {}
  960. toString() {
  961. return this.model.result ? this.model.result.toString() : '';
  962. }
  963. }
  964. class SharedStringValue {
  965. constructor(cell, value) {
  966. this.model = {
  967. address: cell.address,
  968. type: Cell.Types.SharedString,
  969. value
  970. };
  971. }
  972. get value() {
  973. return this.model.value;
  974. }
  975. set value(value) {
  976. this.model.value = value;
  977. }
  978. get type() {
  979. return Cell.Types.SharedString;
  980. }
  981. get effectiveType() {
  982. return Cell.Types.SharedString;
  983. }
  984. get address() {
  985. return this.model.address;
  986. }
  987. set address(value) {
  988. this.model.address = value;
  989. }
  990. toCsvString() {
  991. return this.model.value.toString();
  992. }
  993. release() {}
  994. toString() {
  995. return this.model.value.toString();
  996. }
  997. }
  998. class BooleanValue {
  999. constructor(cell, value) {
  1000. this.model = {
  1001. address: cell.address,
  1002. type: Cell.Types.Boolean,
  1003. value
  1004. };
  1005. }
  1006. get value() {
  1007. return this.model.value;
  1008. }
  1009. set value(value) {
  1010. this.model.value = value;
  1011. }
  1012. get type() {
  1013. return Cell.Types.Boolean;
  1014. }
  1015. get effectiveType() {
  1016. return Cell.Types.Boolean;
  1017. }
  1018. get address() {
  1019. return this.model.address;
  1020. }
  1021. set address(value) {
  1022. this.model.address = value;
  1023. }
  1024. toCsvString() {
  1025. return this.model.value ? 1 : 0;
  1026. }
  1027. release() {}
  1028. toString() {
  1029. return this.model.value.toString();
  1030. }
  1031. }
  1032. class ErrorValue {
  1033. constructor(cell, value) {
  1034. this.model = {
  1035. address: cell.address,
  1036. type: Cell.Types.Error,
  1037. value
  1038. };
  1039. }
  1040. get value() {
  1041. return this.model.value;
  1042. }
  1043. set value(value) {
  1044. this.model.value = value;
  1045. }
  1046. get type() {
  1047. return Cell.Types.Error;
  1048. }
  1049. get effectiveType() {
  1050. return Cell.Types.Error;
  1051. }
  1052. get address() {
  1053. return this.model.address;
  1054. }
  1055. set address(value) {
  1056. this.model.address = value;
  1057. }
  1058. toCsvString() {
  1059. return this.toString();
  1060. }
  1061. release() {}
  1062. toString() {
  1063. return this.model.value.error.toString();
  1064. }
  1065. }
  1066. class JSONValue {
  1067. constructor(cell, value) {
  1068. this.model = {
  1069. address: cell.address,
  1070. type: Cell.Types.String,
  1071. value: JSON.stringify(value),
  1072. rawValue: value
  1073. };
  1074. }
  1075. get value() {
  1076. return this.model.rawValue;
  1077. }
  1078. set value(value) {
  1079. this.model.rawValue = value;
  1080. this.model.value = JSON.stringify(value);
  1081. }
  1082. get type() {
  1083. return Cell.Types.String;
  1084. }
  1085. get effectiveType() {
  1086. return Cell.Types.String;
  1087. }
  1088. get address() {
  1089. return this.model.address;
  1090. }
  1091. set address(value) {
  1092. this.model.address = value;
  1093. }
  1094. toCsvString() {
  1095. return this.model.value;
  1096. }
  1097. release() {}
  1098. toString() {
  1099. return this.model.value;
  1100. }
  1101. }
  1102. // Value is a place to hold common static Value type functions
  1103. const Value = {
  1104. getType(value) {
  1105. if (value === null || value === undefined) {
  1106. return Cell.Types.Null;
  1107. }
  1108. if (value instanceof String || typeof value === 'string') {
  1109. return Cell.Types.String;
  1110. }
  1111. if (typeof value === 'number') {
  1112. return Cell.Types.Number;
  1113. }
  1114. if (typeof value === 'boolean') {
  1115. return Cell.Types.Boolean;
  1116. }
  1117. if (value instanceof Date) {
  1118. return Cell.Types.Date;
  1119. }
  1120. if (value.text && value.hyperlink) {
  1121. return Cell.Types.Hyperlink;
  1122. }
  1123. if (value.formula || value.sharedFormula) {
  1124. return Cell.Types.Formula;
  1125. }
  1126. if (value.richText) {
  1127. return Cell.Types.RichText;
  1128. }
  1129. if (value.sharedString) {
  1130. return Cell.Types.SharedString;
  1131. }
  1132. if (value.error) {
  1133. return Cell.Types.Error;
  1134. }
  1135. return Cell.Types.JSON;
  1136. },
  1137. // map valueType to constructor
  1138. types: [{
  1139. t: Cell.Types.Null,
  1140. f: NullValue
  1141. }, {
  1142. t: Cell.Types.Number,
  1143. f: NumberValue
  1144. }, {
  1145. t: Cell.Types.String,
  1146. f: StringValue
  1147. }, {
  1148. t: Cell.Types.Date,
  1149. f: DateValue
  1150. }, {
  1151. t: Cell.Types.Hyperlink,
  1152. f: HyperlinkValue
  1153. }, {
  1154. t: Cell.Types.Formula,
  1155. f: FormulaValue
  1156. }, {
  1157. t: Cell.Types.Merge,
  1158. f: MergeValue
  1159. }, {
  1160. t: Cell.Types.JSON,
  1161. f: JSONValue
  1162. }, {
  1163. t: Cell.Types.SharedString,
  1164. f: SharedStringValue
  1165. }, {
  1166. t: Cell.Types.RichText,
  1167. f: RichTextValue
  1168. }, {
  1169. t: Cell.Types.Boolean,
  1170. f: BooleanValue
  1171. }, {
  1172. t: Cell.Types.Error,
  1173. f: ErrorValue
  1174. }].reduce((p, t) => {
  1175. p[t.t] = t.f;
  1176. return p;
  1177. }, []),
  1178. create(type, cell, value) {
  1179. const T = this.types[type];
  1180. if (!T) {
  1181. throw new Error(`Could not create Value of type ${type}`);
  1182. }
  1183. return new T(cell, value);
  1184. }
  1185. };
  1186. module.exports = Cell;
  1187. },{"../utils/col-cache":19,"../utils/shared-formula":23,"../utils/under-dash":26,"./enums":7,"./note":9}],4:[function(require,module,exports){
  1188. 'use strict';
  1189. const _ = require('../utils/under-dash');
  1190. const Enums = require('./enums');
  1191. const colCache = require('../utils/col-cache');
  1192. const DEFAULT_COLUMN_WIDTH = 9;
  1193. // Column defines the column properties for 1 column.
  1194. // This includes header rows, widths, key, (style), etc.
  1195. // Worksheet will condense the columns as appropriate during serialization
  1196. class Column {
  1197. constructor(worksheet, number, defn) {
  1198. this._worksheet = worksheet;
  1199. this._number = number;
  1200. if (defn !== false) {
  1201. // sometimes defn will follow
  1202. this.defn = defn;
  1203. }
  1204. }
  1205. get number() {
  1206. return this._number;
  1207. }
  1208. get worksheet() {
  1209. return this._worksheet;
  1210. }
  1211. get letter() {
  1212. return colCache.n2l(this._number);
  1213. }
  1214. get isCustomWidth() {
  1215. return this.width !== undefined && this.width !== DEFAULT_COLUMN_WIDTH;
  1216. }
  1217. get defn() {
  1218. return {
  1219. header: this._header,
  1220. key: this.key,
  1221. width: this.width,
  1222. style: this.style,
  1223. hidden: this.hidden,
  1224. outlineLevel: this.outlineLevel
  1225. };
  1226. }
  1227. set defn(value) {
  1228. if (value) {
  1229. this.key = value.key;
  1230. this.width = value.width !== undefined ? value.width : DEFAULT_COLUMN_WIDTH;
  1231. this.outlineLevel = value.outlineLevel;
  1232. if (value.style) {
  1233. this.style = value.style;
  1234. } else {
  1235. this.style = {};
  1236. }
  1237. // headers must be set after style
  1238. this.header = value.header;
  1239. this._hidden = !!value.hidden;
  1240. } else {
  1241. delete this._header;
  1242. delete this._key;
  1243. delete this.width;
  1244. this.style = {};
  1245. this.outlineLevel = 0;
  1246. }
  1247. }
  1248. get headers() {
  1249. return this._header && this._header instanceof Array ? this._header : [this._header];
  1250. }
  1251. get header() {
  1252. return this._header;
  1253. }
  1254. set header(value) {
  1255. if (value !== undefined) {
  1256. this._header = value;
  1257. this.headers.forEach((text, index) => {
  1258. this._worksheet.getCell(index + 1, this.number).value = text;
  1259. });
  1260. } else {
  1261. this._header = undefined;
  1262. }
  1263. }
  1264. get key() {
  1265. return this._key;
  1266. }
  1267. set key(value) {
  1268. const column = this._key && this._worksheet.getColumnKey(this._key);
  1269. if (column === this) {
  1270. this._worksheet.deleteColumnKey(this._key);
  1271. }
  1272. this._key = value;
  1273. if (value) {
  1274. this._worksheet.setColumnKey(this._key, this);
  1275. }
  1276. }
  1277. get hidden() {
  1278. return !!this._hidden;
  1279. }
  1280. set hidden(value) {
  1281. this._hidden = value;
  1282. }
  1283. get outlineLevel() {
  1284. return this._outlineLevel || 0;
  1285. }
  1286. set outlineLevel(value) {
  1287. this._outlineLevel = value;
  1288. }
  1289. get collapsed() {
  1290. return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelCol);
  1291. }
  1292. toString() {
  1293. return JSON.stringify({
  1294. key: this.key,
  1295. width: this.width,
  1296. headers: this.headers.length ? this.headers : undefined
  1297. });
  1298. }
  1299. equivalentTo(other) {
  1300. return this.width === other.width && this.hidden === other.hidden && this.outlineLevel === other.outlineLevel && _.isEqual(this.style, other.style);
  1301. }
  1302. get isDefault() {
  1303. if (this.isCustomWidth) {
  1304. return false;
  1305. }
  1306. if (this.hidden) {
  1307. return false;
  1308. }
  1309. if (this.outlineLevel) {
  1310. return false;
  1311. }
  1312. const s = this.style;
  1313. if (s && (s.font || s.numFmt || s.alignment || s.border || s.fill || s.protection)) {
  1314. return false;
  1315. }
  1316. return true;
  1317. }
  1318. get headerCount() {
  1319. return this.headers.length;
  1320. }
  1321. eachCell(options, iteratee) {
  1322. const colNumber = this.number;
  1323. if (!iteratee) {
  1324. iteratee = options;
  1325. options = null;
  1326. }
  1327. this._worksheet.eachRow(options, (row, rowNumber) => {
  1328. iteratee(row.getCell(colNumber), rowNumber);
  1329. });
  1330. }
  1331. get values() {
  1332. const v = [];
  1333. this.eachCell((cell, rowNumber) => {
  1334. if (cell && cell.type !== Enums.ValueType.Null) {
  1335. v[rowNumber] = cell.value;
  1336. }
  1337. });
  1338. return v;
  1339. }
  1340. set values(v) {
  1341. if (!v) {
  1342. return;
  1343. }
  1344. const colNumber = this.number;
  1345. let offset = 0;
  1346. if (v.hasOwnProperty('0')) {
  1347. // assume contiguous array, start at row 1
  1348. offset = 1;
  1349. }
  1350. v.forEach((value, index) => {
  1351. this._worksheet.getCell(index + offset, colNumber).value = value;
  1352. });
  1353. }
  1354. // =========================================================================
  1355. // styles
  1356. _applyStyle(name, value) {
  1357. this.style[name] = value;
  1358. this.eachCell(cell => {
  1359. cell[name] = value;
  1360. });
  1361. return value;
  1362. }
  1363. get numFmt() {
  1364. return this.style.numFmt;
  1365. }
  1366. set numFmt(value) {
  1367. this._applyStyle('numFmt', value);
  1368. }
  1369. get font() {
  1370. return this.style.font;
  1371. }
  1372. set font(value) {
  1373. this._applyStyle('font', value);
  1374. }
  1375. get alignment() {
  1376. return this.style.alignment;
  1377. }
  1378. set alignment(value) {
  1379. this._applyStyle('alignment', value);
  1380. }
  1381. get protection() {
  1382. return this.style.protection;
  1383. }
  1384. set protection(value) {
  1385. this._applyStyle('protection', value);
  1386. }
  1387. get border() {
  1388. return this.style.border;
  1389. }
  1390. set border(value) {
  1391. this._applyStyle('border', value);
  1392. }
  1393. get fill() {
  1394. return this.style.fill;
  1395. }
  1396. set fill(value) {
  1397. this._applyStyle('fill', value);
  1398. }
  1399. // =============================================================================
  1400. // static functions
  1401. static toModel(columns) {
  1402. // Convert array of Column into compressed list cols
  1403. const cols = [];
  1404. let col = null;
  1405. if (columns) {
  1406. columns.forEach((column, index) => {
  1407. if (column.isDefault) {
  1408. if (col) {
  1409. col = null;
  1410. }
  1411. } else if (!col || !column.equivalentTo(col)) {
  1412. col = {
  1413. min: index + 1,
  1414. max: index + 1,
  1415. width: column.width !== undefined ? column.width : DEFAULT_COLUMN_WIDTH,
  1416. style: column.style,
  1417. isCustomWidth: column.isCustomWidth,
  1418. hidden: column.hidden,
  1419. outlineLevel: column.outlineLevel,
  1420. collapsed: column.collapsed
  1421. };
  1422. cols.push(col);
  1423. } else {
  1424. col.max = index + 1;
  1425. }
  1426. });
  1427. }
  1428. return cols.length ? cols : undefined;
  1429. }
  1430. static fromModel(worksheet, cols) {
  1431. cols = cols || [];
  1432. const columns = [];
  1433. let count = 1;
  1434. let index = 0;
  1435. /**
  1436. * sort cols by min
  1437. * If it is not sorted, the subsequent column configuration will be overwritten
  1438. * */
  1439. cols = cols.sort(function (pre, next) {
  1440. return pre.min - next.min;
  1441. });
  1442. while (index < cols.length) {
  1443. const col = cols[index++];
  1444. while (count < col.min) {
  1445. columns.push(new Column(worksheet, count++));
  1446. }
  1447. while (count <= col.max) {
  1448. columns.push(new Column(worksheet, count++, col));
  1449. }
  1450. }
  1451. return columns.length ? columns : null;
  1452. }
  1453. }
  1454. module.exports = Column;
  1455. },{"../utils/col-cache":19,"../utils/under-dash":26,"./enums":7}],5:[function(require,module,exports){
  1456. "use strict";
  1457. class DataValidations {
  1458. constructor(model) {
  1459. this.model = model || {};
  1460. }
  1461. add(address, validation) {
  1462. return this.model[address] = validation;
  1463. }
  1464. find(address) {
  1465. return this.model[address];
  1466. }
  1467. remove(address) {
  1468. this.model[address] = undefined;
  1469. }
  1470. }
  1471. module.exports = DataValidations;
  1472. },{}],6:[function(require,module,exports){
  1473. 'use strict';
  1474. const _ = require('../utils/under-dash');
  1475. const colCache = require('../utils/col-cache');
  1476. const CellMatrix = require('../utils/cell-matrix');
  1477. const Range = require('./range');
  1478. const rangeRegexp = /[$](\w+)[$](\d+)(:[$](\w+)[$](\d+))?/;
  1479. class DefinedNames {
  1480. constructor() {
  1481. this.matrixMap = {};
  1482. }
  1483. getMatrix(name) {
  1484. const matrix = this.matrixMap[name] || (this.matrixMap[name] = new CellMatrix());
  1485. return matrix;
  1486. }
  1487. // add a name to a cell. locStr in the form SheetName!$col$row or SheetName!$c1$r1:$c2:$r2
  1488. add(locStr, name) {
  1489. const location = colCache.decodeEx(locStr);
  1490. this.addEx(location, name);
  1491. }
  1492. addEx(location, name) {
  1493. const matrix = this.getMatrix(name);
  1494. if (location.top) {
  1495. for (let col = location.left; col <= location.right; col++) {
  1496. for (let row = location.top; row <= location.bottom; row++) {
  1497. const address = {
  1498. sheetName: location.sheetName,
  1499. address: colCache.n2l(col) + row,
  1500. row,
  1501. col
  1502. };
  1503. matrix.addCellEx(address);
  1504. }
  1505. }
  1506. } else {
  1507. matrix.addCellEx(location);
  1508. }
  1509. }
  1510. remove(locStr, name) {
  1511. const location = colCache.decodeEx(locStr);
  1512. this.removeEx(location, name);
  1513. }
  1514. removeEx(location, name) {
  1515. const matrix = this.getMatrix(name);
  1516. matrix.removeCellEx(location);
  1517. }
  1518. removeAllNames(location) {
  1519. _.each(this.matrixMap, matrix => {
  1520. matrix.removeCellEx(location);
  1521. });
  1522. }
  1523. forEach(callback) {
  1524. _.each(this.matrixMap, (matrix, name) => {
  1525. matrix.forEach(cell => {
  1526. callback(name, cell);
  1527. });
  1528. });
  1529. }
  1530. // get all the names of a cell
  1531. getNames(addressStr) {
  1532. return this.getNamesEx(colCache.decodeEx(addressStr));
  1533. }
  1534. getNamesEx(address) {
  1535. return _.map(this.matrixMap, (matrix, name) => matrix.findCellEx(address) && name).filter(Boolean);
  1536. }
  1537. _explore(matrix, cell) {
  1538. cell.mark = false;
  1539. const {
  1540. sheetName
  1541. } = cell;
  1542. const range = new Range(cell.row, cell.col, cell.row, cell.col, sheetName);
  1543. let x;
  1544. let y;
  1545. // grow vertical - only one col to worry about
  1546. function vGrow(yy, edge) {
  1547. const c = matrix.findCellAt(sheetName, yy, cell.col);
  1548. if (!c || !c.mark) {
  1549. return false;
  1550. }
  1551. range[edge] = yy;
  1552. c.mark = false;
  1553. return true;
  1554. }
  1555. for (y = cell.row - 1; vGrow(y, 'top'); y--);
  1556. for (y = cell.row + 1; vGrow(y, 'bottom'); y++);
  1557. // grow horizontal - ensure all rows can grow
  1558. function hGrow(xx, edge) {
  1559. const cells = [];
  1560. for (y = range.top; y <= range.bottom; y++) {
  1561. const c = matrix.findCellAt(sheetName, y, xx);
  1562. if (c && c.mark) {
  1563. cells.push(c);
  1564. } else {
  1565. return false;
  1566. }
  1567. }
  1568. range[edge] = xx;
  1569. for (let i = 0; i < cells.length; i++) {
  1570. cells[i].mark = false;
  1571. }
  1572. return true;
  1573. }
  1574. for (x = cell.col - 1; hGrow(x, 'left'); x--);
  1575. for (x = cell.col + 1; hGrow(x, 'right'); x++);
  1576. return range;
  1577. }
  1578. getRanges(name, matrix) {
  1579. matrix = matrix || this.matrixMap[name];
  1580. if (!matrix) {
  1581. return {
  1582. name,
  1583. ranges: []
  1584. };
  1585. }
  1586. // mark and sweep!
  1587. matrix.forEach(cell => {
  1588. cell.mark = true;
  1589. });
  1590. const ranges = matrix.map(cell => cell.mark && this._explore(matrix, cell)).filter(Boolean).map(range => range.$shortRange);
  1591. return {
  1592. name,
  1593. ranges
  1594. };
  1595. }
  1596. normaliseMatrix(matrix, sheetName) {
  1597. // some of the cells might have shifted on specified sheet
  1598. // need to reassign rows, cols
  1599. matrix.forEachInSheet(sheetName, (cell, row, col) => {
  1600. if (cell) {
  1601. if (cell.row !== row || cell.col !== col) {
  1602. cell.row = row;
  1603. cell.col = col;
  1604. cell.address = colCache.n2l(col) + row;
  1605. }
  1606. }
  1607. });
  1608. }
  1609. spliceRows(sheetName, start, numDelete, numInsert) {
  1610. _.each(this.matrixMap, matrix => {
  1611. matrix.spliceRows(sheetName, start, numDelete, numInsert);
  1612. this.normaliseMatrix(matrix, sheetName);
  1613. });
  1614. }
  1615. spliceColumns(sheetName, start, numDelete, numInsert) {
  1616. _.each(this.matrixMap, matrix => {
  1617. matrix.spliceColumns(sheetName, start, numDelete, numInsert);
  1618. this.normaliseMatrix(matrix, sheetName);
  1619. });
  1620. }
  1621. get model() {
  1622. // To get names per cell - just iterate over all names finding cells if they exist
  1623. return _.map(this.matrixMap, (matrix, name) => this.getRanges(name, matrix)).filter(definedName => definedName.ranges.length);
  1624. }
  1625. set model(value) {
  1626. // value is [ { name, ranges }, ... ]
  1627. const matrixMap = this.matrixMap = {};
  1628. value.forEach(definedName => {
  1629. const matrix = matrixMap[definedName.name] = new CellMatrix();
  1630. definedName.ranges.forEach(rangeStr => {
  1631. if (rangeRegexp.test(rangeStr.split('!').pop() || '')) {
  1632. matrix.addCell(rangeStr);
  1633. }
  1634. });
  1635. });
  1636. }
  1637. }
  1638. module.exports = DefinedNames;
  1639. },{"../utils/cell-matrix":18,"../utils/col-cache":19,"../utils/under-dash":26,"./range":10}],7:[function(require,module,exports){
  1640. 'use strict';
  1641. module.exports = {
  1642. ValueType: {
  1643. Null: 0,
  1644. Merge: 1,
  1645. Number: 2,
  1646. String: 3,
  1647. Date: 4,
  1648. Hyperlink: 5,
  1649. Formula: 6,
  1650. SharedString: 7,
  1651. RichText: 8,
  1652. Boolean: 9,
  1653. Error: 10
  1654. },
  1655. FormulaType: {
  1656. None: 0,
  1657. Master: 1,
  1658. Shared: 2
  1659. },
  1660. RelationshipType: {
  1661. None: 0,
  1662. OfficeDocument: 1,
  1663. Worksheet: 2,
  1664. CalcChain: 3,
  1665. SharedStrings: 4,
  1666. Styles: 5,
  1667. Theme: 6,
  1668. Hyperlink: 7
  1669. },
  1670. DocumentType: {
  1671. Xlsx: 1
  1672. },
  1673. ReadingOrder: {
  1674. LeftToRight: 1,
  1675. RightToLeft: 2
  1676. },
  1677. ErrorValue: {
  1678. NotApplicable: '#N/A',
  1679. Ref: '#REF!',
  1680. Name: '#NAME?',
  1681. DivZero: '#DIV/0!',
  1682. Null: '#NULL!',
  1683. Value: '#VALUE!',
  1684. Num: '#NUM!'
  1685. }
  1686. };
  1687. },{}],8:[function(require,module,exports){
  1688. "use strict";
  1689. const colCache = require('../utils/col-cache');
  1690. const Anchor = require('./anchor');
  1691. class Image {
  1692. constructor(worksheet, model) {
  1693. this.worksheet = worksheet;
  1694. this.model = model;
  1695. }
  1696. get model() {
  1697. switch (this.type) {
  1698. case 'background':
  1699. return {
  1700. type: this.type,
  1701. imageId: this.imageId
  1702. };
  1703. case 'image':
  1704. return {
  1705. type: this.type,
  1706. imageId: this.imageId,
  1707. hyperlinks: this.range.hyperlinks,
  1708. range: {
  1709. tl: this.range.tl.model,
  1710. br: this.range.br && this.range.br.model,
  1711. ext: this.range.ext,
  1712. editAs: this.range.editAs
  1713. }
  1714. };
  1715. default:
  1716. throw new Error('Invalid Image Type');
  1717. }
  1718. }
  1719. set model(_ref) {
  1720. let {
  1721. type,
  1722. imageId,
  1723. range,
  1724. hyperlinks
  1725. } = _ref;
  1726. this.type = type;
  1727. this.imageId = imageId;
  1728. if (type === 'image') {
  1729. if (typeof range === 'string') {
  1730. const decoded = colCache.decode(range);
  1731. this.range = {
  1732. tl: new Anchor(this.worksheet, {
  1733. col: decoded.left,
  1734. row: decoded.top
  1735. }, -1),
  1736. br: new Anchor(this.worksheet, {
  1737. col: decoded.right,
  1738. row: decoded.bottom
  1739. }, 0),
  1740. editAs: 'oneCell'
  1741. };
  1742. } else {
  1743. this.range = {
  1744. tl: new Anchor(this.worksheet, range.tl, 0),
  1745. br: range.br && new Anchor(this.worksheet, range.br, 0),
  1746. ext: range.ext,
  1747. editAs: range.editAs,
  1748. hyperlinks: hyperlinks || range.hyperlinks
  1749. };
  1750. }
  1751. }
  1752. }
  1753. }
  1754. module.exports = Image;
  1755. },{"../utils/col-cache":19,"./anchor":2}],9:[function(require,module,exports){
  1756. "use strict";
  1757. const _ = require('../utils/under-dash');
  1758. class Note {
  1759. constructor(note) {
  1760. this.note = note;
  1761. }
  1762. get model() {
  1763. let value = null;
  1764. switch (typeof this.note) {
  1765. case 'string':
  1766. value = {
  1767. type: 'note',
  1768. note: {
  1769. texts: [{
  1770. text: this.note
  1771. }]
  1772. }
  1773. };
  1774. break;
  1775. default:
  1776. value = {
  1777. type: 'note',
  1778. note: this.note
  1779. };
  1780. break;
  1781. }
  1782. // Suitable for all cell comments
  1783. return _.deepMerge({}, Note.DEFAULT_CONFIGS, value);
  1784. }
  1785. set model(value) {
  1786. const {
  1787. note
  1788. } = value;
  1789. const {
  1790. texts
  1791. } = note;
  1792. if (texts.length === 1 && Object.keys(texts[0]).length === 1) {
  1793. this.note = texts[0].text;
  1794. } else {
  1795. this.note = note;
  1796. }
  1797. }
  1798. static fromModel(model) {
  1799. const note = new Note();
  1800. note.model = model;
  1801. return note;
  1802. }
  1803. }
  1804. Note.DEFAULT_CONFIGS = {
  1805. note: {
  1806. margins: {
  1807. insetmode: 'auto',
  1808. inset: [0.13, 0.13, 0.25, 0.25]
  1809. },
  1810. protection: {
  1811. locked: 'True',
  1812. lockText: 'True'
  1813. },
  1814. editAs: 'absolute'
  1815. }
  1816. };
  1817. module.exports = Note;
  1818. },{"../utils/under-dash":26}],10:[function(require,module,exports){
  1819. "use strict";
  1820. const colCache = require('../utils/col-cache');
  1821. // used by worksheet to calculate sheet dimensions
  1822. class Range {
  1823. constructor() {
  1824. this.decode(arguments);
  1825. }
  1826. setTLBR(t, l, b, r, s) {
  1827. if (arguments.length < 4) {
  1828. // setTLBR(tl, br, s)
  1829. const tl = colCache.decodeAddress(t);
  1830. const br = colCache.decodeAddress(l);
  1831. this.model = {
  1832. top: Math.min(tl.row, br.row),
  1833. left: Math.min(tl.col, br.col),
  1834. bottom: Math.max(tl.row, br.row),
  1835. right: Math.max(tl.col, br.col),
  1836. sheetName: b
  1837. };
  1838. this.setTLBR(tl.row, tl.col, br.row, br.col, s);
  1839. } else {
  1840. // setTLBR(t, l, b, r, s)
  1841. this.model = {
  1842. top: Math.min(t, b),
  1843. left: Math.min(l, r),
  1844. bottom: Math.max(t, b),
  1845. right: Math.max(l, r),
  1846. sheetName: s
  1847. };
  1848. }
  1849. }
  1850. decode(argv) {
  1851. switch (argv.length) {
  1852. case 5:
  1853. // [t,l,b,r,s]
  1854. this.setTLBR(argv[0], argv[1], argv[2], argv[3], argv[4]);
  1855. break;
  1856. case 4:
  1857. // [t,l,b,r]
  1858. this.setTLBR(argv[0], argv[1], argv[2], argv[3]);
  1859. break;
  1860. case 3:
  1861. // [tl,br,s]
  1862. this.setTLBR(argv[0], argv[1], argv[2]);
  1863. break;
  1864. case 2:
  1865. // [tl,br]
  1866. this.setTLBR(argv[0], argv[1]);
  1867. break;
  1868. case 1:
  1869. {
  1870. const value = argv[0];
  1871. if (value instanceof Range) {
  1872. // copy constructor
  1873. this.model = {
  1874. top: value.model.top,
  1875. left: value.model.left,
  1876. bottom: value.model.bottom,
  1877. right: value.model.right,
  1878. sheetName: value.sheetName
  1879. };
  1880. } else if (value instanceof Array) {
  1881. // an arguments array
  1882. this.decode(value);
  1883. } else if (value.top && value.left && value.bottom && value.right) {
  1884. // a model
  1885. this.model = {
  1886. top: value.top,
  1887. left: value.left,
  1888. bottom: value.bottom,
  1889. right: value.right,
  1890. sheetName: value.sheetName
  1891. };
  1892. } else {
  1893. // [sheetName!]tl:br
  1894. const tlbr = colCache.decodeEx(value);
  1895. if (tlbr.top) {
  1896. this.model = {
  1897. top: tlbr.top,
  1898. left: tlbr.left,
  1899. bottom: tlbr.bottom,
  1900. right: tlbr.right,
  1901. sheetName: tlbr.sheetName
  1902. };
  1903. } else {
  1904. this.model = {
  1905. top: tlbr.row,
  1906. left: tlbr.col,
  1907. bottom: tlbr.row,
  1908. right: tlbr.col,
  1909. sheetName: tlbr.sheetName
  1910. };
  1911. }
  1912. }
  1913. break;
  1914. }
  1915. case 0:
  1916. this.model = {
  1917. top: 0,
  1918. left: 0,
  1919. bottom: 0,
  1920. right: 0
  1921. };
  1922. break;
  1923. default:
  1924. throw new Error(`Invalid number of arguments to _getDimensions() - ${argv.length}`);
  1925. }
  1926. }
  1927. get top() {
  1928. return this.model.top || 1;
  1929. }
  1930. set top(value) {
  1931. this.model.top = value;
  1932. }
  1933. get left() {
  1934. return this.model.left || 1;
  1935. }
  1936. set left(value) {
  1937. this.model.left = value;
  1938. }
  1939. get bottom() {
  1940. return this.model.bottom || 1;
  1941. }
  1942. set bottom(value) {
  1943. this.model.bottom = value;
  1944. }
  1945. get right() {
  1946. return this.model.right || 1;
  1947. }
  1948. set right(value) {
  1949. this.model.right = value;
  1950. }
  1951. get sheetName() {
  1952. return this.model.sheetName;
  1953. }
  1954. set sheetName(value) {
  1955. this.model.sheetName = value;
  1956. }
  1957. get _serialisedSheetName() {
  1958. const {
  1959. sheetName
  1960. } = this.model;
  1961. if (sheetName) {
  1962. if (/^[a-zA-Z0-9]*$/.test(sheetName)) {
  1963. return `${sheetName}!`;
  1964. }
  1965. return `'${sheetName}'!`;
  1966. }
  1967. return '';
  1968. }
  1969. expand(top, left, bottom, right) {
  1970. if (!this.model.top || top < this.top) this.top = top;
  1971. if (!this.model.left || left < this.left) this.left = left;
  1972. if (!this.model.bottom || bottom > this.bottom) this.bottom = bottom;
  1973. if (!this.model.right || right > this.right) this.right = right;
  1974. }
  1975. expandRow(row) {
  1976. if (row) {
  1977. const {
  1978. dimensions,
  1979. number
  1980. } = row;
  1981. if (dimensions) {
  1982. this.expand(number, dimensions.min, number, dimensions.max);
  1983. }
  1984. }
  1985. }
  1986. expandToAddress(addressStr) {
  1987. const address = colCache.decodeEx(addressStr);
  1988. this.expand(address.row, address.col, address.row, address.col);
  1989. }
  1990. get tl() {
  1991. return colCache.n2l(this.left) + this.top;
  1992. }
  1993. get $t$l() {
  1994. return `$${colCache.n2l(this.left)}$${this.top}`;
  1995. }
  1996. get br() {
  1997. return colCache.n2l(this.right) + this.bottom;
  1998. }
  1999. get $b$r() {
  2000. return `$${colCache.n2l(this.right)}$${this.bottom}`;
  2001. }
  2002. get range() {
  2003. return `${this._serialisedSheetName + this.tl}:${this.br}`;
  2004. }
  2005. get $range() {
  2006. return `${this._serialisedSheetName + this.$t$l}:${this.$b$r}`;
  2007. }
  2008. get shortRange() {
  2009. return this.count > 1 ? this.range : this._serialisedSheetName + this.tl;
  2010. }
  2011. get $shortRange() {
  2012. return this.count > 1 ? this.$range : this._serialisedSheetName + this.$t$l;
  2013. }
  2014. get count() {
  2015. return (1 + this.bottom - this.top) * (1 + this.right - this.left);
  2016. }
  2017. toString() {
  2018. return this.range;
  2019. }
  2020. intersects(other) {
  2021. if (other.sheetName && this.sheetName && other.sheetName !== this.sheetName) return false;
  2022. if (other.bottom < this.top) return false;
  2023. if (other.top > this.bottom) return false;
  2024. if (other.right < this.left) return false;
  2025. if (other.left > this.right) return false;
  2026. return true;
  2027. }
  2028. contains(addressStr) {
  2029. const address = colCache.decodeEx(addressStr);
  2030. return this.containsEx(address);
  2031. }
  2032. containsEx(address) {
  2033. if (address.sheetName && this.sheetName && address.sheetName !== this.sheetName) return false;
  2034. return address.row >= this.top && address.row <= this.bottom && address.col >= this.left && address.col <= this.right;
  2035. }
  2036. forEachAddress(cb) {
  2037. for (let col = this.left; col <= this.right; col++) {
  2038. for (let row = this.top; row <= this.bottom; row++) {
  2039. cb(colCache.encodeAddress(row, col), row, col);
  2040. }
  2041. }
  2042. }
  2043. }
  2044. module.exports = Range;
  2045. },{"../utils/col-cache":19}],11:[function(require,module,exports){
  2046. 'use strict';
  2047. const _ = require('../utils/under-dash');
  2048. const Enums = require('./enums');
  2049. const colCache = require('../utils/col-cache');
  2050. const Cell = require('./cell');
  2051. class Row {
  2052. constructor(worksheet, number) {
  2053. this._worksheet = worksheet;
  2054. this._number = number;
  2055. this._cells = [];
  2056. this.style = {};
  2057. this.outlineLevel = 0;
  2058. }
  2059. // return the row number
  2060. get number() {
  2061. return this._number;
  2062. }
  2063. get worksheet() {
  2064. return this._worksheet;
  2065. }
  2066. // Inform Streaming Writer that this row (and all rows before it) are complete
  2067. // and ready to write. Has no effect on Worksheet document
  2068. commit() {
  2069. this._worksheet._commitRow(this); // eslint-disable-line no-underscore-dangle
  2070. }
  2071. // helps GC by breaking cyclic references
  2072. destroy() {
  2073. delete this._worksheet;
  2074. delete this._cells;
  2075. delete this.style;
  2076. }
  2077. findCell(colNumber) {
  2078. return this._cells[colNumber - 1];
  2079. }
  2080. // given {address, row, col}, find or create new cell
  2081. getCellEx(address) {
  2082. let cell = this._cells[address.col - 1];
  2083. if (!cell) {
  2084. const column = this._worksheet.getColumn(address.col);
  2085. cell = new Cell(this, column, address.address);
  2086. this._cells[address.col - 1] = cell;
  2087. }
  2088. return cell;
  2089. }
  2090. // get cell by key, letter or column number
  2091. getCell(col) {
  2092. if (typeof col === 'string') {
  2093. // is it a key?
  2094. const column = this._worksheet.getColumnKey(col);
  2095. if (column) {
  2096. col = column.number;
  2097. } else {
  2098. col = colCache.l2n(col);
  2099. }
  2100. }
  2101. return this._cells[col - 1] || this.getCellEx({
  2102. address: colCache.encodeAddress(this._number, col),
  2103. row: this._number,
  2104. col
  2105. });
  2106. }
  2107. // remove cell(s) and shift all higher cells down by count
  2108. splice(start, count) {
  2109. const nKeep = start + count;
  2110. for (var _len = arguments.length, inserts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  2111. inserts[_key - 2] = arguments[_key];
  2112. }
  2113. const nExpand = inserts.length - count;
  2114. const nEnd = this._cells.length;
  2115. let i;
  2116. let cSrc;
  2117. let cDst;
  2118. if (nExpand < 0) {
  2119. // remove cells
  2120. for (i = start + inserts.length; i <= nEnd; i++) {
  2121. cDst = this._cells[i - 1];
  2122. cSrc = this._cells[i - nExpand - 1];
  2123. if (cSrc) {
  2124. cDst = this.getCell(i);
  2125. cDst.value = cSrc.value;
  2126. cDst.style = cSrc.style;
  2127. // eslint-disable-next-line no-underscore-dangle
  2128. cDst._comment = cSrc._comment;
  2129. } else if (cDst) {
  2130. cDst.value = null;
  2131. cDst.style = {};
  2132. // eslint-disable-next-line no-underscore-dangle
  2133. cDst._comment = undefined;
  2134. }
  2135. }
  2136. } else if (nExpand > 0) {
  2137. // insert new cells
  2138. for (i = nEnd; i >= nKeep; i--) {
  2139. cSrc = this._cells[i - 1];
  2140. if (cSrc) {
  2141. cDst = this.getCell(i + nExpand);
  2142. cDst.value = cSrc.value;
  2143. cDst.style = cSrc.style;
  2144. // eslint-disable-next-line no-underscore-dangle
  2145. cDst._comment = cSrc._comment;
  2146. } else {
  2147. this._cells[i + nExpand - 1] = undefined;
  2148. }
  2149. }
  2150. }
  2151. // now add the new values
  2152. for (i = 0; i < inserts.length; i++) {
  2153. cDst = this.getCell(start + i);
  2154. cDst.value = inserts[i];
  2155. cDst.style = {};
  2156. // eslint-disable-next-line no-underscore-dangle
  2157. cDst._comment = undefined;
  2158. }
  2159. }
  2160. // Iterate over all non-null cells in this row
  2161. eachCell(options, iteratee) {
  2162. if (!iteratee) {
  2163. iteratee = options;
  2164. options = null;
  2165. }
  2166. if (options && options.includeEmpty) {
  2167. const n = this._cells.length;
  2168. for (let i = 1; i <= n; i++) {
  2169. iteratee(this.getCell(i), i);
  2170. }
  2171. } else {
  2172. this._cells.forEach((cell, index) => {
  2173. if (cell && cell.type !== Enums.ValueType.Null) {
  2174. iteratee(cell, index + 1);
  2175. }
  2176. });
  2177. }
  2178. }
  2179. // ===========================================================================
  2180. // Page Breaks
  2181. addPageBreak(lft, rght) {
  2182. const ws = this._worksheet;
  2183. const left = Math.max(0, lft - 1) || 0;
  2184. const right = Math.max(0, rght - 1) || 16838;
  2185. const pb = {
  2186. id: this._number,
  2187. max: right,
  2188. man: 1
  2189. };
  2190. if (left) pb.min = left;
  2191. ws.rowBreaks.push(pb);
  2192. }
  2193. // return a sparse array of cell values
  2194. get values() {
  2195. const values = [];
  2196. this._cells.forEach(cell => {
  2197. if (cell && cell.type !== Enums.ValueType.Null) {
  2198. values[cell.col] = cell.value;
  2199. }
  2200. });
  2201. return values;
  2202. }
  2203. // set the values by contiguous or sparse array, or by key'd object literal
  2204. set values(value) {
  2205. // this operation is not additive - any prior cells are removed
  2206. this._cells = [];
  2207. if (!value) {
  2208. // empty row
  2209. } else if (value instanceof Array) {
  2210. let offset = 0;
  2211. if (value.hasOwnProperty('0')) {
  2212. // contiguous array - start at column 1
  2213. offset = 1;
  2214. }
  2215. value.forEach((item, index) => {
  2216. if (item !== undefined) {
  2217. this.getCellEx({
  2218. address: colCache.encodeAddress(this._number, index + offset),
  2219. row: this._number,
  2220. col: index + offset
  2221. }).value = item;
  2222. }
  2223. });
  2224. } else {
  2225. // assume object with column keys
  2226. this._worksheet.eachColumnKey((column, key) => {
  2227. if (value[key] !== undefined) {
  2228. this.getCellEx({
  2229. address: colCache.encodeAddress(this._number, column.number),
  2230. row: this._number,
  2231. col: column.number
  2232. }).value = value[key];
  2233. }
  2234. });
  2235. }
  2236. }
  2237. // returns true if the row includes at least one cell with a value
  2238. get hasValues() {
  2239. return _.some(this._cells, cell => cell && cell.type !== Enums.ValueType.Null);
  2240. }
  2241. get cellCount() {
  2242. return this._cells.length;
  2243. }
  2244. get actualCellCount() {
  2245. let count = 0;
  2246. this.eachCell(() => {
  2247. count++;
  2248. });
  2249. return count;
  2250. }
  2251. // get the min and max column number for the non-null cells in this row or null
  2252. get dimensions() {
  2253. let min = 0;
  2254. let max = 0;
  2255. this._cells.forEach(cell => {
  2256. if (cell && cell.type !== Enums.ValueType.Null) {
  2257. if (!min || min > cell.col) {
  2258. min = cell.col;
  2259. }
  2260. if (max < cell.col) {
  2261. max = cell.col;
  2262. }
  2263. }
  2264. });
  2265. return min > 0 ? {
  2266. min,
  2267. max
  2268. } : null;
  2269. }
  2270. // =========================================================================
  2271. // styles
  2272. _applyStyle(name, value) {
  2273. this.style[name] = value;
  2274. this._cells.forEach(cell => {
  2275. if (cell) {
  2276. cell[name] = value;
  2277. }
  2278. });
  2279. return value;
  2280. }
  2281. get numFmt() {
  2282. return this.style.numFmt;
  2283. }
  2284. set numFmt(value) {
  2285. this._applyStyle('numFmt', value);
  2286. }
  2287. get font() {
  2288. return this.style.font;
  2289. }
  2290. set font(value) {
  2291. this._applyStyle('font', value);
  2292. }
  2293. get alignment() {
  2294. return this.style.alignment;
  2295. }
  2296. set alignment(value) {
  2297. this._applyStyle('alignment', value);
  2298. }
  2299. get protection() {
  2300. return this.style.protection;
  2301. }
  2302. set protection(value) {
  2303. this._applyStyle('protection', value);
  2304. }
  2305. get border() {
  2306. return this.style.border;
  2307. }
  2308. set border(value) {
  2309. this._applyStyle('border', value);
  2310. }
  2311. get fill() {
  2312. return this.style.fill;
  2313. }
  2314. set fill(value) {
  2315. this._applyStyle('fill', value);
  2316. }
  2317. get hidden() {
  2318. return !!this._hidden;
  2319. }
  2320. set hidden(value) {
  2321. this._hidden = value;
  2322. }
  2323. get outlineLevel() {
  2324. return this._outlineLevel || 0;
  2325. }
  2326. set outlineLevel(value) {
  2327. this._outlineLevel = value;
  2328. }
  2329. get collapsed() {
  2330. return !!(this._outlineLevel && this._outlineLevel >= this._worksheet.properties.outlineLevelRow);
  2331. }
  2332. // =========================================================================
  2333. get model() {
  2334. const cells = [];
  2335. let min = 0;
  2336. let max = 0;
  2337. this._cells.forEach(cell => {
  2338. if (cell) {
  2339. const cellModel = cell.model;
  2340. if (cellModel) {
  2341. if (!min || min > cell.col) {
  2342. min = cell.col;
  2343. }
  2344. if (max < cell.col) {
  2345. max = cell.col;
  2346. }
  2347. cells.push(cellModel);
  2348. }
  2349. }
  2350. });
  2351. return this.height || cells.length ? {
  2352. cells,
  2353. number: this.number,
  2354. min,
  2355. max,
  2356. height: this.height,
  2357. style: this.style,
  2358. hidden: this.hidden,
  2359. outlineLevel: this.outlineLevel,
  2360. collapsed: this.collapsed
  2361. } : null;
  2362. }
  2363. set model(value) {
  2364. if (value.number !== this._number) {
  2365. throw new Error('Invalid row number in model');
  2366. }
  2367. this._cells = [];
  2368. let previousAddress;
  2369. value.cells.forEach(cellModel => {
  2370. switch (cellModel.type) {
  2371. case Cell.Types.Merge:
  2372. // special case - don't add this types
  2373. break;
  2374. default:
  2375. {
  2376. let address;
  2377. if (cellModel.address) {
  2378. address = colCache.decodeAddress(cellModel.address);
  2379. } else if (previousAddress) {
  2380. // This is a <c> element without an r attribute
  2381. // Assume that it's the cell for the next column
  2382. const {
  2383. row
  2384. } = previousAddress;
  2385. const col = previousAddress.col + 1;
  2386. address = {
  2387. row,
  2388. col,
  2389. address: colCache.encodeAddress(row, col),
  2390. $col$row: `$${colCache.n2l(col)}$${row}`
  2391. };
  2392. }
  2393. previousAddress = address;
  2394. const cell = this.getCellEx(address);
  2395. cell.model = cellModel;
  2396. break;
  2397. }
  2398. }
  2399. });
  2400. if (value.height) {
  2401. this.height = value.height;
  2402. } else {
  2403. delete this.height;
  2404. }
  2405. this.hidden = value.hidden;
  2406. this.outlineLevel = value.outlineLevel || 0;
  2407. this.style = value.style && JSON.parse(JSON.stringify(value.style)) || {};
  2408. }
  2409. }
  2410. module.exports = Row;
  2411. },{"../utils/col-cache":19,"../utils/under-dash":26,"./cell":3,"./enums":7}],12:[function(require,module,exports){
  2412. "use strict";
  2413. /* eslint-disable max-classes-per-file */
  2414. const colCache = require('../utils/col-cache');
  2415. class Column {
  2416. // wrapper around column model, allowing access and manipulation
  2417. constructor(table, column, index) {
  2418. this.table = table;
  2419. this.column = column;
  2420. this.index = index;
  2421. }
  2422. _set(name, value) {
  2423. this.table.cacheState();
  2424. this.column[name] = value;
  2425. }
  2426. /* eslint-disable lines-between-class-members */
  2427. get name() {
  2428. return this.column.name;
  2429. }
  2430. set name(value) {
  2431. this._set('name', value);
  2432. }
  2433. get filterButton() {
  2434. return this.column.filterButton;
  2435. }
  2436. set filterButton(value) {
  2437. this.column.filterButton = value;
  2438. }
  2439. get style() {
  2440. return this.column.style;
  2441. }
  2442. set style(value) {
  2443. this.column.style = value;
  2444. }
  2445. get totalsRowLabel() {
  2446. return this.column.totalsRowLabel;
  2447. }
  2448. set totalsRowLabel(value) {
  2449. this._set('totalsRowLabel', value);
  2450. }
  2451. get totalsRowFunction() {
  2452. return this.column.totalsRowFunction;
  2453. }
  2454. set totalsRowFunction(value) {
  2455. this._set('totalsRowFunction', value);
  2456. }
  2457. get totalsRowResult() {
  2458. return this.column.totalsRowResult;
  2459. }
  2460. set totalsRowResult(value) {
  2461. this._set('totalsRowResult', value);
  2462. }
  2463. get totalsRowFormula() {
  2464. return this.column.totalsRowFormula;
  2465. }
  2466. set totalsRowFormula(value) {
  2467. this._set('totalsRowFormula', value);
  2468. }
  2469. /* eslint-enable lines-between-class-members */
  2470. }
  2471. class Table {
  2472. constructor(worksheet, table) {
  2473. this.worksheet = worksheet;
  2474. if (table) {
  2475. this.table = table;
  2476. // check things are ok first
  2477. this.validate();
  2478. this.store();
  2479. }
  2480. }
  2481. getFormula(column) {
  2482. // get the correct formula to apply to the totals row
  2483. switch (column.totalsRowFunction) {
  2484. case 'none':
  2485. return null;
  2486. case 'average':
  2487. return `SUBTOTAL(101,${this.table.name}[${column.name}])`;
  2488. case 'countNums':
  2489. return `SUBTOTAL(102,${this.table.name}[${column.name}])`;
  2490. case 'count':
  2491. return `SUBTOTAL(103,${this.table.name}[${column.name}])`;
  2492. case 'max':
  2493. return `SUBTOTAL(104,${this.table.name}[${column.name}])`;
  2494. case 'min':
  2495. return `SUBTOTAL(105,${this.table.name}[${column.name}])`;
  2496. case 'stdDev':
  2497. return `SUBTOTAL(106,${this.table.name}[${column.name}])`;
  2498. case 'var':
  2499. return `SUBTOTAL(107,${this.table.name}[${column.name}])`;
  2500. case 'sum':
  2501. return `SUBTOTAL(109,${this.table.name}[${column.name}])`;
  2502. case 'custom':
  2503. return column.totalsRowFormula;
  2504. default:
  2505. throw new Error(`Invalid Totals Row Function: ${column.totalsRowFunction}`);
  2506. }
  2507. }
  2508. get width() {
  2509. // width of the table
  2510. return this.table.columns.length;
  2511. }
  2512. get height() {
  2513. // height of the table data
  2514. return this.table.rows.length;
  2515. }
  2516. get filterHeight() {
  2517. // height of the table data plus optional header row
  2518. return this.height + (this.table.headerRow ? 1 : 0);
  2519. }
  2520. get tableHeight() {
  2521. // full height of the table on the sheet
  2522. return this.filterHeight + (this.table.totalsRow ? 1 : 0);
  2523. }
  2524. validate() {
  2525. const {
  2526. table
  2527. } = this;
  2528. // set defaults and check is valid
  2529. const assign = (o, name, dflt) => {
  2530. if (o[name] === undefined) {
  2531. o[name] = dflt;
  2532. }
  2533. };
  2534. assign(table, 'headerRow', true);
  2535. assign(table, 'totalsRow', false);
  2536. assign(table, 'style', {});
  2537. assign(table.style, 'theme', 'TableStyleMedium2');
  2538. assign(table.style, 'showFirstColumn', false);
  2539. assign(table.style, 'showLastColumn', false);
  2540. assign(table.style, 'showRowStripes', false);
  2541. assign(table.style, 'showColumnStripes', false);
  2542. const assert = (test, message) => {
  2543. if (!test) {
  2544. throw new Error(message);
  2545. }
  2546. };
  2547. assert(table.ref, 'Table must have ref');
  2548. assert(table.columns, 'Table must have column definitions');
  2549. assert(table.rows, 'Table must have row definitions');
  2550. table.tl = colCache.decodeAddress(table.ref);
  2551. const {
  2552. row,
  2553. col
  2554. } = table.tl;
  2555. assert(row > 0, 'Table must be on valid row');
  2556. assert(col > 0, 'Table must be on valid col');
  2557. const {
  2558. width,
  2559. filterHeight,
  2560. tableHeight
  2561. } = this;
  2562. // autoFilterRef is a range that includes optional headers only
  2563. table.autoFilterRef = colCache.encode(row, col, row + filterHeight - 1, col + width - 1);
  2564. // tableRef is a range that includes optional headers and totals
  2565. table.tableRef = colCache.encode(row, col, row + tableHeight - 1, col + width - 1);
  2566. table.columns.forEach((column, i) => {
  2567. assert(column.name, `Column ${i} must have a name`);
  2568. if (i === 0) {
  2569. assign(column, 'totalsRowLabel', 'Total');
  2570. } else {
  2571. assign(column, 'totalsRowFunction', 'none');
  2572. column.totalsRowFormula = this.getFormula(column);
  2573. }
  2574. });
  2575. }
  2576. store() {
  2577. // where the table needs to store table data, headers, footers in
  2578. // the sheet...
  2579. const assignStyle = (cell, style) => {
  2580. if (style) {
  2581. Object.keys(style).forEach(key => {
  2582. cell[key] = style[key];
  2583. });
  2584. }
  2585. };
  2586. const {
  2587. worksheet,
  2588. table
  2589. } = this;
  2590. const {
  2591. row,
  2592. col
  2593. } = table.tl;
  2594. let count = 0;
  2595. if (table.headerRow) {
  2596. const r = worksheet.getRow(row + count++);
  2597. table.columns.forEach((column, j) => {
  2598. const {
  2599. style,
  2600. name
  2601. } = column;
  2602. const cell = r.getCell(col + j);
  2603. cell.value = name;
  2604. assignStyle(cell, style);
  2605. });
  2606. }
  2607. table.rows.forEach(data => {
  2608. const r = worksheet.getRow(row + count++);
  2609. data.forEach((value, j) => {
  2610. const cell = r.getCell(col + j);
  2611. cell.value = value;
  2612. assignStyle(cell, table.columns[j].style);
  2613. });
  2614. });
  2615. if (table.totalsRow) {
  2616. const r = worksheet.getRow(row + count++);
  2617. table.columns.forEach((column, j) => {
  2618. const cell = r.getCell(col + j);
  2619. if (j === 0) {
  2620. cell.value = column.totalsRowLabel;
  2621. } else {
  2622. const formula = this.getFormula(column);
  2623. if (formula) {
  2624. cell.value = {
  2625. formula: column.totalsRowFormula,
  2626. result: column.totalsRowResult
  2627. };
  2628. } else {
  2629. cell.value = null;
  2630. }
  2631. }
  2632. assignStyle(cell, column.style);
  2633. });
  2634. }
  2635. }
  2636. load(worksheet) {
  2637. // where the table will read necessary features from a loaded sheet
  2638. const {
  2639. table
  2640. } = this;
  2641. const {
  2642. row,
  2643. col
  2644. } = table.tl;
  2645. let count = 0;
  2646. if (table.headerRow) {
  2647. const r = worksheet.getRow(row + count++);
  2648. table.columns.forEach((column, j) => {
  2649. const cell = r.getCell(col + j);
  2650. cell.value = column.name;
  2651. });
  2652. }
  2653. table.rows.forEach(data => {
  2654. const r = worksheet.getRow(row + count++);
  2655. data.forEach((value, j) => {
  2656. const cell = r.getCell(col + j);
  2657. cell.value = value;
  2658. });
  2659. });
  2660. if (table.totalsRow) {
  2661. const r = worksheet.getRow(row + count++);
  2662. table.columns.forEach((column, j) => {
  2663. const cell = r.getCell(col + j);
  2664. if (j === 0) {
  2665. cell.value = column.totalsRowLabel;
  2666. } else {
  2667. const formula = this.getFormula(column);
  2668. if (formula) {
  2669. cell.value = {
  2670. formula: column.totalsRowFormula,
  2671. result: column.totalsRowResult
  2672. };
  2673. }
  2674. }
  2675. });
  2676. }
  2677. }
  2678. get model() {
  2679. return this.table;
  2680. }
  2681. set model(value) {
  2682. this.table = value;
  2683. }
  2684. // ================================================================
  2685. // TODO: Mutating methods
  2686. cacheState() {
  2687. if (!this._cache) {
  2688. this._cache = {
  2689. ref: this.ref,
  2690. width: this.width,
  2691. tableHeight: this.tableHeight
  2692. };
  2693. }
  2694. }
  2695. commit() {
  2696. // changes may have been made that might have on-sheet effects
  2697. if (!this._cache) {
  2698. return;
  2699. }
  2700. // check things are ok first
  2701. this.validate();
  2702. const ref = colCache.decodeAddress(this._cache.ref);
  2703. if (this.ref !== this._cache.ref) {
  2704. // wipe out whole table footprint at previous location
  2705. for (let i = 0; i < this._cache.tableHeight; i++) {
  2706. const row = this.worksheet.getRow(ref.row + i);
  2707. for (let j = 0; j < this._cache.width; j++) {
  2708. const cell = row.getCell(ref.col + j);
  2709. cell.value = null;
  2710. }
  2711. }
  2712. } else {
  2713. // clear out below table if it has shrunk
  2714. for (let i = this.tableHeight; i < this._cache.tableHeight; i++) {
  2715. const row = this.worksheet.getRow(ref.row + i);
  2716. for (let j = 0; j < this._cache.width; j++) {
  2717. const cell = row.getCell(ref.col + j);
  2718. cell.value = null;
  2719. }
  2720. }
  2721. // clear out to right of table if it has lost columns
  2722. for (let i = 0; i < this.tableHeight; i++) {
  2723. const row = this.worksheet.getRow(ref.row + i);
  2724. for (let j = this.width; j < this._cache.width; j++) {
  2725. const cell = row.getCell(ref.col + j);
  2726. cell.value = null;
  2727. }
  2728. }
  2729. }
  2730. this.store();
  2731. }
  2732. addRow(values, rowNumber) {
  2733. // Add a row of data, either insert at rowNumber or append
  2734. this.cacheState();
  2735. if (rowNumber === undefined) {
  2736. this.table.rows.push(values);
  2737. } else {
  2738. this.table.rows.splice(rowNumber, 0, values);
  2739. }
  2740. }
  2741. removeRows(rowIndex) {
  2742. let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  2743. // Remove a rows of data
  2744. this.cacheState();
  2745. this.table.rows.splice(rowIndex, count);
  2746. }
  2747. getColumn(colIndex) {
  2748. const column = this.table.columns[colIndex];
  2749. return new Column(this, column, colIndex);
  2750. }
  2751. addColumn(column, values, colIndex) {
  2752. // Add a new column, including column defn and values
  2753. // Inserts at colNumber or adds to the right
  2754. this.cacheState();
  2755. if (colIndex === undefined) {
  2756. this.table.columns.push(column);
  2757. this.table.rows.forEach((row, i) => {
  2758. row.push(values[i]);
  2759. });
  2760. } else {
  2761. this.table.columns.splice(colIndex, 0, column);
  2762. this.table.rows.forEach((row, i) => {
  2763. row.splice(colIndex, 0, values[i]);
  2764. });
  2765. }
  2766. }
  2767. removeColumns(colIndex) {
  2768. let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  2769. // Remove a column with data
  2770. this.cacheState();
  2771. this.table.columns.splice(colIndex, count);
  2772. this.table.rows.forEach(row => {
  2773. row.splice(colIndex, count);
  2774. });
  2775. }
  2776. _assign(target, prop, value) {
  2777. this.cacheState();
  2778. target[prop] = value;
  2779. }
  2780. /* eslint-disable lines-between-class-members */
  2781. get ref() {
  2782. return this.table.ref;
  2783. }
  2784. set ref(value) {
  2785. this._assign(this.table, 'ref', value);
  2786. }
  2787. get name() {
  2788. return this.table.name;
  2789. }
  2790. set name(value) {
  2791. this.table.name = value;
  2792. }
  2793. get displayName() {
  2794. return this.table.displyName || this.table.name;
  2795. }
  2796. set displayNamename(value) {
  2797. this.table.displayName = value;
  2798. }
  2799. get headerRow() {
  2800. return this.table.headerRow;
  2801. }
  2802. set headerRow(value) {
  2803. this._assign(this.table, 'headerRow', value);
  2804. }
  2805. get totalsRow() {
  2806. return this.table.totalsRow;
  2807. }
  2808. set totalsRow(value) {
  2809. this._assign(this.table, 'totalsRow', value);
  2810. }
  2811. get theme() {
  2812. return this.table.style.name;
  2813. }
  2814. set theme(value) {
  2815. this.table.style.name = value;
  2816. }
  2817. get showFirstColumn() {
  2818. return this.table.style.showFirstColumn;
  2819. }
  2820. set showFirstColumn(value) {
  2821. this.table.style.showFirstColumn = value;
  2822. }
  2823. get showLastColumn() {
  2824. return this.table.style.showLastColumn;
  2825. }
  2826. set showLastColumn(value) {
  2827. this.table.style.showLastColumn = value;
  2828. }
  2829. get showRowStripes() {
  2830. return this.table.style.showRowStripes;
  2831. }
  2832. set showRowStripes(value) {
  2833. this.table.style.showRowStripes = value;
  2834. }
  2835. get showColumnStripes() {
  2836. return this.table.style.showColumnStripes;
  2837. }
  2838. set showColumnStripes(value) {
  2839. this.table.style.showColumnStripes = value;
  2840. }
  2841. /* eslint-enable lines-between-class-members */
  2842. }
  2843. module.exports = Table;
  2844. },{"../utils/col-cache":19}],13:[function(require,module,exports){
  2845. 'use strict';
  2846. const Worksheet = require('./worksheet');
  2847. const DefinedNames = require('./defined-names');
  2848. const XLSX = require('../xlsx/xlsx');
  2849. const CSV = require('../csv/csv');
  2850. // Workbook requirements
  2851. // Load and Save from file and stream
  2852. // Access/Add/Delete individual worksheets
  2853. // Manage String table, Hyperlink table, etc.
  2854. // Manage scaffolding for contained objects to write to/read from
  2855. class Workbook {
  2856. constructor() {
  2857. this.category = '';
  2858. this.company = '';
  2859. this.created = new Date();
  2860. this.description = '';
  2861. this.keywords = '';
  2862. this.manager = '';
  2863. this.modified = this.created;
  2864. this.properties = {};
  2865. this.calcProperties = {};
  2866. this._worksheets = [];
  2867. this.subject = '';
  2868. this.title = '';
  2869. this.views = [];
  2870. this.media = [];
  2871. this._definedNames = new DefinedNames();
  2872. }
  2873. get xlsx() {
  2874. if (!this._xlsx) this._xlsx = new XLSX(this);
  2875. return this._xlsx;
  2876. }
  2877. get csv() {
  2878. if (!this._csv) this._csv = new CSV(this);
  2879. return this._csv;
  2880. }
  2881. get nextId() {
  2882. // find the next unique spot to add worksheet
  2883. for (let i = 1; i < this._worksheets.length; i++) {
  2884. if (!this._worksheets[i]) {
  2885. return i;
  2886. }
  2887. }
  2888. return this._worksheets.length || 1;
  2889. }
  2890. addWorksheet(name, options) {
  2891. const id = this.nextId;
  2892. // if options is a color, call it tabColor (and signal deprecated message)
  2893. if (options) {
  2894. if (typeof options === 'string') {
  2895. // eslint-disable-next-line no-console
  2896. console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { argb: "rbg value" } }');
  2897. options = {
  2898. properties: {
  2899. tabColor: {
  2900. argb: options
  2901. }
  2902. }
  2903. };
  2904. } else if (options.argb || options.theme || options.indexed) {
  2905. // eslint-disable-next-line no-console
  2906. console.trace('tabColor argument is now deprecated. Please use workbook.addWorksheet(name, {properties: { tabColor: { ... } }');
  2907. options = {
  2908. properties: {
  2909. tabColor: options
  2910. }
  2911. };
  2912. }
  2913. }
  2914. const lastOrderNo = this._worksheets.reduce((acc, ws) => (ws && ws.orderNo) > acc ? ws.orderNo : acc, 0);
  2915. const worksheetOptions = Object.assign({}, options, {
  2916. id,
  2917. name,
  2918. orderNo: lastOrderNo + 1,
  2919. workbook: this
  2920. });
  2921. const worksheet = new Worksheet(worksheetOptions);
  2922. this._worksheets[id] = worksheet;
  2923. return worksheet;
  2924. }
  2925. removeWorksheetEx(worksheet) {
  2926. delete this._worksheets[worksheet.id];
  2927. }
  2928. removeWorksheet(id) {
  2929. const worksheet = this.getWorksheet(id);
  2930. if (worksheet) {
  2931. worksheet.destroy();
  2932. }
  2933. }
  2934. getWorksheet(id) {
  2935. if (id === undefined) {
  2936. return this._worksheets.find(Boolean);
  2937. }
  2938. if (typeof id === 'number') {
  2939. return this._worksheets[id];
  2940. }
  2941. if (typeof id === 'string') {
  2942. return this._worksheets.find(worksheet => worksheet && worksheet.name === id);
  2943. }
  2944. return undefined;
  2945. }
  2946. get worksheets() {
  2947. // return a clone of _worksheets
  2948. return this._worksheets.slice(1).sort((a, b) => a.orderNo - b.orderNo).filter(Boolean);
  2949. }
  2950. eachSheet(iteratee) {
  2951. this.worksheets.forEach(sheet => {
  2952. iteratee(sheet, sheet.id);
  2953. });
  2954. }
  2955. get definedNames() {
  2956. return this._definedNames;
  2957. }
  2958. clearThemes() {
  2959. // Note: themes are not an exposed feature, meddle at your peril!
  2960. this._themes = undefined;
  2961. }
  2962. addImage(image) {
  2963. // TODO: validation?
  2964. const id = this.media.length;
  2965. this.media.push(Object.assign({}, image, {
  2966. type: 'image'
  2967. }));
  2968. return id;
  2969. }
  2970. getImage(id) {
  2971. return this.media[id];
  2972. }
  2973. get model() {
  2974. return {
  2975. creator: this.creator || 'Unknown',
  2976. lastModifiedBy: this.lastModifiedBy || 'Unknown',
  2977. lastPrinted: this.lastPrinted,
  2978. created: this.created,
  2979. modified: this.modified,
  2980. properties: this.properties,
  2981. worksheets: this.worksheets.map(worksheet => worksheet.model),
  2982. sheets: this.worksheets.map(ws => ws.model).filter(Boolean),
  2983. definedNames: this._definedNames.model,
  2984. views: this.views,
  2985. company: this.company,
  2986. manager: this.manager,
  2987. title: this.title,
  2988. subject: this.subject,
  2989. keywords: this.keywords,
  2990. category: this.category,
  2991. description: this.description,
  2992. language: this.language,
  2993. revision: this.revision,
  2994. contentStatus: this.contentStatus,
  2995. themes: this._themes,
  2996. media: this.media,
  2997. calcProperties: this.calcProperties
  2998. };
  2999. }
  3000. set model(value) {
  3001. this.creator = value.creator;
  3002. this.lastModifiedBy = value.lastModifiedBy;
  3003. this.lastPrinted = value.lastPrinted;
  3004. this.created = value.created;
  3005. this.modified = value.modified;
  3006. this.company = value.company;
  3007. this.manager = value.manager;
  3008. this.title = value.title;
  3009. this.subject = value.subject;
  3010. this.keywords = value.keywords;
  3011. this.category = value.category;
  3012. this.description = value.description;
  3013. this.language = value.language;
  3014. this.revision = value.revision;
  3015. this.contentStatus = value.contentStatus;
  3016. this.properties = value.properties;
  3017. this.calcProperties = value.calcProperties;
  3018. this._worksheets = [];
  3019. value.worksheets.forEach(worksheetModel => {
  3020. const {
  3021. id,
  3022. name,
  3023. state
  3024. } = worksheetModel;
  3025. const orderNo = value.sheets && value.sheets.findIndex(ws => ws.id === id);
  3026. const worksheet = this._worksheets[id] = new Worksheet({
  3027. id,
  3028. name,
  3029. orderNo,
  3030. state,
  3031. workbook: this
  3032. });
  3033. worksheet.model = worksheetModel;
  3034. });
  3035. this._definedNames.model = value.definedNames;
  3036. this.views = value.views;
  3037. this._themes = value.themes;
  3038. this.media = value.media || [];
  3039. }
  3040. }
  3041. module.exports = Workbook;
  3042. },{"../csv/csv":1,"../xlsx/xlsx":144,"./defined-names":6,"./worksheet":14}],14:[function(require,module,exports){
  3043. "use strict";
  3044. const _ = require('../utils/under-dash');
  3045. const colCache = require('../utils/col-cache');
  3046. const Range = require('./range');
  3047. const Row = require('./row');
  3048. const Column = require('./column');
  3049. const Enums = require('./enums');
  3050. const Image = require('./image');
  3051. const Table = require('./table');
  3052. const DataValidations = require('./data-validations');
  3053. const Encryptor = require('../utils/encryptor');
  3054. const {
  3055. copyStyle
  3056. } = require('../utils/copy-style');
  3057. // Worksheet requirements
  3058. // Operate as sheet inside workbook or standalone
  3059. // Load and Save from file and stream
  3060. // Access/Add/Delete individual cells
  3061. // Manage column widths and row heights
  3062. class Worksheet {
  3063. constructor(options) {
  3064. options = options || {};
  3065. this._workbook = options.workbook;
  3066. // in a workbook, each sheet will have a number
  3067. this.id = options.id;
  3068. this.orderNo = options.orderNo;
  3069. // and a name
  3070. this.name = options.name;
  3071. // add a state
  3072. this.state = options.state || 'visible';
  3073. // rows allows access organised by row. Sparse array of arrays indexed by row-1, col
  3074. // Note: _rows is zero based. Must subtract 1 to go from cell.row to index
  3075. this._rows = [];
  3076. // column definitions
  3077. this._columns = null;
  3078. // column keys (addRow convenience): key ==> this._collumns index
  3079. this._keys = {};
  3080. // keep record of all merges
  3081. this._merges = {};
  3082. // record of all row and column pageBreaks
  3083. this.rowBreaks = [];
  3084. // for tabColor, default row height, outline levels, etc
  3085. this.properties = Object.assign({}, {
  3086. defaultRowHeight: 15,
  3087. dyDescent: 55,
  3088. outlineLevelCol: 0,
  3089. outlineLevelRow: 0
  3090. }, options.properties);
  3091. // for all things printing
  3092. this.pageSetup = Object.assign({}, {
  3093. margins: {
  3094. left: 0.7,
  3095. right: 0.7,
  3096. top: 0.75,
  3097. bottom: 0.75,
  3098. header: 0.3,
  3099. footer: 0.3
  3100. },
  3101. orientation: 'portrait',
  3102. horizontalDpi: 4294967295,
  3103. verticalDpi: 4294967295,
  3104. fitToPage: !!(options.pageSetup && (options.pageSetup.fitToWidth || options.pageSetup.fitToHeight) && !options.pageSetup.scale),
  3105. pageOrder: 'downThenOver',
  3106. blackAndWhite: false,
  3107. draft: false,
  3108. cellComments: 'None',
  3109. errors: 'displayed',
  3110. scale: 100,
  3111. fitToWidth: 1,
  3112. fitToHeight: 1,
  3113. paperSize: undefined,
  3114. showRowColHeaders: false,
  3115. showGridLines: false,
  3116. firstPageNumber: undefined,
  3117. horizontalCentered: false,
  3118. verticalCentered: false,
  3119. rowBreaks: null,
  3120. colBreaks: null
  3121. }, options.pageSetup);
  3122. this.headerFooter = Object.assign({}, {
  3123. differentFirst: false,
  3124. differentOddEven: false,
  3125. oddHeader: null,
  3126. oddFooter: null,
  3127. evenHeader: null,
  3128. evenFooter: null,
  3129. firstHeader: null,
  3130. firstFooter: null
  3131. }, options.headerFooter);
  3132. this.dataValidations = new DataValidations();
  3133. // for freezepanes, split, zoom, gridlines, etc
  3134. this.views = options.views || [];
  3135. this.autoFilter = options.autoFilter || null;
  3136. // for images, etc
  3137. this._media = [];
  3138. // worksheet protection
  3139. this.sheetProtection = null;
  3140. // for tables
  3141. this.tables = {};
  3142. this.conditionalFormattings = [];
  3143. }
  3144. get name() {
  3145. return this._name;
  3146. }
  3147. set name(name) {
  3148. if (name === undefined) {
  3149. name = `sheet${this.id}`;
  3150. }
  3151. if (this._name === name) return;
  3152. if (typeof name !== 'string') {
  3153. throw new Error('The name has to be a string.');
  3154. }
  3155. if (name === '') {
  3156. throw new Error('The name can\'t be empty.');
  3157. }
  3158. if (name === 'History') {
  3159. throw new Error('The name "History" is protected. Please use a different name.');
  3160. }
  3161. // Illegal character in worksheet name: asterisk (*), question mark (?),
  3162. // colon (:), forward slash (/ \), or bracket ([])
  3163. if (/[*?:/\\[\]]/.test(name)) {
  3164. throw new Error(`Worksheet name ${name} cannot include any of the following characters: * ? : \\ / [ ]`);
  3165. }
  3166. if (/(^')|('$)/.test(name)) {
  3167. throw new Error(`The first or last character of worksheet name cannot be a single quotation mark: ${name}`);
  3168. }
  3169. if (name && name.length > 31) {
  3170. // eslint-disable-next-line no-console
  3171. console.warn(`Worksheet name ${name} exceeds 31 chars. This will be truncated`);
  3172. name = name.substring(0, 31);
  3173. }
  3174. if (this._workbook._worksheets.find(ws => ws && ws.name.toLowerCase() === name.toLowerCase())) {
  3175. throw new Error(`Worksheet name already exists: ${name}`);
  3176. }
  3177. this._name = name;
  3178. }
  3179. get workbook() {
  3180. return this._workbook;
  3181. }
  3182. // when you're done with this worksheet, call this to remove from workbook
  3183. destroy() {
  3184. this._workbook.removeWorksheetEx(this);
  3185. }
  3186. // Get the bounding range of the cells in this worksheet
  3187. get dimensions() {
  3188. const dimensions = new Range();
  3189. this._rows.forEach(row => {
  3190. if (row) {
  3191. const rowDims = row.dimensions;
  3192. if (rowDims) {
  3193. dimensions.expand(row.number, rowDims.min, row.number, rowDims.max);
  3194. }
  3195. }
  3196. });
  3197. return dimensions;
  3198. }
  3199. // =========================================================================
  3200. // Columns
  3201. // get the current columns array.
  3202. get columns() {
  3203. return this._columns;
  3204. }
  3205. // set the columns from an array of column definitions.
  3206. // Note: any headers defined will overwrite existing values.
  3207. set columns(value) {
  3208. // calculate max header row count
  3209. this._headerRowCount = value.reduce((pv, cv) => {
  3210. const headerCount = cv.header && 1 || cv.headers && cv.headers.length || 0;
  3211. return Math.max(pv, headerCount);
  3212. }, 0);
  3213. // construct Column objects
  3214. let count = 1;
  3215. const columns = this._columns = [];
  3216. value.forEach(defn => {
  3217. const column = new Column(this, count++, false);
  3218. columns.push(column);
  3219. column.defn = defn;
  3220. });
  3221. }
  3222. getColumnKey(key) {
  3223. return this._keys[key];
  3224. }
  3225. setColumnKey(key, value) {
  3226. this._keys[key] = value;
  3227. }
  3228. deleteColumnKey(key) {
  3229. delete this._keys[key];
  3230. }
  3231. eachColumnKey(f) {
  3232. _.each(this._keys, f);
  3233. }
  3234. // get a single column by col number. If it doesn't exist, create it and any gaps before it
  3235. getColumn(c) {
  3236. if (typeof c === 'string') {
  3237. // if it matches a key'd column, return that
  3238. const col = this._keys[c];
  3239. if (col) return col;
  3240. // otherwise, assume letter
  3241. c = colCache.l2n(c);
  3242. }
  3243. if (!this._columns) {
  3244. this._columns = [];
  3245. }
  3246. if (c > this._columns.length) {
  3247. let n = this._columns.length + 1;
  3248. while (n <= c) {
  3249. this._columns.push(new Column(this, n++));
  3250. }
  3251. }
  3252. return this._columns[c - 1];
  3253. }
  3254. spliceColumns(start, count) {
  3255. const rows = this._rows;
  3256. const nRows = rows.length;
  3257. for (var _len = arguments.length, inserts = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  3258. inserts[_key - 2] = arguments[_key];
  3259. }
  3260. if (inserts.length > 0) {
  3261. // must iterate over all rows whether they exist yet or not
  3262. for (let i = 0; i < nRows; i++) {
  3263. const rowArguments = [start, count];
  3264. // eslint-disable-next-line no-loop-func
  3265. inserts.forEach(insert => {
  3266. rowArguments.push(insert[i] || null);
  3267. });
  3268. const row = this.getRow(i + 1);
  3269. // eslint-disable-next-line prefer-spread
  3270. row.splice.apply(row, rowArguments);
  3271. }
  3272. } else {
  3273. // nothing to insert, so just splice all rows
  3274. this._rows.forEach(r => {
  3275. if (r) {
  3276. r.splice(start, count);
  3277. }
  3278. });
  3279. }
  3280. // splice column definitions
  3281. const nExpand = inserts.length - count;
  3282. const nKeep = start + count;
  3283. const nEnd = this._columns.length;
  3284. if (nExpand < 0) {
  3285. for (let i = start + inserts.length; i <= nEnd; i++) {
  3286. this.getColumn(i).defn = this.getColumn(i - nExpand).defn;
  3287. }
  3288. } else if (nExpand > 0) {
  3289. for (let i = nEnd; i >= nKeep; i--) {
  3290. this.getColumn(i + nExpand).defn = this.getColumn(i).defn;
  3291. }
  3292. }
  3293. for (let i = start; i < start + inserts.length; i++) {
  3294. this.getColumn(i).defn = null;
  3295. }
  3296. // account for defined names
  3297. this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length);
  3298. }
  3299. get lastColumn() {
  3300. return this.getColumn(this.columnCount);
  3301. }
  3302. get columnCount() {
  3303. let maxCount = 0;
  3304. this.eachRow(row => {
  3305. maxCount = Math.max(maxCount, row.cellCount);
  3306. });
  3307. return maxCount;
  3308. }
  3309. get actualColumnCount() {
  3310. // performance nightmare - for each row, counts all the columns used
  3311. const counts = [];
  3312. let count = 0;
  3313. this.eachRow(row => {
  3314. row.eachCell(_ref => {
  3315. let {
  3316. col
  3317. } = _ref;
  3318. if (!counts[col]) {
  3319. counts[col] = true;
  3320. count++;
  3321. }
  3322. });
  3323. });
  3324. return count;
  3325. }
  3326. // =========================================================================
  3327. // Rows
  3328. _commitRow() {
  3329. // nop - allows streaming reader to fill a document
  3330. }
  3331. get _lastRowNumber() {
  3332. // need to cope with results of splice
  3333. const rows = this._rows;
  3334. let n = rows.length;
  3335. while (n > 0 && rows[n - 1] === undefined) {
  3336. n--;
  3337. }
  3338. return n;
  3339. }
  3340. get _nextRow() {
  3341. return this._lastRowNumber + 1;
  3342. }
  3343. get lastRow() {
  3344. if (this._rows.length) {
  3345. return this._rows[this._rows.length - 1];
  3346. }
  3347. return undefined;
  3348. }
  3349. // find a row (if exists) by row number
  3350. findRow(r) {
  3351. return this._rows[r - 1];
  3352. }
  3353. // find multiple rows (if exists) by row number
  3354. findRows(start, length) {
  3355. return this._rows.slice(start - 1, start - 1 + length);
  3356. }
  3357. get rowCount() {
  3358. return this._lastRowNumber;
  3359. }
  3360. get actualRowCount() {
  3361. // counts actual rows that have actual data
  3362. let count = 0;
  3363. this.eachRow(() => {
  3364. count++;
  3365. });
  3366. return count;
  3367. }
  3368. // get a row by row number.
  3369. getRow(r) {
  3370. let row = this._rows[r - 1];
  3371. if (!row) {
  3372. row = this._rows[r - 1] = new Row(this, r);
  3373. }
  3374. return row;
  3375. }
  3376. // get multiple rows by row number.
  3377. getRows(start, length) {
  3378. if (length < 1) return undefined;
  3379. const rows = [];
  3380. for (let i = start; i < start + length; i++) {
  3381. rows.push(this.getRow(i));
  3382. }
  3383. return rows;
  3384. }
  3385. addRow(value) {
  3386. let style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'n';
  3387. const rowNo = this._nextRow;
  3388. const row = this.getRow(rowNo);
  3389. row.values = value;
  3390. this._setStyleOption(rowNo, style[0] === 'i' ? style : 'n');
  3391. return row;
  3392. }
  3393. addRows(value) {
  3394. let style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'n';
  3395. const rows = [];
  3396. value.forEach(row => {
  3397. rows.push(this.addRow(row, style));
  3398. });
  3399. return rows;
  3400. }
  3401. insertRow(pos, value) {
  3402. let style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'n';
  3403. this.spliceRows(pos, 0, value);
  3404. this._setStyleOption(pos, style);
  3405. return this.getRow(pos);
  3406. }
  3407. insertRows(pos, values) {
  3408. let style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'n';
  3409. this.spliceRows(pos, 0, ...values);
  3410. if (style !== 'n') {
  3411. // copy over the styles
  3412. for (let i = 0; i < values.length; i++) {
  3413. if (style[0] === 'o' && this.findRow(values.length + pos + i) !== undefined) {
  3414. this._copyStyle(values.length + pos + i, pos + i, style[1] === '+');
  3415. } else if (style[0] === 'i' && this.findRow(pos - 1) !== undefined) {
  3416. this._copyStyle(pos - 1, pos + i, style[1] === '+');
  3417. }
  3418. }
  3419. }
  3420. return this.getRows(pos, values.length);
  3421. }
  3422. // set row at position to same style as of either pervious row (option 'i') or next row (option 'o')
  3423. _setStyleOption(pos) {
  3424. let style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'n';
  3425. if (style[0] === 'o' && this.findRow(pos + 1) !== undefined) {
  3426. this._copyStyle(pos + 1, pos, style[1] === '+');
  3427. } else if (style[0] === 'i' && this.findRow(pos - 1) !== undefined) {
  3428. this._copyStyle(pos - 1, pos, style[1] === '+');
  3429. }
  3430. }
  3431. _copyStyle(src, dest) {
  3432. let styleEmpty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3433. const rSrc = this.getRow(src);
  3434. const rDst = this.getRow(dest);
  3435. rDst.style = copyStyle(rSrc.style);
  3436. // eslint-disable-next-line no-loop-func
  3437. rSrc.eachCell({
  3438. includeEmpty: styleEmpty
  3439. }, (cell, colNumber) => {
  3440. rDst.getCell(colNumber).style = copyStyle(cell.style);
  3441. });
  3442. rDst.height = rSrc.height;
  3443. }
  3444. duplicateRow(rowNum, count) {
  3445. let insert = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3446. // create count duplicates of rowNum
  3447. // either inserting new or overwriting existing rows
  3448. const rSrc = this._rows[rowNum - 1];
  3449. const inserts = new Array(count).fill(rSrc.values);
  3450. this.spliceRows(rowNum + 1, insert ? 0 : count, ...inserts);
  3451. // now copy styles...
  3452. for (let i = 0; i < count; i++) {
  3453. const rDst = this._rows[rowNum + i];
  3454. rDst.style = rSrc.style;
  3455. rDst.height = rSrc.height;
  3456. // eslint-disable-next-line no-loop-func
  3457. rSrc.eachCell({
  3458. includeEmpty: true
  3459. }, (cell, colNumber) => {
  3460. rDst.getCell(colNumber).style = cell.style;
  3461. });
  3462. }
  3463. }
  3464. spliceRows(start, count) {
  3465. // same problem as row.splice, except worse.
  3466. const nKeep = start + count;
  3467. for (var _len2 = arguments.length, inserts = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  3468. inserts[_key2 - 2] = arguments[_key2];
  3469. }
  3470. const nInserts = inserts.length;
  3471. const nExpand = nInserts - count;
  3472. const nEnd = this._rows.length;
  3473. let i;
  3474. let rSrc;
  3475. if (nExpand < 0) {
  3476. // remove rows
  3477. if (start === nEnd) {
  3478. this._rows[nEnd - 1] = undefined;
  3479. }
  3480. for (i = nKeep; i <= nEnd; i++) {
  3481. rSrc = this._rows[i - 1];
  3482. if (rSrc) {
  3483. const rDst = this.getRow(i + nExpand);
  3484. rDst.values = rSrc.values;
  3485. rDst.style = rSrc.style;
  3486. rDst.height = rSrc.height;
  3487. // eslint-disable-next-line no-loop-func
  3488. rSrc.eachCell({
  3489. includeEmpty: true
  3490. }, (cell, colNumber) => {
  3491. rDst.getCell(colNumber).style = cell.style;
  3492. });
  3493. this._rows[i - 1] = undefined;
  3494. } else {
  3495. this._rows[i + nExpand - 1] = undefined;
  3496. }
  3497. }
  3498. } else if (nExpand > 0) {
  3499. // insert new cells
  3500. for (i = nEnd; i >= nKeep; i--) {
  3501. rSrc = this._rows[i - 1];
  3502. if (rSrc) {
  3503. const rDst = this.getRow(i + nExpand);
  3504. rDst.values = rSrc.values;
  3505. rDst.style = rSrc.style;
  3506. rDst.height = rSrc.height;
  3507. // eslint-disable-next-line no-loop-func
  3508. rSrc.eachCell({
  3509. includeEmpty: true
  3510. }, (cell, colNumber) => {
  3511. rDst.getCell(colNumber).style = cell.style;
  3512. // remerge cells accounting for insert offset
  3513. if (cell._value.constructor.name === 'MergeValue') {
  3514. const cellToBeMerged = this.getRow(cell._row._number + nInserts).getCell(colNumber);
  3515. const prevMaster = cell._value._master;
  3516. const newMaster = this.getRow(prevMaster._row._number + nInserts).getCell(prevMaster._column._number);
  3517. cellToBeMerged.merge(newMaster);
  3518. }
  3519. });
  3520. } else {
  3521. this._rows[i + nExpand - 1] = undefined;
  3522. }
  3523. }
  3524. }
  3525. // now copy over the new values
  3526. for (i = 0; i < nInserts; i++) {
  3527. const rDst = this.getRow(start + i);
  3528. rDst.style = {};
  3529. rDst.values = inserts[i];
  3530. }
  3531. // account for defined names
  3532. this.workbook.definedNames.spliceRows(this.name, start, count, nInserts);
  3533. }
  3534. // iterate over every row in the worksheet, including maybe empty rows
  3535. eachRow(options, iteratee) {
  3536. if (!iteratee) {
  3537. iteratee = options;
  3538. options = undefined;
  3539. }
  3540. if (options && options.includeEmpty) {
  3541. const n = this._rows.length;
  3542. for (let i = 1; i <= n; i++) {
  3543. iteratee(this.getRow(i), i);
  3544. }
  3545. } else {
  3546. this._rows.forEach(row => {
  3547. if (row && row.hasValues) {
  3548. iteratee(row, row.number);
  3549. }
  3550. });
  3551. }
  3552. }
  3553. // return all rows as sparse array
  3554. getSheetValues() {
  3555. const rows = [];
  3556. this._rows.forEach(row => {
  3557. if (row) {
  3558. rows[row.number] = row.values;
  3559. }
  3560. });
  3561. return rows;
  3562. }
  3563. // =========================================================================
  3564. // Cells
  3565. // returns the cell at [r,c] or address given by r. If not found, return undefined
  3566. findCell(r, c) {
  3567. const address = colCache.getAddress(r, c);
  3568. const row = this._rows[address.row - 1];
  3569. return row ? row.findCell(address.col) : undefined;
  3570. }
  3571. // return the cell at [r,c] or address given by r. If not found, create a new one.
  3572. getCell(r, c) {
  3573. const address = colCache.getAddress(r, c);
  3574. const row = this.getRow(address.row);
  3575. return row.getCellEx(address);
  3576. }
  3577. // =========================================================================
  3578. // Merge
  3579. // convert the range defined by ['tl:br'], [tl,br] or [t,l,b,r] into a single 'merged' cell
  3580. mergeCells() {
  3581. for (var _len3 = arguments.length, cells = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  3582. cells[_key3] = arguments[_key3];
  3583. }
  3584. const dimensions = new Range(cells);
  3585. this._mergeCellsInternal(dimensions);
  3586. }
  3587. mergeCellsWithoutStyle() {
  3588. for (var _len4 = arguments.length, cells = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  3589. cells[_key4] = arguments[_key4];
  3590. }
  3591. const dimensions = new Range(cells);
  3592. this._mergeCellsInternal(dimensions, true);
  3593. }
  3594. _mergeCellsInternal(dimensions, ignoreStyle) {
  3595. // check cells aren't already merged
  3596. _.each(this._merges, merge => {
  3597. if (merge.intersects(dimensions)) {
  3598. throw new Error('Cannot merge already merged cells');
  3599. }
  3600. });
  3601. // apply merge
  3602. const master = this.getCell(dimensions.top, dimensions.left);
  3603. for (let i = dimensions.top; i <= dimensions.bottom; i++) {
  3604. for (let j = dimensions.left; j <= dimensions.right; j++) {
  3605. // merge all but the master cell
  3606. if (i > dimensions.top || j > dimensions.left) {
  3607. this.getCell(i, j).merge(master, ignoreStyle);
  3608. }
  3609. }
  3610. }
  3611. // index merge
  3612. this._merges[master.address] = dimensions;
  3613. }
  3614. _unMergeMaster(master) {
  3615. // master is always top left of a rectangle
  3616. const merge = this._merges[master.address];
  3617. if (merge) {
  3618. for (let i = merge.top; i <= merge.bottom; i++) {
  3619. for (let j = merge.left; j <= merge.right; j++) {
  3620. this.getCell(i, j).unmerge();
  3621. }
  3622. }
  3623. delete this._merges[master.address];
  3624. }
  3625. }
  3626. get hasMerges() {
  3627. // return true if this._merges has a merge object
  3628. return _.some(this._merges, Boolean);
  3629. }
  3630. // scan the range defined by ['tl:br'], [tl,br] or [t,l,b,r] and if any cell is part of a merge,
  3631. // un-merge the group. Note this function can affect multiple merges and merge-blocks are
  3632. // atomic - either they're all merged or all un-merged.
  3633. unMergeCells() {
  3634. for (var _len5 = arguments.length, cells = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  3635. cells[_key5] = arguments[_key5];
  3636. }
  3637. const dimensions = new Range(cells);
  3638. // find any cells in that range and unmerge them
  3639. for (let i = dimensions.top; i <= dimensions.bottom; i++) {
  3640. for (let j = dimensions.left; j <= dimensions.right; j++) {
  3641. const cell = this.findCell(i, j);
  3642. if (cell) {
  3643. if (cell.type === Enums.ValueType.Merge) {
  3644. // this cell merges to another master
  3645. this._unMergeMaster(cell.master);
  3646. } else if (this._merges[cell.address]) {
  3647. // this cell is a master
  3648. this._unMergeMaster(cell);
  3649. }
  3650. }
  3651. }
  3652. }
  3653. }
  3654. // ===========================================================================
  3655. // Shared/Array Formula
  3656. fillFormula(range, formula, results) {
  3657. let shareType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'shared';
  3658. // Define formula for top-left cell and share to rest
  3659. const decoded = colCache.decode(range);
  3660. const {
  3661. top,
  3662. left,
  3663. bottom,
  3664. right
  3665. } = decoded;
  3666. const width = right - left + 1;
  3667. const masterAddress = colCache.encodeAddress(top, left);
  3668. const isShared = shareType === 'shared';
  3669. // work out result accessor
  3670. let getResult;
  3671. if (typeof results === 'function') {
  3672. getResult = results;
  3673. } else if (Array.isArray(results)) {
  3674. if (Array.isArray(results[0])) {
  3675. getResult = (row, col) => results[row - top][col - left];
  3676. } else {
  3677. // eslint-disable-next-line no-mixed-operators
  3678. getResult = (row, col) => results[(row - top) * width + (col - left)];
  3679. }
  3680. } else {
  3681. getResult = () => undefined;
  3682. }
  3683. let first = true;
  3684. for (let r = top; r <= bottom; r++) {
  3685. for (let c = left; c <= right; c++) {
  3686. if (first) {
  3687. this.getCell(r, c).value = {
  3688. shareType,
  3689. formula,
  3690. ref: range,
  3691. result: getResult(r, c)
  3692. };
  3693. first = false;
  3694. } else {
  3695. this.getCell(r, c).value = isShared ? {
  3696. sharedFormula: masterAddress,
  3697. result: getResult(r, c)
  3698. } : getResult(r, c);
  3699. }
  3700. }
  3701. }
  3702. }
  3703. // =========================================================================
  3704. // Images
  3705. addImage(imageId, range) {
  3706. const model = {
  3707. type: 'image',
  3708. imageId,
  3709. range
  3710. };
  3711. this._media.push(new Image(this, model));
  3712. }
  3713. getImages() {
  3714. return this._media.filter(m => m.type === 'image');
  3715. }
  3716. addBackgroundImage(imageId) {
  3717. const model = {
  3718. type: 'background',
  3719. imageId
  3720. };
  3721. this._media.push(new Image(this, model));
  3722. }
  3723. getBackgroundImageId() {
  3724. const image = this._media.find(m => m.type === 'background');
  3725. return image && image.imageId;
  3726. }
  3727. // =========================================================================
  3728. // Worksheet Protection
  3729. protect(password, options) {
  3730. // TODO: make this function truly async
  3731. // perhaps marshal to worker thread or something
  3732. return new Promise(resolve => {
  3733. this.sheetProtection = {
  3734. sheet: true
  3735. };
  3736. if (options && 'spinCount' in options) {
  3737. // force spinCount to be integer >= 0
  3738. options.spinCount = Number.isFinite(options.spinCount) ? Math.round(Math.max(0, options.spinCount)) : 100000;
  3739. }
  3740. if (password) {
  3741. this.sheetProtection.algorithmName = 'SHA-512';
  3742. this.sheetProtection.saltValue = Encryptor.randomBytes(16).toString('base64');
  3743. this.sheetProtection.spinCount = options && 'spinCount' in options ? options.spinCount : 100000; // allow user specified spinCount
  3744. this.sheetProtection.hashValue = Encryptor.convertPasswordToHash(password, 'SHA512', this.sheetProtection.saltValue, this.sheetProtection.spinCount);
  3745. }
  3746. if (options) {
  3747. this.sheetProtection = Object.assign(this.sheetProtection, options);
  3748. if (!password && 'spinCount' in options) {
  3749. delete this.sheetProtection.spinCount;
  3750. }
  3751. }
  3752. resolve();
  3753. });
  3754. }
  3755. unprotect() {
  3756. this.sheetProtection = null;
  3757. }
  3758. // =========================================================================
  3759. // Tables
  3760. addTable(model) {
  3761. const table = new Table(this, model);
  3762. this.tables[model.name] = table;
  3763. return table;
  3764. }
  3765. getTable(name) {
  3766. return this.tables[name];
  3767. }
  3768. removeTable(name) {
  3769. delete this.tables[name];
  3770. }
  3771. getTables() {
  3772. return Object.values(this.tables);
  3773. }
  3774. // ===========================================================================
  3775. // Conditional Formatting
  3776. addConditionalFormatting(cf) {
  3777. this.conditionalFormattings.push(cf);
  3778. }
  3779. removeConditionalFormatting(filter) {
  3780. if (typeof filter === 'number') {
  3781. this.conditionalFormattings.splice(filter, 1);
  3782. } else if (filter instanceof Function) {
  3783. this.conditionalFormattings = this.conditionalFormattings.filter(filter);
  3784. } else {
  3785. this.conditionalFormattings = [];
  3786. }
  3787. }
  3788. // ===========================================================================
  3789. // Deprecated
  3790. get tabColor() {
  3791. // eslint-disable-next-line no-console
  3792. console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
  3793. return this.properties.tabColor;
  3794. }
  3795. set tabColor(value) {
  3796. // eslint-disable-next-line no-console
  3797. console.trace('worksheet.tabColor property is now deprecated. Please use worksheet.properties.tabColor');
  3798. this.properties.tabColor = value;
  3799. }
  3800. // ===========================================================================
  3801. // Model
  3802. get model() {
  3803. const model = {
  3804. id: this.id,
  3805. name: this.name,
  3806. dataValidations: this.dataValidations.model,
  3807. properties: this.properties,
  3808. state: this.state,
  3809. pageSetup: this.pageSetup,
  3810. headerFooter: this.headerFooter,
  3811. rowBreaks: this.rowBreaks,
  3812. views: this.views,
  3813. autoFilter: this.autoFilter,
  3814. media: this._media.map(medium => medium.model),
  3815. sheetProtection: this.sheetProtection,
  3816. tables: Object.values(this.tables).map(table => table.model),
  3817. conditionalFormattings: this.conditionalFormattings
  3818. };
  3819. // =================================================
  3820. // columns
  3821. model.cols = Column.toModel(this.columns);
  3822. // ==========================================================
  3823. // Rows
  3824. const rows = model.rows = [];
  3825. const dimensions = model.dimensions = new Range();
  3826. this._rows.forEach(row => {
  3827. const rowModel = row && row.model;
  3828. if (rowModel) {
  3829. dimensions.expand(rowModel.number, rowModel.min, rowModel.number, rowModel.max);
  3830. rows.push(rowModel);
  3831. }
  3832. });
  3833. // ==========================================================
  3834. // Merges
  3835. model.merges = [];
  3836. _.each(this._merges, merge => {
  3837. model.merges.push(merge.range);
  3838. });
  3839. return model;
  3840. }
  3841. _parseRows(model) {
  3842. this._rows = [];
  3843. model.rows.forEach(rowModel => {
  3844. const row = new Row(this, rowModel.number);
  3845. this._rows[row.number - 1] = row;
  3846. row.model = rowModel;
  3847. });
  3848. }
  3849. _parseMergeCells(model) {
  3850. _.each(model.mergeCells, merge => {
  3851. // Do not merge styles when importing an Excel file
  3852. // since each cell may have different styles intentionally.
  3853. this.mergeCellsWithoutStyle(merge);
  3854. });
  3855. }
  3856. set model(value) {
  3857. this.name = value.name;
  3858. this._columns = Column.fromModel(this, value.cols);
  3859. this._parseRows(value);
  3860. this._parseMergeCells(value);
  3861. this.dataValidations = new DataValidations(value.dataValidations);
  3862. this.properties = value.properties;
  3863. this.pageSetup = value.pageSetup;
  3864. this.headerFooter = value.headerFooter;
  3865. this.views = value.views;
  3866. this.autoFilter = value.autoFilter;
  3867. this._media = value.media.map(medium => new Image(this, medium));
  3868. this.sheetProtection = value.sheetProtection;
  3869. this.tables = value.tables.reduce((tables, table) => {
  3870. const t = new Table();
  3871. t.model = table;
  3872. tables[table.name] = t;
  3873. return tables;
  3874. }, {});
  3875. this.conditionalFormattings = value.conditionalFormattings;
  3876. }
  3877. }
  3878. module.exports = Worksheet;
  3879. },{"../utils/col-cache":19,"../utils/copy-style":20,"../utils/encryptor":21,"../utils/under-dash":26,"./column":4,"./data-validations":5,"./enums":7,"./image":8,"./range":10,"./row":11,"./table":12}],15:[function(require,module,exports){
  3880. "use strict";
  3881. /* eslint-disable import/no-extraneous-dependencies,node/no-unpublished-require */
  3882. require('core-js/modules/es.promise');
  3883. require('core-js/modules/es.promise.finally');
  3884. require('core-js/modules/es.object.assign');
  3885. require('core-js/modules/es.object.keys');
  3886. require('core-js/modules/es.object.values');
  3887. require('core-js/modules/es.symbol');
  3888. require('core-js/modules/es.symbol.async-iterator');
  3889. // required by core-js/modules/es.promise Promise.all
  3890. require('core-js/modules/es.array.iterator');
  3891. // required by node_modules/saxes/saxes.js SaxesParser.captureTo
  3892. require('core-js/modules/es.array.includes');
  3893. // required by lib/doc/workbook.js Workbook.model
  3894. require('core-js/modules/es.array.find-index');
  3895. // required by lib/doc/workbook.js Workbook.addWorksheet and Workbook.getWorksheet
  3896. require('core-js/modules/es.array.find');
  3897. // required by node_modules/saxes/saxes.js SaxesParser.getCode10
  3898. require('core-js/modules/es.string.from-code-point');
  3899. // required by lib/xlsx/xform/sheet/data-validations-xform.js DataValidationsXform.parseClose
  3900. require('core-js/modules/es.string.includes');
  3901. // required by lib/utils/utils.js utils.validInt and lib/csv/csv.js CSV.read
  3902. require('core-js/modules/es.number.is-nan');
  3903. require('regenerator-runtime/runtime');
  3904. const ExcelJS = {
  3905. Workbook: require('./doc/workbook')
  3906. };
  3907. // Object.assign mono-fill
  3908. const Enums = require('./doc/enums');
  3909. Object.keys(Enums).forEach(key => {
  3910. ExcelJS[key] = Enums[key];
  3911. });
  3912. module.exports = ExcelJS;
  3913. },{"./doc/enums":7,"./doc/workbook":13,"core-js/modules/es.array.find":359,"core-js/modules/es.array.find-index":358,"core-js/modules/es.array.includes":360,"core-js/modules/es.array.iterator":361,"core-js/modules/es.number.is-nan":363,"core-js/modules/es.object.assign":364,"core-js/modules/es.object.keys":366,"core-js/modules/es.object.values":367,"core-js/modules/es.promise":372,"core-js/modules/es.promise.finally":371,"core-js/modules/es.string.from-code-point":376,"core-js/modules/es.string.includes":377,"core-js/modules/es.symbol":381,"core-js/modules/es.symbol.async-iterator":378,"regenerator-runtime/runtime":492}],16:[function(require,module,exports){
  3914. "use strict";
  3915. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  3916. const textDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8');
  3917. function bufferToString(chunk) {
  3918. if (typeof chunk === 'string') {
  3919. return chunk;
  3920. }
  3921. if (textDecoder) {
  3922. return textDecoder.decode(chunk);
  3923. }
  3924. return chunk.toString();
  3925. }
  3926. exports.bufferToString = bufferToString;
  3927. },{}],17:[function(require,module,exports){
  3928. "use strict";
  3929. // eslint-disable-next-line node/no-unsupported-features/node-builtins
  3930. const textEncoder = typeof TextEncoder === 'undefined' ? null : new TextEncoder('utf-8');
  3931. const {
  3932. Buffer
  3933. } = require('buffer');
  3934. function stringToBuffer(str) {
  3935. if (typeof str !== 'string') {
  3936. return str;
  3937. }
  3938. if (textEncoder) {
  3939. return Buffer.from(textEncoder.encode(str).buffer);
  3940. }
  3941. return Buffer.from(str);
  3942. }
  3943. exports.stringToBuffer = stringToBuffer;
  3944. },{"buffer":220}],18:[function(require,module,exports){
  3945. "use strict";
  3946. const _ = require('./under-dash');
  3947. const colCache = require('./col-cache');
  3948. class CellMatrix {
  3949. constructor(template) {
  3950. this.template = template;
  3951. this.sheets = {};
  3952. }
  3953. addCell(addressStr) {
  3954. this.addCellEx(colCache.decodeEx(addressStr));
  3955. }
  3956. getCell(addressStr) {
  3957. return this.findCellEx(colCache.decodeEx(addressStr), true);
  3958. }
  3959. findCell(addressStr) {
  3960. return this.findCellEx(colCache.decodeEx(addressStr), false);
  3961. }
  3962. findCellAt(sheetName, rowNumber, colNumber) {
  3963. const sheet = this.sheets[sheetName];
  3964. const row = sheet && sheet[rowNumber];
  3965. return row && row[colNumber];
  3966. }
  3967. addCellEx(address) {
  3968. if (address.top) {
  3969. for (let row = address.top; row <= address.bottom; row++) {
  3970. for (let col = address.left; col <= address.right; col++) {
  3971. this.getCellAt(address.sheetName, row, col);
  3972. }
  3973. }
  3974. } else {
  3975. this.findCellEx(address, true);
  3976. }
  3977. }
  3978. getCellEx(address) {
  3979. return this.findCellEx(address, true);
  3980. }
  3981. findCellEx(address, create) {
  3982. const sheet = this.findSheet(address, create);
  3983. const row = this.findSheetRow(sheet, address, create);
  3984. return this.findRowCell(row, address, create);
  3985. }
  3986. getCellAt(sheetName, rowNumber, colNumber) {
  3987. const sheet = this.sheets[sheetName] || (this.sheets[sheetName] = []);
  3988. const row = sheet[rowNumber] || (sheet[rowNumber] = []);
  3989. const cell = row[colNumber] || (row[colNumber] = {
  3990. sheetName,
  3991. address: colCache.n2l(colNumber) + rowNumber,
  3992. row: rowNumber,
  3993. col: colNumber
  3994. });
  3995. return cell;
  3996. }
  3997. removeCellEx(address) {
  3998. const sheet = this.findSheet(address);
  3999. if (!sheet) {
  4000. return;
  4001. }
  4002. const row = this.findSheetRow(sheet, address);
  4003. if (!row) {
  4004. return;
  4005. }
  4006. delete row[address.col];
  4007. }
  4008. forEachInSheet(sheetName, callback) {
  4009. const sheet = this.sheets[sheetName];
  4010. if (sheet) {
  4011. sheet.forEach((row, rowNumber) => {
  4012. if (row) {
  4013. row.forEach((cell, colNumber) => {
  4014. if (cell) {
  4015. callback(cell, rowNumber, colNumber);
  4016. }
  4017. });
  4018. }
  4019. });
  4020. }
  4021. }
  4022. forEach(callback) {
  4023. _.each(this.sheets, (sheet, sheetName) => {
  4024. this.forEachInSheet(sheetName, callback);
  4025. });
  4026. }
  4027. map(callback) {
  4028. const results = [];
  4029. this.forEach(cell => {
  4030. results.push(callback(cell));
  4031. });
  4032. return results;
  4033. }
  4034. findSheet(address, create) {
  4035. const name = address.sheetName;
  4036. if (this.sheets[name]) {
  4037. return this.sheets[name];
  4038. }
  4039. if (create) {
  4040. return this.sheets[name] = [];
  4041. }
  4042. return undefined;
  4043. }
  4044. findSheetRow(sheet, address, create) {
  4045. const {
  4046. row
  4047. } = address;
  4048. if (sheet && sheet[row]) {
  4049. return sheet[row];
  4050. }
  4051. if (create) {
  4052. return sheet[row] = [];
  4053. }
  4054. return undefined;
  4055. }
  4056. findRowCell(row, address, create) {
  4057. const {
  4058. col
  4059. } = address;
  4060. if (row && row[col]) {
  4061. return row[col];
  4062. }
  4063. if (create) {
  4064. return row[col] = this.template ? Object.assign(address, JSON.parse(JSON.stringify(this.template))) : address;
  4065. }
  4066. return undefined;
  4067. }
  4068. spliceRows(sheetName, start, numDelete, numInsert) {
  4069. const sheet = this.sheets[sheetName];
  4070. if (sheet) {
  4071. const inserts = [];
  4072. for (let i = 0; i < numInsert; i++) {
  4073. inserts.push([]);
  4074. }
  4075. sheet.splice(start, numDelete, ...inserts);
  4076. }
  4077. }
  4078. spliceColumns(sheetName, start, numDelete, numInsert) {
  4079. const sheet = this.sheets[sheetName];
  4080. if (sheet) {
  4081. const inserts = [];
  4082. for (let i = 0; i < numInsert; i++) {
  4083. inserts.push(null);
  4084. }
  4085. _.each(sheet, row => {
  4086. row.splice(start, numDelete, ...inserts);
  4087. });
  4088. }
  4089. }
  4090. }
  4091. module.exports = CellMatrix;
  4092. },{"./col-cache":19,"./under-dash":26}],19:[function(require,module,exports){
  4093. "use strict";
  4094. const addressRegex = /^[A-Z]+\d+$/;
  4095. // =========================================================================
  4096. // Column Letter to Number conversion
  4097. const colCache = {
  4098. _dictionary: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
  4099. _l2nFill: 0,
  4100. _l2n: {},
  4101. _n2l: [],
  4102. _level(n) {
  4103. if (n <= 26) {
  4104. return 1;
  4105. }
  4106. if (n <= 26 * 26) {
  4107. return 2;
  4108. }
  4109. return 3;
  4110. },
  4111. _fill(level) {
  4112. let c;
  4113. let v;
  4114. let l1;
  4115. let l2;
  4116. let l3;
  4117. let n = 1;
  4118. if (level >= 4) {
  4119. throw new Error('Out of bounds. Excel supports columns from 1 to 16384');
  4120. }
  4121. if (this._l2nFill < 1 && level >= 1) {
  4122. while (n <= 26) {
  4123. c = this._dictionary[n - 1];
  4124. this._n2l[n] = c;
  4125. this._l2n[c] = n;
  4126. n++;
  4127. }
  4128. this._l2nFill = 1;
  4129. }
  4130. if (this._l2nFill < 2 && level >= 2) {
  4131. n = 27;
  4132. while (n <= 26 + 26 * 26) {
  4133. v = n - (26 + 1);
  4134. l1 = v % 26;
  4135. l2 = Math.floor(v / 26);
  4136. c = this._dictionary[l2] + this._dictionary[l1];
  4137. this._n2l[n] = c;
  4138. this._l2n[c] = n;
  4139. n++;
  4140. }
  4141. this._l2nFill = 2;
  4142. }
  4143. if (this._l2nFill < 3 && level >= 3) {
  4144. n = 26 + 26 * 26 + 1;
  4145. while (n <= 16384) {
  4146. v = n - (26 * 26 + 26 + 1);
  4147. l1 = v % 26;
  4148. l2 = Math.floor(v / 26) % 26;
  4149. l3 = Math.floor(v / (26 * 26));
  4150. c = this._dictionary[l3] + this._dictionary[l2] + this._dictionary[l1];
  4151. this._n2l[n] = c;
  4152. this._l2n[c] = n;
  4153. n++;
  4154. }
  4155. this._l2nFill = 3;
  4156. }
  4157. },
  4158. l2n(l) {
  4159. if (!this._l2n[l]) {
  4160. this._fill(l.length);
  4161. }
  4162. if (!this._l2n[l]) {
  4163. throw new Error(`Out of bounds. Invalid column letter: ${l}`);
  4164. }
  4165. return this._l2n[l];
  4166. },
  4167. n2l(n) {
  4168. if (n < 1 || n > 16384) {
  4169. throw new Error(`${n} is out of bounds. Excel supports columns from 1 to 16384`);
  4170. }
  4171. if (!this._n2l[n]) {
  4172. this._fill(this._level(n));
  4173. }
  4174. return this._n2l[n];
  4175. },
  4176. // =========================================================================
  4177. // Address processing
  4178. _hash: {},
  4179. // check if value looks like an address
  4180. validateAddress(value) {
  4181. if (!addressRegex.test(value)) {
  4182. throw new Error(`Invalid Address: ${value}`);
  4183. }
  4184. return true;
  4185. },
  4186. // convert address string into structure
  4187. decodeAddress(value) {
  4188. const addr = value.length < 5 && this._hash[value];
  4189. if (addr) {
  4190. return addr;
  4191. }
  4192. let hasCol = false;
  4193. let col = '';
  4194. let colNumber = 0;
  4195. let hasRow = false;
  4196. let row = '';
  4197. let rowNumber = 0;
  4198. for (let i = 0, char; i < value.length; i++) {
  4199. char = value.charCodeAt(i);
  4200. // col should before row
  4201. if (!hasRow && char >= 65 && char <= 90) {
  4202. // 65 = 'A'.charCodeAt(0)
  4203. // 90 = 'Z'.charCodeAt(0)
  4204. hasCol = true;
  4205. col += value[i];
  4206. // colNumber starts from 1
  4207. colNumber = colNumber * 26 + char - 64;
  4208. } else if (char >= 48 && char <= 57) {
  4209. // 48 = '0'.charCodeAt(0)
  4210. // 57 = '9'.charCodeAt(0)
  4211. hasRow = true;
  4212. row += value[i];
  4213. // rowNumber starts from 0
  4214. rowNumber = rowNumber * 10 + char - 48;
  4215. } else if (hasRow && hasCol && char !== 36) {
  4216. // 36 = '$'.charCodeAt(0)
  4217. break;
  4218. }
  4219. }
  4220. if (!hasCol) {
  4221. colNumber = undefined;
  4222. } else if (colNumber > 16384) {
  4223. throw new Error(`Out of bounds. Invalid column letter: ${col}`);
  4224. }
  4225. if (!hasRow) {
  4226. rowNumber = undefined;
  4227. }
  4228. // in case $row$col
  4229. value = col + row;
  4230. const address = {
  4231. address: value,
  4232. col: colNumber,
  4233. row: rowNumber,
  4234. $col$row: `$${col}$${row}`
  4235. };
  4236. // mem fix - cache only the tl 100x100 square
  4237. if (colNumber <= 100 && rowNumber <= 100) {
  4238. this._hash[value] = address;
  4239. this._hash[address.$col$row] = address;
  4240. }
  4241. return address;
  4242. },
  4243. // convert r,c into structure (if only 1 arg, assume r is address string)
  4244. getAddress(r, c) {
  4245. if (c) {
  4246. const address = this.n2l(c) + r;
  4247. return this.decodeAddress(address);
  4248. }
  4249. return this.decodeAddress(r);
  4250. },
  4251. // convert [address], [tl:br] into address structures
  4252. decode(value) {
  4253. const parts = value.split(':');
  4254. if (parts.length === 2) {
  4255. const tl = this.decodeAddress(parts[0]);
  4256. const br = this.decodeAddress(parts[1]);
  4257. const result = {
  4258. top: Math.min(tl.row, br.row),
  4259. left: Math.min(tl.col, br.col),
  4260. bottom: Math.max(tl.row, br.row),
  4261. right: Math.max(tl.col, br.col)
  4262. };
  4263. // reconstruct tl, br and dimensions
  4264. result.tl = this.n2l(result.left) + result.top;
  4265. result.br = this.n2l(result.right) + result.bottom;
  4266. result.dimensions = `${result.tl}:${result.br}`;
  4267. return result;
  4268. }
  4269. return this.decodeAddress(value);
  4270. },
  4271. // convert [sheetName!][$]col[$]row[[$]col[$]row] into address or range structures
  4272. decodeEx(value) {
  4273. const groups = value.match(/(?:(?:(?:'((?:[^']|'')*)')|([^'^ !]*))!)?(.*)/);
  4274. const sheetName = groups[1] || groups[2]; // Qouted and unqouted groups
  4275. const reference = groups[3]; // Remaining address
  4276. const parts = reference.split(':');
  4277. if (parts.length > 1) {
  4278. let tl = this.decodeAddress(parts[0]);
  4279. let br = this.decodeAddress(parts[1]);
  4280. const top = Math.min(tl.row, br.row);
  4281. const left = Math.min(tl.col, br.col);
  4282. const bottom = Math.max(tl.row, br.row);
  4283. const right = Math.max(tl.col, br.col);
  4284. tl = this.n2l(left) + top;
  4285. br = this.n2l(right) + bottom;
  4286. return {
  4287. top,
  4288. left,
  4289. bottom,
  4290. right,
  4291. sheetName,
  4292. tl: {
  4293. address: tl,
  4294. col: left,
  4295. row: top,
  4296. $col$row: `$${this.n2l(left)}$${top}`,
  4297. sheetName
  4298. },
  4299. br: {
  4300. address: br,
  4301. col: right,
  4302. row: bottom,
  4303. $col$row: `$${this.n2l(right)}$${bottom}`,
  4304. sheetName
  4305. },
  4306. dimensions: `${tl}:${br}`
  4307. };
  4308. }
  4309. if (reference.startsWith('#')) {
  4310. return sheetName ? {
  4311. sheetName,
  4312. error: reference
  4313. } : {
  4314. error: reference
  4315. };
  4316. }
  4317. const address = this.decodeAddress(reference);
  4318. return sheetName ? {
  4319. sheetName,
  4320. ...address
  4321. } : address;
  4322. },
  4323. // convert row,col into address string
  4324. encodeAddress(row, col) {
  4325. return colCache.n2l(col) + row;
  4326. },
  4327. // convert row,col into string address or t,l,b,r into range
  4328. encode() {
  4329. switch (arguments.length) {
  4330. case 2:
  4331. return colCache.encodeAddress(arguments[0], arguments[1]);
  4332. case 4:
  4333. return `${colCache.encodeAddress(arguments[0], arguments[1])}:${colCache.encodeAddress(arguments[2], arguments[3])}`;
  4334. default:
  4335. throw new Error('Can only encode with 2 or 4 arguments');
  4336. }
  4337. },
  4338. // return true if address is contained within range
  4339. inRange(range, address) {
  4340. const [left, top,, right, bottom] = range;
  4341. const [col, row] = address;
  4342. return col >= left && col <= right && row >= top && row <= bottom;
  4343. }
  4344. };
  4345. module.exports = colCache;
  4346. },{}],20:[function(require,module,exports){
  4347. "use strict";
  4348. const oneDepthCopy = (obj, nestKeys) => ({
  4349. ...obj,
  4350. ...nestKeys.reduce((memo, key) => {
  4351. if (obj[key]) memo[key] = {
  4352. ...obj[key]
  4353. };
  4354. return memo;
  4355. }, {})
  4356. });
  4357. const setIfExists = function (src, dst, key) {
  4358. let nestKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  4359. if (src[key]) dst[key] = oneDepthCopy(src[key], nestKeys);
  4360. };
  4361. const isEmptyObj = obj => Object.keys(obj).length === 0;
  4362. const copyStyle = style => {
  4363. if (!style) return style;
  4364. if (isEmptyObj(style)) return {};
  4365. const copied = {
  4366. ...style
  4367. };
  4368. setIfExists(style, copied, 'font', ['color']);
  4369. setIfExists(style, copied, 'alignment');
  4370. setIfExists(style, copied, 'protection');
  4371. if (style.border) {
  4372. setIfExists(style, copied, 'border');
  4373. setIfExists(style.border, copied.border, 'top', ['color']);
  4374. setIfExists(style.border, copied.border, 'left', ['color']);
  4375. setIfExists(style.border, copied.border, 'bottom', ['color']);
  4376. setIfExists(style.border, copied.border, 'right', ['color']);
  4377. setIfExists(style.border, copied.border, 'diagonal', ['color']);
  4378. }
  4379. if (style.fill) {
  4380. setIfExists(style, copied, 'fill', ['fgColor', 'bgColor', 'center']);
  4381. if (style.fill.stops) {
  4382. copied.fill.stops = style.fill.stops.map(s => oneDepthCopy(s, ['color']));
  4383. }
  4384. }
  4385. return copied;
  4386. };
  4387. exports.copyStyle = copyStyle;
  4388. },{}],21:[function(require,module,exports){
  4389. (function (Buffer){(function (){
  4390. 'use strict';
  4391. const crypto = require('crypto');
  4392. const Encryptor = {
  4393. /**
  4394. * Calculate a hash of the concatenated buffers with the given algorithm.
  4395. * @param {string} algorithm - The hash algorithm.
  4396. * @returns {Buffer} The hash
  4397. */
  4398. hash(algorithm) {
  4399. const hash = crypto.createHash(algorithm);
  4400. for (var _len = arguments.length, buffers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  4401. buffers[_key - 1] = arguments[_key];
  4402. }
  4403. hash.update(Buffer.concat(buffers));
  4404. return hash.digest();
  4405. },
  4406. /**
  4407. * Convert a password into an encryption key
  4408. * @param {string} password - The password
  4409. * @param {string} hashAlgorithm - The hash algoritm
  4410. * @param {string} saltValue - The salt value
  4411. * @param {number} spinCount - The spin count
  4412. * @param {number} keyBits - The length of the key in bits
  4413. * @param {Buffer} blockKey - The block key
  4414. * @returns {Buffer} The encryption key
  4415. */
  4416. convertPasswordToHash(password, hashAlgorithm, saltValue, spinCount) {
  4417. hashAlgorithm = hashAlgorithm.toLowerCase();
  4418. const hashes = crypto.getHashes();
  4419. if (hashes.indexOf(hashAlgorithm) < 0) {
  4420. throw new Error(`Hash algorithm '${hashAlgorithm}' not supported!`);
  4421. }
  4422. // Password must be in unicode buffer
  4423. const passwordBuffer = Buffer.from(password, 'utf16le');
  4424. // Generate the initial hash
  4425. let key = this.hash(hashAlgorithm, Buffer.from(saltValue, 'base64'), passwordBuffer);
  4426. // Now regenerate until spin count
  4427. for (let i = 0; i < spinCount; i++) {
  4428. const iterator = Buffer.alloc(4);
  4429. // this is the 'special' element of Excel password hashing
  4430. // that stops us from using crypto.pbkdf2()
  4431. iterator.writeUInt32LE(i, 0);
  4432. key = this.hash(hashAlgorithm, key, iterator);
  4433. }
  4434. return key.toString('base64');
  4435. },
  4436. /**
  4437. * Generates cryptographically strong pseudo-random data.
  4438. * @param size The size argument is a number indicating the number of bytes to generate.
  4439. */
  4440. randomBytes(size) {
  4441. return crypto.randomBytes(size);
  4442. }
  4443. };
  4444. module.exports = Encryptor;
  4445. }).call(this)}).call(this,require("buffer").Buffer)
  4446. },{"buffer":220,"crypto":390}],22:[function(require,module,exports){
  4447. "use strict";
  4448. const {
  4449. SaxesParser
  4450. } = require('saxes');
  4451. const {
  4452. PassThrough
  4453. } = require('readable-stream');
  4454. const {
  4455. bufferToString
  4456. } = require('./browser-buffer-decode');
  4457. module.exports = async function* (iterable) {
  4458. // TODO: Remove once node v8 is deprecated
  4459. // Detect and upgrade old streams
  4460. if (iterable.pipe && !iterable[Symbol.asyncIterator]) {
  4461. iterable = iterable.pipe(new PassThrough());
  4462. }
  4463. const saxesParser = new SaxesParser();
  4464. let error;
  4465. saxesParser.on('error', err => {
  4466. error = err;
  4467. });
  4468. let events = [];
  4469. saxesParser.on('opentag', value => events.push({
  4470. eventType: 'opentag',
  4471. value
  4472. }));
  4473. saxesParser.on('text', value => events.push({
  4474. eventType: 'text',
  4475. value
  4476. }));
  4477. saxesParser.on('closetag', value => events.push({
  4478. eventType: 'closetag',
  4479. value
  4480. }));
  4481. for await (const chunk of iterable) {
  4482. saxesParser.write(bufferToString(chunk));
  4483. // saxesParser.write and saxesParser.on() are synchronous,
  4484. // so we can only reach the below line once all events have been emitted
  4485. if (error) throw error;
  4486. // As a performance optimization, we gather all events instead of passing
  4487. // them one by one, which would cause each event to go through the event queue
  4488. yield events;
  4489. events = [];
  4490. }
  4491. };
  4492. },{"./browser-buffer-decode":16,"readable-stream":491,"saxes":496}],23:[function(require,module,exports){
  4493. "use strict";
  4494. const colCache = require('./col-cache');
  4495. // const cellRefRegex = /(([a-z_\-0-9]*)!)?[$]?([a-z]+)[$]?([1-9][0-9]*)/i;
  4496. const replacementCandidateRx = /(([a-z_\-0-9]*)!)?([a-z0-9_$]{2,})([(])?/gi;
  4497. const CRrx = /^([$])?([a-z]+)([$])?([1-9][0-9]*)$/i;
  4498. function slideFormula(formula, fromCell, toCell) {
  4499. const offset = colCache.decode(fromCell);
  4500. const to = colCache.decode(toCell);
  4501. return formula.replace(replacementCandidateRx, (refMatch, sheet, sheetMaybe, addrPart, trailingParen) => {
  4502. if (trailingParen) {
  4503. return refMatch;
  4504. }
  4505. const match = CRrx.exec(addrPart);
  4506. if (match) {
  4507. const colDollar = match[1];
  4508. const colStr = match[2].toUpperCase();
  4509. const rowDollar = match[3];
  4510. const rowStr = match[4];
  4511. if (colStr.length > 3 || colStr.length === 3 && colStr > 'XFD') {
  4512. // > XFD is the highest col number in excel 2007 and beyond, so this is a named range
  4513. return refMatch;
  4514. }
  4515. let col = colCache.l2n(colStr);
  4516. let row = parseInt(rowStr, 10);
  4517. if (!colDollar) {
  4518. col += to.col - offset.col;
  4519. }
  4520. if (!rowDollar) {
  4521. row += to.row - offset.row;
  4522. }
  4523. const res = (sheet || '') + (colDollar || '') + colCache.n2l(col) + (rowDollar || '') + row;
  4524. return res;
  4525. }
  4526. return refMatch;
  4527. });
  4528. }
  4529. module.exports = {
  4530. slideFormula
  4531. };
  4532. },{"./col-cache":19}],24:[function(require,module,exports){
  4533. (function (process,Buffer){(function (){
  4534. "use strict";
  4535. /* eslint-disable max-classes-per-file */
  4536. const Stream = require('readable-stream');
  4537. const utils = require('./utils');
  4538. const StringBuf = require('./string-buf');
  4539. // =============================================================================
  4540. // data chunks - encapsulating incoming data
  4541. class StringChunk {
  4542. constructor(data, encoding) {
  4543. this._data = data;
  4544. this._encoding = encoding;
  4545. }
  4546. get length() {
  4547. return this.toBuffer().length;
  4548. }
  4549. // copy to target buffer
  4550. copy(target, targetOffset, offset, length) {
  4551. return this.toBuffer().copy(target, targetOffset, offset, length);
  4552. }
  4553. toBuffer() {
  4554. if (!this._buffer) {
  4555. this._buffer = Buffer.from(this._data, this._encoding);
  4556. }
  4557. return this._buffer;
  4558. }
  4559. }
  4560. class StringBufChunk {
  4561. constructor(data) {
  4562. this._data = data;
  4563. }
  4564. get length() {
  4565. return this._data.length;
  4566. }
  4567. // copy to target buffer
  4568. copy(target, targetOffset, offset, length) {
  4569. // eslint-disable-next-line no-underscore-dangle
  4570. return this._data._buf.copy(target, targetOffset, offset, length);
  4571. }
  4572. toBuffer() {
  4573. return this._data.toBuffer();
  4574. }
  4575. }
  4576. class BufferChunk {
  4577. constructor(data) {
  4578. this._data = data;
  4579. }
  4580. get length() {
  4581. return this._data.length;
  4582. }
  4583. // copy to target buffer
  4584. copy(target, targetOffset, offset, length) {
  4585. this._data.copy(target, targetOffset, offset, length);
  4586. }
  4587. toBuffer() {
  4588. return this._data;
  4589. }
  4590. }
  4591. // =============================================================================
  4592. // ReadWriteBuf - a single buffer supporting simple read-write
  4593. class ReadWriteBuf {
  4594. constructor(size) {
  4595. this.size = size;
  4596. // the buffer
  4597. this.buffer = Buffer.alloc(size);
  4598. // read index
  4599. this.iRead = 0;
  4600. // write index
  4601. this.iWrite = 0;
  4602. }
  4603. toBuffer() {
  4604. if (this.iRead === 0 && this.iWrite === this.size) {
  4605. return this.buffer;
  4606. }
  4607. const buf = Buffer.alloc(this.iWrite - this.iRead);
  4608. this.buffer.copy(buf, 0, this.iRead, this.iWrite);
  4609. return buf;
  4610. }
  4611. get length() {
  4612. return this.iWrite - this.iRead;
  4613. }
  4614. get eod() {
  4615. return this.iRead === this.iWrite;
  4616. }
  4617. get full() {
  4618. return this.iWrite === this.size;
  4619. }
  4620. read(size) {
  4621. let buf;
  4622. // read size bytes from buffer and return buffer
  4623. if (size === 0) {
  4624. // special case - return null if no data requested
  4625. return null;
  4626. }
  4627. if (size === undefined || size >= this.length) {
  4628. // if no size specified or size is at least what we have then return all of the bytes
  4629. buf = this.toBuffer();
  4630. this.iRead = this.iWrite;
  4631. return buf;
  4632. }
  4633. // otherwise return a chunk
  4634. buf = Buffer.alloc(size);
  4635. this.buffer.copy(buf, 0, this.iRead, size);
  4636. this.iRead += size;
  4637. return buf;
  4638. }
  4639. write(chunk, offset, length) {
  4640. // write as many bytes from data from optional source offset
  4641. // and return number of bytes written
  4642. const size = Math.min(length, this.size - this.iWrite);
  4643. chunk.copy(this.buffer, this.iWrite, offset, offset + size);
  4644. this.iWrite += size;
  4645. return size;
  4646. }
  4647. }
  4648. // =============================================================================
  4649. // StreamBuf - a multi-purpose read-write stream
  4650. // As MemBuf - write as much data as you like. Then call toBuffer() to consolidate
  4651. // As StreamHub - pipe to multiple writables
  4652. // As readable stream - feed data into the writable part and have some other code read from it.
  4653. // Note: Not sure why but StreamBuf does not like JS "class" sugar. It fails the
  4654. // integration tests
  4655. const StreamBuf = function (options) {
  4656. options = options || {};
  4657. this.bufSize = options.bufSize || 1024 * 1024;
  4658. this.buffers = [];
  4659. // batch mode fills a buffer completely before passing the data on
  4660. // to pipes or 'readable' event listeners
  4661. this.batch = options.batch || false;
  4662. this.corked = false;
  4663. // where in the current writable buffer we're up to
  4664. this.inPos = 0;
  4665. // where in the current readable buffer we've read up to
  4666. this.outPos = 0;
  4667. // consuming pipe streams go here
  4668. this.pipes = [];
  4669. // controls emit('data')
  4670. this.paused = false;
  4671. this.encoding = null;
  4672. };
  4673. utils.inherits(StreamBuf, Stream.Duplex, {
  4674. toBuffer() {
  4675. switch (this.buffers.length) {
  4676. case 0:
  4677. return null;
  4678. case 1:
  4679. return this.buffers[0].toBuffer();
  4680. default:
  4681. return Buffer.concat(this.buffers.map(rwBuf => rwBuf.toBuffer()));
  4682. }
  4683. },
  4684. // writable
  4685. // event drain - if write returns false (which it won't), indicates when safe to write again.
  4686. // finish - end() has been called
  4687. // pipe(src) - pipe() has been called on readable
  4688. // unpipe(src) - unpipe() has been called on readable
  4689. // error - duh
  4690. _getWritableBuffer() {
  4691. if (this.buffers.length) {
  4692. const last = this.buffers[this.buffers.length - 1];
  4693. if (!last.full) {
  4694. return last;
  4695. }
  4696. }
  4697. const buf = new ReadWriteBuf(this.bufSize);
  4698. this.buffers.push(buf);
  4699. return buf;
  4700. },
  4701. async _pipe(chunk) {
  4702. const write = function (pipe) {
  4703. return new Promise(resolve => {
  4704. pipe.write(chunk.toBuffer(), () => {
  4705. resolve();
  4706. });
  4707. });
  4708. };
  4709. await Promise.all(this.pipes.map(write));
  4710. },
  4711. _writeToBuffers(chunk) {
  4712. let inPos = 0;
  4713. const inLen = chunk.length;
  4714. while (inPos < inLen) {
  4715. // find writable buffer
  4716. const buffer = this._getWritableBuffer();
  4717. // write some data
  4718. inPos += buffer.write(chunk, inPos, inLen - inPos);
  4719. }
  4720. },
  4721. async write(data, encoding, callback) {
  4722. if (encoding instanceof Function) {
  4723. callback = encoding;
  4724. encoding = 'utf8';
  4725. }
  4726. callback = callback || utils.nop;
  4727. // encapsulate data into a chunk
  4728. let chunk;
  4729. if (data instanceof StringBuf) {
  4730. chunk = new StringBufChunk(data);
  4731. } else if (data instanceof Buffer) {
  4732. chunk = new BufferChunk(data);
  4733. } else if (typeof data === 'string' || data instanceof String || data instanceof ArrayBuffer) {
  4734. chunk = new StringChunk(data, encoding);
  4735. } else {
  4736. throw new Error('Chunk must be one of type String, Buffer or StringBuf.');
  4737. }
  4738. // now, do something with the chunk
  4739. if (this.pipes.length) {
  4740. if (this.batch) {
  4741. this._writeToBuffers(chunk);
  4742. while (!this.corked && this.buffers.length > 1) {
  4743. this._pipe(this.buffers.shift());
  4744. }
  4745. } else if (!this.corked) {
  4746. await this._pipe(chunk);
  4747. callback();
  4748. } else {
  4749. this._writeToBuffers(chunk);
  4750. process.nextTick(callback);
  4751. }
  4752. } else {
  4753. if (!this.paused) {
  4754. this.emit('data', chunk.toBuffer());
  4755. }
  4756. this._writeToBuffers(chunk);
  4757. this.emit('readable');
  4758. }
  4759. return true;
  4760. },
  4761. cork() {
  4762. this.corked = true;
  4763. },
  4764. _flush( /* destination */
  4765. ) {
  4766. // if we have comsumers...
  4767. if (this.pipes.length) {
  4768. // and there's stuff not written
  4769. while (this.buffers.length) {
  4770. this._pipe(this.buffers.shift());
  4771. }
  4772. }
  4773. },
  4774. uncork() {
  4775. this.corked = false;
  4776. this._flush();
  4777. },
  4778. end(chunk, encoding, callback) {
  4779. const writeComplete = error => {
  4780. if (error) {
  4781. callback(error);
  4782. } else {
  4783. this._flush();
  4784. this.pipes.forEach(pipe => {
  4785. pipe.end();
  4786. });
  4787. this.emit('finish');
  4788. }
  4789. };
  4790. if (chunk) {
  4791. this.write(chunk, encoding, writeComplete);
  4792. } else {
  4793. writeComplete();
  4794. }
  4795. },
  4796. // readable
  4797. // event readable - some data is now available
  4798. // event data - switch to flowing mode - feeds chunks to handler
  4799. // event end - no more data
  4800. // event close - optional, indicates upstream close
  4801. // event error - duh
  4802. read(size) {
  4803. let buffers;
  4804. // read min(buffer, size || infinity)
  4805. if (size) {
  4806. buffers = [];
  4807. while (size && this.buffers.length && !this.buffers[0].eod) {
  4808. const first = this.buffers[0];
  4809. const buffer = first.read(size);
  4810. size -= buffer.length;
  4811. buffers.push(buffer);
  4812. if (first.eod && first.full) {
  4813. this.buffers.shift();
  4814. }
  4815. }
  4816. return Buffer.concat(buffers);
  4817. }
  4818. buffers = this.buffers.map(buf => buf.toBuffer()).filter(Boolean);
  4819. this.buffers = [];
  4820. return Buffer.concat(buffers);
  4821. },
  4822. setEncoding(encoding) {
  4823. // causes stream.read or stream.on('data) to return strings of encoding instead of Buffer objects
  4824. this.encoding = encoding;
  4825. },
  4826. pause() {
  4827. this.paused = true;
  4828. },
  4829. resume() {
  4830. this.paused = false;
  4831. },
  4832. isPaused() {
  4833. return !!this.paused;
  4834. },
  4835. pipe(destination) {
  4836. // add destination to pipe list & write current buffer
  4837. this.pipes.push(destination);
  4838. if (!this.paused && this.buffers.length) {
  4839. this.end();
  4840. }
  4841. },
  4842. unpipe(destination) {
  4843. // remove destination from pipe list
  4844. this.pipes = this.pipes.filter(pipe => pipe !== destination);
  4845. },
  4846. unshift( /* chunk */
  4847. ) {
  4848. // some numpty has read some data that's not for them and they want to put it back!
  4849. // Might implement this some day
  4850. throw new Error('Not Implemented');
  4851. },
  4852. wrap( /* stream */
  4853. ) {
  4854. // not implemented
  4855. throw new Error('Not Implemented');
  4856. }
  4857. });
  4858. module.exports = StreamBuf;
  4859. }).call(this)}).call(this,require('_process'),require("buffer").Buffer)
  4860. },{"./string-buf":25,"./utils":27,"_process":467,"buffer":220,"readable-stream":491}],25:[function(require,module,exports){
  4861. (function (Buffer){(function (){
  4862. "use strict";
  4863. // StringBuf - a way to keep string memory operations to a minimum
  4864. // while building the strings for the xml files
  4865. class StringBuf {
  4866. constructor(options) {
  4867. this._buf = Buffer.alloc(options && options.size || 16384);
  4868. this._encoding = options && options.encoding || 'utf8';
  4869. // where in the buffer we are at
  4870. this._inPos = 0;
  4871. // for use by toBuffer()
  4872. this._buffer = undefined;
  4873. }
  4874. get length() {
  4875. return this._inPos;
  4876. }
  4877. get capacity() {
  4878. return this._buf.length;
  4879. }
  4880. get buffer() {
  4881. return this._buf;
  4882. }
  4883. toBuffer() {
  4884. // return the current data as a single enclosing buffer
  4885. if (!this._buffer) {
  4886. this._buffer = Buffer.alloc(this.length);
  4887. this._buf.copy(this._buffer, 0, 0, this.length);
  4888. }
  4889. return this._buffer;
  4890. }
  4891. reset(position) {
  4892. position = position || 0;
  4893. this._buffer = undefined;
  4894. this._inPos = position;
  4895. }
  4896. _grow(min) {
  4897. let size = this._buf.length * 2;
  4898. while (size < min) {
  4899. size *= 2;
  4900. }
  4901. const buf = Buffer.alloc(size);
  4902. this._buf.copy(buf, 0);
  4903. this._buf = buf;
  4904. }
  4905. addText(text) {
  4906. this._buffer = undefined;
  4907. let inPos = this._inPos + this._buf.write(text, this._inPos, this._encoding);
  4908. // if we've hit (or nearing capacity), grow the buf
  4909. while (inPos >= this._buf.length - 4) {
  4910. this._grow(this._inPos + text.length);
  4911. // keep trying to write until we've completely written the text
  4912. inPos = this._inPos + this._buf.write(text, this._inPos, this._encoding);
  4913. }
  4914. this._inPos = inPos;
  4915. }
  4916. addStringBuf(inBuf) {
  4917. if (inBuf.length) {
  4918. this._buffer = undefined;
  4919. if (this.length + inBuf.length > this.capacity) {
  4920. this._grow(this.length + inBuf.length);
  4921. }
  4922. // eslint-disable-next-line no-underscore-dangle
  4923. inBuf._buf.copy(this._buf, this._inPos, 0, inBuf.length);
  4924. this._inPos += inBuf.length;
  4925. }
  4926. }
  4927. }
  4928. module.exports = StringBuf;
  4929. }).call(this)}).call(this,require("buffer").Buffer)
  4930. },{"buffer":220}],26:[function(require,module,exports){
  4931. "use strict";
  4932. const {
  4933. toString
  4934. } = Object.prototype;
  4935. const escapeHtmlRegex = /["&<>]/;
  4936. const _ = {
  4937. each: function each(obj, cb) {
  4938. if (obj) {
  4939. if (Array.isArray(obj)) {
  4940. obj.forEach(cb);
  4941. } else {
  4942. Object.keys(obj).forEach(key => {
  4943. cb(obj[key], key);
  4944. });
  4945. }
  4946. }
  4947. },
  4948. some: function some(obj, cb) {
  4949. if (obj) {
  4950. if (Array.isArray(obj)) {
  4951. return obj.some(cb);
  4952. }
  4953. return Object.keys(obj).some(key => cb(obj[key], key));
  4954. }
  4955. return false;
  4956. },
  4957. every: function every(obj, cb) {
  4958. if (obj) {
  4959. if (Array.isArray(obj)) {
  4960. return obj.every(cb);
  4961. }
  4962. return Object.keys(obj).every(key => cb(obj[key], key));
  4963. }
  4964. return true;
  4965. },
  4966. map: function map(obj, cb) {
  4967. if (obj) {
  4968. if (Array.isArray(obj)) {
  4969. return obj.map(cb);
  4970. }
  4971. return Object.keys(obj).map(key => cb(obj[key], key));
  4972. }
  4973. return [];
  4974. },
  4975. keyBy(a, p) {
  4976. return a.reduce((o, v) => {
  4977. o[v[p]] = v;
  4978. return o;
  4979. }, {});
  4980. },
  4981. isEqual: function isEqual(a, b) {
  4982. const aType = typeof a;
  4983. const bType = typeof b;
  4984. const aArray = Array.isArray(a);
  4985. const bArray = Array.isArray(b);
  4986. let keys;
  4987. if (aType !== bType) {
  4988. return false;
  4989. }
  4990. switch (typeof a) {
  4991. case 'object':
  4992. if (aArray || bArray) {
  4993. if (aArray && bArray) {
  4994. return a.length === b.length && a.every((aValue, index) => {
  4995. const bValue = b[index];
  4996. return _.isEqual(aValue, bValue);
  4997. });
  4998. }
  4999. return false;
  5000. }
  5001. if (a === null || b === null) {
  5002. return a === b;
  5003. }
  5004. // Compare object keys and values
  5005. keys = Object.keys(a);
  5006. if (Object.keys(b).length !== keys.length) {
  5007. return false;
  5008. }
  5009. for (const key of keys) {
  5010. if (!b.hasOwnProperty(key)) {
  5011. return false;
  5012. }
  5013. }
  5014. return _.every(a, (aValue, key) => {
  5015. const bValue = b[key];
  5016. return _.isEqual(aValue, bValue);
  5017. });
  5018. default:
  5019. return a === b;
  5020. }
  5021. },
  5022. escapeHtml(html) {
  5023. const regexResult = escapeHtmlRegex.exec(html);
  5024. if (!regexResult) return html;
  5025. let result = '';
  5026. let escape = '';
  5027. let lastIndex = 0;
  5028. let i = regexResult.index;
  5029. for (; i < html.length; i++) {
  5030. switch (html.charAt(i)) {
  5031. case '"':
  5032. escape = '&quot;';
  5033. break;
  5034. case '&':
  5035. escape = '&amp;';
  5036. break;
  5037. case '\'':
  5038. escape = '&apos;';
  5039. break;
  5040. case '<':
  5041. escape = '&lt;';
  5042. break;
  5043. case '>':
  5044. escape = '&gt;';
  5045. break;
  5046. default:
  5047. continue;
  5048. }
  5049. if (lastIndex !== i) result += html.substring(lastIndex, i);
  5050. lastIndex = i + 1;
  5051. result += escape;
  5052. }
  5053. if (lastIndex !== i) return result + html.substring(lastIndex, i);
  5054. return result;
  5055. },
  5056. strcmp(a, b) {
  5057. if (a < b) return -1;
  5058. if (a > b) return 1;
  5059. return 0;
  5060. },
  5061. isUndefined(val) {
  5062. return toString.call(val) === '[object Undefined]';
  5063. },
  5064. isObject(val) {
  5065. return toString.call(val) === '[object Object]';
  5066. },
  5067. deepMerge() {
  5068. const target = arguments[0] || {};
  5069. const {
  5070. length
  5071. } = arguments;
  5072. // eslint-disable-next-line one-var
  5073. let src, clone, copyIsArray;
  5074. function assignValue(val, key) {
  5075. src = target[key];
  5076. copyIsArray = Array.isArray(val);
  5077. if (_.isObject(val) || copyIsArray) {
  5078. if (copyIsArray) {
  5079. copyIsArray = false;
  5080. clone = src && Array.isArray(src) ? src : [];
  5081. } else {
  5082. clone = src && _.isObject(src) ? src : {};
  5083. }
  5084. target[key] = _.deepMerge(clone, val);
  5085. } else if (!_.isUndefined(val)) {
  5086. target[key] = val;
  5087. }
  5088. }
  5089. for (let i = 0; i < length; i++) {
  5090. _.each(arguments[i], assignValue);
  5091. }
  5092. return target;
  5093. }
  5094. };
  5095. module.exports = _;
  5096. },{}],27:[function(require,module,exports){
  5097. (function (global,setImmediate){(function (){
  5098. "use strict";
  5099. const fs = require('fs');
  5100. // useful stuff
  5101. const inherits = function (cls, superCtor, statics, prototype) {
  5102. // eslint-disable-next-line no-underscore-dangle
  5103. cls.super_ = superCtor;
  5104. if (!prototype) {
  5105. prototype = statics;
  5106. statics = null;
  5107. }
  5108. if (statics) {
  5109. Object.keys(statics).forEach(i => {
  5110. Object.defineProperty(cls, i, Object.getOwnPropertyDescriptor(statics, i));
  5111. });
  5112. }
  5113. const properties = {
  5114. constructor: {
  5115. value: cls,
  5116. enumerable: false,
  5117. writable: false,
  5118. configurable: true
  5119. }
  5120. };
  5121. if (prototype) {
  5122. Object.keys(prototype).forEach(i => {
  5123. properties[i] = Object.getOwnPropertyDescriptor(prototype, i);
  5124. });
  5125. }
  5126. cls.prototype = Object.create(superCtor.prototype, properties);
  5127. };
  5128. // eslint-disable-next-line no-control-regex
  5129. const xmlDecodeRegex = /[<>&'"\x7F\x00-\x08\x0B-\x0C\x0E-\x1F]/;
  5130. const utils = {
  5131. nop() {},
  5132. promiseImmediate(value) {
  5133. return new Promise(resolve => {
  5134. if (global.setImmediate) {
  5135. setImmediate(() => {
  5136. resolve(value);
  5137. });
  5138. } else {
  5139. // poorman's setImmediate - must wait at least 1ms
  5140. setTimeout(() => {
  5141. resolve(value);
  5142. }, 1);
  5143. }
  5144. });
  5145. },
  5146. inherits,
  5147. dateToExcel(d, date1904) {
  5148. return 25569 + d.getTime() / (24 * 3600 * 1000) - (date1904 ? 1462 : 0);
  5149. },
  5150. excelToDate(v, date1904) {
  5151. const millisecondSinceEpoch = Math.round((v - 25569 + (date1904 ? 1462 : 0)) * 24 * 3600 * 1000);
  5152. return new Date(millisecondSinceEpoch);
  5153. },
  5154. parsePath(filepath) {
  5155. const last = filepath.lastIndexOf('/');
  5156. return {
  5157. path: filepath.substring(0, last),
  5158. name: filepath.substring(last + 1)
  5159. };
  5160. },
  5161. getRelsPath(filepath) {
  5162. const path = utils.parsePath(filepath);
  5163. return `${path.path}/_rels/${path.name}.rels`;
  5164. },
  5165. xmlEncode(text) {
  5166. const regexResult = xmlDecodeRegex.exec(text);
  5167. if (!regexResult) return text;
  5168. let result = '';
  5169. let escape = '';
  5170. let lastIndex = 0;
  5171. let i = regexResult.index;
  5172. for (; i < text.length; i++) {
  5173. const charCode = text.charCodeAt(i);
  5174. switch (charCode) {
  5175. case 34:
  5176. // "
  5177. escape = '&quot;';
  5178. break;
  5179. case 38:
  5180. // &
  5181. escape = '&amp;';
  5182. break;
  5183. case 39:
  5184. // '
  5185. escape = '&apos;';
  5186. break;
  5187. case 60:
  5188. // <
  5189. escape = '&lt;';
  5190. break;
  5191. case 62:
  5192. // >
  5193. escape = '&gt;';
  5194. break;
  5195. case 127:
  5196. escape = '';
  5197. break;
  5198. default:
  5199. {
  5200. if (charCode <= 31 && (charCode <= 8 || charCode >= 11 && charCode !== 13)) {
  5201. escape = '';
  5202. break;
  5203. }
  5204. continue;
  5205. }
  5206. }
  5207. if (lastIndex !== i) result += text.substring(lastIndex, i);
  5208. lastIndex = i + 1;
  5209. if (escape) result += escape;
  5210. }
  5211. if (lastIndex !== i) return result + text.substring(lastIndex, i);
  5212. return result;
  5213. },
  5214. xmlDecode(text) {
  5215. return text.replace(/&([a-z]*);/g, c => {
  5216. switch (c) {
  5217. case '&lt;':
  5218. return '<';
  5219. case '&gt;':
  5220. return '>';
  5221. case '&amp;':
  5222. return '&';
  5223. case '&apos;':
  5224. return '\'';
  5225. case '&quot;':
  5226. return '"';
  5227. default:
  5228. return c;
  5229. }
  5230. });
  5231. },
  5232. validInt(value) {
  5233. const i = parseInt(value, 10);
  5234. return !Number.isNaN(i) ? i : 0;
  5235. },
  5236. isDateFmt(fmt) {
  5237. if (!fmt) {
  5238. return false;
  5239. }
  5240. // must remove all chars inside quotes and []
  5241. fmt = fmt.replace(/\[[^\]]*]/g, '');
  5242. fmt = fmt.replace(/"[^"]*"/g, '');
  5243. // then check for date formatting chars
  5244. const result = fmt.match(/[ymdhMsb]+/) !== null;
  5245. return result;
  5246. },
  5247. fs: {
  5248. exists(path) {
  5249. return new Promise(resolve => {
  5250. fs.access(path, fs.constants.F_OK, err => {
  5251. resolve(!err);
  5252. });
  5253. });
  5254. }
  5255. },
  5256. toIsoDateString(dt) {
  5257. return dt.toIsoString().subsstr(0, 10);
  5258. },
  5259. parseBoolean(value) {
  5260. return value === true || value === 'true' || value === 1 || value === '1';
  5261. }
  5262. };
  5263. module.exports = utils;
  5264. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  5265. },{"fs":216,"timers":523}],28:[function(require,module,exports){
  5266. "use strict";
  5267. const _ = require('./under-dash');
  5268. const utils = require('./utils');
  5269. // constants
  5270. const OPEN_ANGLE = '<';
  5271. const CLOSE_ANGLE = '>';
  5272. const OPEN_ANGLE_SLASH = '</';
  5273. const CLOSE_SLASH_ANGLE = '/>';
  5274. function pushAttribute(xml, name, value) {
  5275. xml.push(` ${name}="${utils.xmlEncode(value.toString())}"`);
  5276. }
  5277. function pushAttributes(xml, attributes) {
  5278. if (attributes) {
  5279. const tmp = [];
  5280. _.each(attributes, (value, name) => {
  5281. if (value !== undefined) {
  5282. pushAttribute(tmp, name, value);
  5283. }
  5284. });
  5285. xml.push(tmp.join(""));
  5286. }
  5287. }
  5288. class XmlStream {
  5289. constructor() {
  5290. this._xml = [];
  5291. this._stack = [];
  5292. this._rollbacks = [];
  5293. }
  5294. get tos() {
  5295. return this._stack.length ? this._stack[this._stack.length - 1] : undefined;
  5296. }
  5297. get cursor() {
  5298. // handy way to track whether anything has been added
  5299. return this._xml.length;
  5300. }
  5301. openXml(docAttributes) {
  5302. const xml = this._xml;
  5303. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  5304. xml.push('<?xml');
  5305. pushAttributes(xml, docAttributes);
  5306. xml.push('?>\n');
  5307. }
  5308. openNode(name, attributes) {
  5309. const parent = this.tos;
  5310. const xml = this._xml;
  5311. if (parent && this.open) {
  5312. xml.push(CLOSE_ANGLE);
  5313. }
  5314. this._stack.push(name);
  5315. // start streaming node
  5316. xml.push(OPEN_ANGLE);
  5317. xml.push(name);
  5318. pushAttributes(xml, attributes);
  5319. this.leaf = true;
  5320. this.open = true;
  5321. }
  5322. addAttribute(name, value) {
  5323. if (!this.open) {
  5324. throw new Error('Cannot write attributes to node if it is not open');
  5325. }
  5326. if (value !== undefined) {
  5327. pushAttribute(this._xml, name, value);
  5328. }
  5329. }
  5330. addAttributes(attrs) {
  5331. if (!this.open) {
  5332. throw new Error('Cannot write attributes to node if it is not open');
  5333. }
  5334. pushAttributes(this._xml, attrs);
  5335. }
  5336. writeText(text) {
  5337. const xml = this._xml;
  5338. if (this.open) {
  5339. xml.push(CLOSE_ANGLE);
  5340. this.open = false;
  5341. }
  5342. this.leaf = false;
  5343. xml.push(utils.xmlEncode(text.toString()));
  5344. }
  5345. writeXml(xml) {
  5346. if (this.open) {
  5347. this._xml.push(CLOSE_ANGLE);
  5348. this.open = false;
  5349. }
  5350. this.leaf = false;
  5351. this._xml.push(xml);
  5352. }
  5353. closeNode() {
  5354. const node = this._stack.pop();
  5355. const xml = this._xml;
  5356. if (this.leaf) {
  5357. xml.push(CLOSE_SLASH_ANGLE);
  5358. } else {
  5359. xml.push(OPEN_ANGLE_SLASH);
  5360. xml.push(node);
  5361. xml.push(CLOSE_ANGLE);
  5362. }
  5363. this.open = false;
  5364. this.leaf = false;
  5365. }
  5366. leafNode(name, attributes, text) {
  5367. this.openNode(name, attributes);
  5368. if (text !== undefined) {
  5369. // zeros need to be written
  5370. this.writeText(text);
  5371. }
  5372. this.closeNode();
  5373. }
  5374. closeAll() {
  5375. while (this._stack.length) {
  5376. this.closeNode();
  5377. }
  5378. }
  5379. addRollback() {
  5380. this._rollbacks.push({
  5381. xml: this._xml.length,
  5382. stack: this._stack.length,
  5383. leaf: this.leaf,
  5384. open: this.open
  5385. });
  5386. return this.cursor;
  5387. }
  5388. commit() {
  5389. this._rollbacks.pop();
  5390. }
  5391. rollback() {
  5392. const r = this._rollbacks.pop();
  5393. if (this._xml.length > r.xml) {
  5394. this._xml.splice(r.xml, this._xml.length - r.xml);
  5395. }
  5396. if (this._stack.length > r.stack) {
  5397. this._stack.splice(r.stack, this._stack.length - r.stack);
  5398. }
  5399. this.leaf = r.leaf;
  5400. this.open = r.open;
  5401. }
  5402. get xml() {
  5403. this.closeAll();
  5404. return this._xml.join('');
  5405. }
  5406. }
  5407. XmlStream.StdDocAttributes = {
  5408. version: '1.0',
  5409. encoding: 'UTF-8',
  5410. standalone: 'yes'
  5411. };
  5412. module.exports = XmlStream;
  5413. },{"./under-dash":26,"./utils":27}],29:[function(require,module,exports){
  5414. (function (process){(function (){
  5415. "use strict";
  5416. const events = require('events');
  5417. const JSZip = require('jszip');
  5418. const StreamBuf = require('./stream-buf');
  5419. const {
  5420. stringToBuffer
  5421. } = require('./browser-buffer-encode');
  5422. // =============================================================================
  5423. // The ZipWriter class
  5424. // Packs streamed data into an output zip stream
  5425. class ZipWriter extends events.EventEmitter {
  5426. constructor(options) {
  5427. super();
  5428. this.options = Object.assign({
  5429. type: 'nodebuffer',
  5430. compression: 'DEFLATE'
  5431. }, options);
  5432. this.zip = new JSZip();
  5433. this.stream = new StreamBuf();
  5434. }
  5435. append(data, options) {
  5436. if (options.hasOwnProperty('base64') && options.base64) {
  5437. this.zip.file(options.name, data, {
  5438. base64: true
  5439. });
  5440. } else {
  5441. // https://www.npmjs.com/package/process
  5442. if (process.browser && typeof data === 'string') {
  5443. // use TextEncoder in browser
  5444. data = stringToBuffer(data);
  5445. }
  5446. this.zip.file(options.name, data);
  5447. }
  5448. }
  5449. async finalize() {
  5450. const content = await this.zip.generateAsync(this.options);
  5451. this.stream.end(content);
  5452. this.emit('finish');
  5453. }
  5454. // ==========================================================================
  5455. // Stream.Readable interface
  5456. read(size) {
  5457. return this.stream.read(size);
  5458. }
  5459. setEncoding(encoding) {
  5460. return this.stream.setEncoding(encoding);
  5461. }
  5462. pause() {
  5463. return this.stream.pause();
  5464. }
  5465. resume() {
  5466. return this.stream.resume();
  5467. }
  5468. isPaused() {
  5469. return this.stream.isPaused();
  5470. }
  5471. pipe(destination, options) {
  5472. return this.stream.pipe(destination, options);
  5473. }
  5474. unpipe(destination) {
  5475. return this.stream.unpipe(destination);
  5476. }
  5477. unshift(chunk) {
  5478. return this.stream.unshift(chunk);
  5479. }
  5480. wrap(stream) {
  5481. return this.stream.wrap(stream);
  5482. }
  5483. }
  5484. // =============================================================================
  5485. module.exports = {
  5486. ZipWriter
  5487. };
  5488. }).call(this)}).call(this,require('_process'))
  5489. },{"./browser-buffer-encode":17,"./stream-buf":24,"_process":467,"events":422,"jszip":441}],30:[function(require,module,exports){
  5490. "use strict";
  5491. module.exports = {
  5492. 0: {
  5493. f: 'General'
  5494. },
  5495. 1: {
  5496. f: '0'
  5497. },
  5498. 2: {
  5499. f: '0.00'
  5500. },
  5501. 3: {
  5502. f: '#,##0'
  5503. },
  5504. 4: {
  5505. f: '#,##0.00'
  5506. },
  5507. 9: {
  5508. f: '0%'
  5509. },
  5510. 10: {
  5511. f: '0.00%'
  5512. },
  5513. 11: {
  5514. f: '0.00E+00'
  5515. },
  5516. 12: {
  5517. f: '# ?/?'
  5518. },
  5519. 13: {
  5520. f: '# ??/??'
  5521. },
  5522. 14: {
  5523. f: 'mm-dd-yy'
  5524. },
  5525. 15: {
  5526. f: 'd-mmm-yy'
  5527. },
  5528. 16: {
  5529. f: 'd-mmm'
  5530. },
  5531. 17: {
  5532. f: 'mmm-yy'
  5533. },
  5534. 18: {
  5535. f: 'h:mm AM/PM'
  5536. },
  5537. 19: {
  5538. f: 'h:mm:ss AM/PM'
  5539. },
  5540. 20: {
  5541. f: 'h:mm'
  5542. },
  5543. 21: {
  5544. f: 'h:mm:ss'
  5545. },
  5546. 22: {
  5547. f: 'm/d/yy "h":mm'
  5548. },
  5549. 27: {
  5550. 'zh-tw': '[$-404]e/m/d',
  5551. 'zh-cn': 'yyyy"年"m"月"',
  5552. 'ja-jp': '[$-411]ge.m.d',
  5553. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  5554. },
  5555. 28: {
  5556. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  5557. 'zh-cn': 'm"月"d"日"',
  5558. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  5559. 'ko-kr': 'mm-dd'
  5560. },
  5561. 29: {
  5562. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  5563. 'zh-cn': 'm"月"d"日"',
  5564. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  5565. 'ko-kr': 'mm-dd'
  5566. },
  5567. 30: {
  5568. 'zh-tw': 'm/d/yy ',
  5569. 'zh-cn': 'm-d-yy',
  5570. 'ja-jp': 'm/d/yy',
  5571. 'ko-kr': 'mm-dd-yy'
  5572. },
  5573. 31: {
  5574. 'zh-tw': 'yyyy"年"m"月"d"日"',
  5575. 'zh-cn': 'yyyy"年"m"月"d"日"',
  5576. 'ja-jp': 'yyyy"年"m"月"d"日"',
  5577. 'ko-kr': 'yyyy"년" mm"월" dd"일"'
  5578. },
  5579. 32: {
  5580. 'zh-tw': 'hh"時"mm"分"',
  5581. 'zh-cn': 'h"时"mm"分"',
  5582. 'ja-jp': 'h"時"mm"分"',
  5583. 'ko-kr': 'h"시" mm"분"'
  5584. },
  5585. 33: {
  5586. 'zh-tw': 'hh"時"mm"分"ss"秒"',
  5587. 'zh-cn': 'h"时"mm"分"ss"秒"',
  5588. 'ja-jp': 'h"時"mm"分"ss"秒"',
  5589. 'ko-kr': 'h"시" mm"분" ss"초"'
  5590. },
  5591. 34: {
  5592. 'zh-tw': '上午/下午 hh"時"mm"分"',
  5593. 'zh-cn': '上午/下午 h"时"mm"分"',
  5594. 'ja-jp': 'yyyy"年"m"月"',
  5595. 'ko-kr': 'yyyy-mm-dd'
  5596. },
  5597. 35: {
  5598. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  5599. 'zh-cn': '上午/下午 h"时"mm"分"ss"秒"',
  5600. 'ja-jp': 'm"月"d"日"',
  5601. 'ko-kr': 'yyyy-mm-dd'
  5602. },
  5603. 36: {
  5604. 'zh-tw': '[$-404]e/m/d',
  5605. 'zh-cn': 'yyyy"年"m"月"',
  5606. 'ja-jp': '[$-411]ge.m.d',
  5607. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  5608. },
  5609. 37: {
  5610. f: '#,##0 ;(#,##0)'
  5611. },
  5612. 38: {
  5613. f: '#,##0 ;[Red](#,##0)'
  5614. },
  5615. 39: {
  5616. f: '#,##0.00 ;(#,##0.00)'
  5617. },
  5618. 40: {
  5619. f: '#,##0.00 ;[Red](#,##0.00)'
  5620. },
  5621. 45: {
  5622. f: 'mm:ss'
  5623. },
  5624. 46: {
  5625. f: '[h]:mm:ss'
  5626. },
  5627. 47: {
  5628. f: 'mmss.0'
  5629. },
  5630. 48: {
  5631. f: '##0.0E+0'
  5632. },
  5633. 49: {
  5634. f: '@'
  5635. },
  5636. 50: {
  5637. 'zh-tw': '[$-404]e/m/d',
  5638. 'zh-cn': 'yyyy"年"m"月"',
  5639. 'ja-jp': '[$-411]ge.m.d',
  5640. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  5641. },
  5642. 51: {
  5643. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  5644. 'zh-cn': 'm"月"d"日"',
  5645. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  5646. 'ko-kr': 'mm-dd'
  5647. },
  5648. 52: {
  5649. 'zh-tw': '上午/下午 hh"時"mm"分"',
  5650. 'zh-cn': 'yyyy"年"m"月"',
  5651. 'ja-jp': 'yyyy"年"m"月"',
  5652. 'ko-kr': 'yyyy-mm-dd'
  5653. },
  5654. 53: {
  5655. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  5656. 'zh-cn': 'm"月"d"日"',
  5657. 'ja-jp': 'm"月"d"日"',
  5658. 'ko-kr': 'yyyy-mm-dd'
  5659. },
  5660. 54: {
  5661. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  5662. 'zh-cn': 'm"月"d"日"',
  5663. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  5664. 'ko-kr': 'mm-dd'
  5665. },
  5666. 55: {
  5667. 'zh-tw': '上午/下午 hh"時"mm"分"',
  5668. 'zh-cn': '上午/下午 h"时"mm"分"',
  5669. 'ja-jp': 'yyyy"年"m"月"',
  5670. 'ko-kr': 'yyyy-mm-dd'
  5671. },
  5672. 56: {
  5673. 'zh-tw': '上午/下午 hh"時"mm"分"ss"秒"',
  5674. 'zh-cn': '上午/下午 h"时"mm"分"ss"秒"',
  5675. 'ja-jp': 'm"月"d"日"',
  5676. 'ko-kr': 'yyyy-mm-dd'
  5677. },
  5678. 57: {
  5679. 'zh-tw': '[$-404]e/m/d',
  5680. 'zh-cn': 'yyyy"年"m"月"',
  5681. 'ja-jp': '[$-411]ge.m.d',
  5682. 'ko-kr': 'yyyy"年" mm"月" dd"日"'
  5683. },
  5684. 58: {
  5685. 'zh-tw': '[$-404]e"年"m"月"d"日"',
  5686. 'zh-cn': 'm"月"d"日"',
  5687. 'ja-jp': '[$-411]ggge"年"m"月"d"日"',
  5688. 'ko-kr': 'mm-dd'
  5689. },
  5690. 59: {
  5691. 'th-th': 't0'
  5692. },
  5693. 60: {
  5694. 'th-th': 't0.00'
  5695. },
  5696. 61: {
  5697. 'th-th': 't#,##0'
  5698. },
  5699. 62: {
  5700. 'th-th': 't#,##0.00'
  5701. },
  5702. 67: {
  5703. 'th-th': 't0%'
  5704. },
  5705. 68: {
  5706. 'th-th': 't0.00%'
  5707. },
  5708. 69: {
  5709. 'th-th': 't# ?/?'
  5710. },
  5711. 70: {
  5712. 'th-th': 't# ??/??'
  5713. },
  5714. 81: {
  5715. 'th-th': 'd/m/bb'
  5716. }
  5717. };
  5718. },{}],31:[function(require,module,exports){
  5719. 'use strict';
  5720. module.exports = {
  5721. OfficeDocument: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
  5722. Worksheet: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
  5723. CalcChain: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain',
  5724. SharedStrings: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
  5725. Styles: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
  5726. Theme: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
  5727. Hyperlink: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
  5728. Image: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  5729. CoreProperties: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
  5730. ExtenderProperties: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
  5731. Comments: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
  5732. VmlDrawing: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
  5733. Table: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table'
  5734. };
  5735. },{}],32:[function(require,module,exports){
  5736. "use strict";
  5737. const parseSax = require('../../utils/parse-sax');
  5738. const XmlStream = require('../../utils/xml-stream');
  5739. /* 'virtual' methods used as a form of documentation */
  5740. /* eslint-disable class-methods-use-this */
  5741. // Base class for Xforms
  5742. class BaseXform {
  5743. // constructor(/* model, name */) {}
  5744. // ============================================================
  5745. // Virtual Interface
  5746. prepare( /* model, options */
  5747. ) {
  5748. // optional preparation (mutation) of model so it is ready for write
  5749. }
  5750. render( /* xmlStream, model */
  5751. ) {
  5752. // convert model to xml
  5753. }
  5754. parseOpen(node) {
  5755. // XML node opened
  5756. }
  5757. parseText(text) {
  5758. // chunk of text encountered for current node
  5759. }
  5760. parseClose(name) {
  5761. // XML node closed
  5762. }
  5763. reconcile(model, options) {
  5764. // optional post-parse step (opposite to prepare)
  5765. }
  5766. // ============================================================
  5767. reset() {
  5768. // to make sure parses don't bleed to next iteration
  5769. this.model = null;
  5770. // if we have a map - reset them too
  5771. if (this.map) {
  5772. Object.values(this.map).forEach(xform => {
  5773. if (xform instanceof BaseXform) {
  5774. xform.reset();
  5775. } else if (xform.xform) {
  5776. xform.xform.reset();
  5777. }
  5778. });
  5779. }
  5780. }
  5781. mergeModel(obj) {
  5782. // set obj's props to this.model
  5783. this.model = Object.assign(this.model || {}, obj);
  5784. }
  5785. async parse(saxParser) {
  5786. for await (const events of saxParser) {
  5787. for (const {
  5788. eventType,
  5789. value
  5790. } of events) {
  5791. if (eventType === 'opentag') {
  5792. this.parseOpen(value);
  5793. } else if (eventType === 'text') {
  5794. this.parseText(value);
  5795. } else if (eventType === 'closetag') {
  5796. if (!this.parseClose(value.name)) {
  5797. return this.model;
  5798. }
  5799. }
  5800. }
  5801. }
  5802. return this.model;
  5803. }
  5804. async parseStream(stream) {
  5805. return this.parse(parseSax(stream));
  5806. }
  5807. get xml() {
  5808. // convenience function to get the xml of this.model
  5809. // useful for manager types that are built during the prepare phase
  5810. return this.toXml(this.model);
  5811. }
  5812. toXml(model) {
  5813. const xmlStream = new XmlStream();
  5814. this.render(xmlStream, model);
  5815. return xmlStream.xml;
  5816. }
  5817. // ============================================================
  5818. // Useful Utilities
  5819. static toAttribute(value, dflt) {
  5820. let always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  5821. if (value === undefined) {
  5822. if (always) {
  5823. return dflt;
  5824. }
  5825. } else if (always || value !== dflt) {
  5826. return value.toString();
  5827. }
  5828. return undefined;
  5829. }
  5830. static toStringAttribute(value, dflt) {
  5831. let always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  5832. return BaseXform.toAttribute(value, dflt, always);
  5833. }
  5834. static toStringValue(attr, dflt) {
  5835. return attr === undefined ? dflt : attr;
  5836. }
  5837. static toBoolAttribute(value, dflt) {
  5838. let always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  5839. if (value === undefined) {
  5840. if (always) {
  5841. return dflt;
  5842. }
  5843. } else if (always || value !== dflt) {
  5844. return value ? '1' : '0';
  5845. }
  5846. return undefined;
  5847. }
  5848. static toBoolValue(attr, dflt) {
  5849. return attr === undefined ? dflt : attr === '1';
  5850. }
  5851. static toIntAttribute(value, dflt) {
  5852. let always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  5853. return BaseXform.toAttribute(value, dflt, always);
  5854. }
  5855. static toIntValue(attr, dflt) {
  5856. return attr === undefined ? dflt : parseInt(attr, 10);
  5857. }
  5858. static toFloatAttribute(value, dflt) {
  5859. let always = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  5860. return BaseXform.toAttribute(value, dflt, always);
  5861. }
  5862. static toFloatValue(attr, dflt) {
  5863. return attr === undefined ? dflt : parseFloat(attr);
  5864. }
  5865. }
  5866. module.exports = BaseXform;
  5867. },{"../../utils/parse-sax":22,"../../utils/xml-stream":28}],33:[function(require,module,exports){
  5868. "use strict";
  5869. const BaseXform = require('../base-xform');
  5870. const colCache = require('../../../utils/col-cache');
  5871. class DefinedNamesXform extends BaseXform {
  5872. render(xmlStream, model) {
  5873. // <definedNames>
  5874. // <definedName name="name">name.ranges.join(',')</definedName>
  5875. // <definedName name="_xlnm.Print_Area" localSheetId="0">name.ranges.join(',')</definedName>
  5876. // </definedNames>
  5877. xmlStream.openNode('definedName', {
  5878. name: model.name,
  5879. localSheetId: model.localSheetId
  5880. });
  5881. xmlStream.writeText(model.ranges.join(','));
  5882. xmlStream.closeNode();
  5883. }
  5884. parseOpen(node) {
  5885. switch (node.name) {
  5886. case 'definedName':
  5887. this._parsedName = node.attributes.name;
  5888. this._parsedLocalSheetId = node.attributes.localSheetId;
  5889. this._parsedText = [];
  5890. return true;
  5891. default:
  5892. return false;
  5893. }
  5894. }
  5895. parseText(text) {
  5896. this._parsedText.push(text);
  5897. }
  5898. parseClose() {
  5899. this.model = {
  5900. name: this._parsedName,
  5901. ranges: extractRanges(this._parsedText.join(''))
  5902. };
  5903. if (this._parsedLocalSheetId !== undefined) {
  5904. this.model.localSheetId = parseInt(this._parsedLocalSheetId, 10);
  5905. }
  5906. return false;
  5907. }
  5908. }
  5909. function isValidRange(range) {
  5910. try {
  5911. colCache.decodeEx(range);
  5912. return true;
  5913. } catch (err) {
  5914. return false;
  5915. }
  5916. }
  5917. function extractRanges(parsedText) {
  5918. const ranges = [];
  5919. let quotesOpened = false;
  5920. let last = '';
  5921. parsedText.split(',').forEach(item => {
  5922. if (!item) {
  5923. return;
  5924. }
  5925. const quotes = (item.match(/'/g) || []).length;
  5926. if (!quotes) {
  5927. if (quotesOpened) {
  5928. last += `${item},`;
  5929. } else if (isValidRange(item)) {
  5930. ranges.push(item);
  5931. }
  5932. return;
  5933. }
  5934. const quotesEven = quotes % 2 === 0;
  5935. if (!quotesOpened && quotesEven && isValidRange(item)) {
  5936. ranges.push(item);
  5937. } else if (quotesOpened && !quotesEven) {
  5938. quotesOpened = false;
  5939. if (isValidRange(last + item)) {
  5940. ranges.push(last + item);
  5941. }
  5942. last = '';
  5943. } else {
  5944. quotesOpened = true;
  5945. last += `${item},`;
  5946. }
  5947. });
  5948. return ranges;
  5949. }
  5950. module.exports = DefinedNamesXform;
  5951. },{"../../../utils/col-cache":19,"../base-xform":32}],34:[function(require,module,exports){
  5952. "use strict";
  5953. const utils = require('../../../utils/utils');
  5954. const BaseXform = require('../base-xform');
  5955. class WorksheetXform extends BaseXform {
  5956. render(xmlStream, model) {
  5957. xmlStream.leafNode('sheet', {
  5958. sheetId: model.id,
  5959. name: model.name,
  5960. state: model.state,
  5961. 'r:id': model.rId
  5962. });
  5963. }
  5964. parseOpen(node) {
  5965. if (node.name === 'sheet') {
  5966. this.model = {
  5967. name: utils.xmlDecode(node.attributes.name),
  5968. id: parseInt(node.attributes.sheetId, 10),
  5969. state: node.attributes.state,
  5970. rId: node.attributes['r:id']
  5971. };
  5972. return true;
  5973. }
  5974. return false;
  5975. }
  5976. parseText() {}
  5977. parseClose() {
  5978. return false;
  5979. }
  5980. }
  5981. module.exports = WorksheetXform;
  5982. },{"../../../utils/utils":27,"../base-xform":32}],35:[function(require,module,exports){
  5983. "use strict";
  5984. const BaseXform = require('../base-xform');
  5985. class WorkbookCalcPropertiesXform extends BaseXform {
  5986. render(xmlStream, model) {
  5987. xmlStream.leafNode('calcPr', {
  5988. calcId: 171027,
  5989. fullCalcOnLoad: model.fullCalcOnLoad ? 1 : undefined
  5990. });
  5991. }
  5992. parseOpen(node) {
  5993. if (node.name === 'calcPr') {
  5994. this.model = {};
  5995. return true;
  5996. }
  5997. return false;
  5998. }
  5999. parseText() {}
  6000. parseClose() {
  6001. return false;
  6002. }
  6003. }
  6004. module.exports = WorkbookCalcPropertiesXform;
  6005. },{"../base-xform":32}],36:[function(require,module,exports){
  6006. "use strict";
  6007. const BaseXform = require('../base-xform');
  6008. class WorksheetPropertiesXform extends BaseXform {
  6009. render(xmlStream, model) {
  6010. xmlStream.leafNode('workbookPr', {
  6011. date1904: model.date1904 ? 1 : undefined,
  6012. defaultThemeVersion: 164011,
  6013. filterPrivacy: 1
  6014. });
  6015. }
  6016. parseOpen(node) {
  6017. if (node.name === 'workbookPr') {
  6018. this.model = {
  6019. date1904: node.attributes.date1904 === '1'
  6020. };
  6021. return true;
  6022. }
  6023. return false;
  6024. }
  6025. parseText() {}
  6026. parseClose() {
  6027. return false;
  6028. }
  6029. }
  6030. module.exports = WorksheetPropertiesXform;
  6031. },{"../base-xform":32}],37:[function(require,module,exports){
  6032. "use strict";
  6033. const BaseXform = require('../base-xform');
  6034. class WorkbookViewXform extends BaseXform {
  6035. render(xmlStream, model) {
  6036. const attributes = {
  6037. xWindow: model.x || 0,
  6038. yWindow: model.y || 0,
  6039. windowWidth: model.width || 12000,
  6040. windowHeight: model.height || 24000,
  6041. firstSheet: model.firstSheet,
  6042. activeTab: model.activeTab
  6043. };
  6044. if (model.visibility && model.visibility !== 'visible') {
  6045. attributes.visibility = model.visibility;
  6046. }
  6047. xmlStream.leafNode('workbookView', attributes);
  6048. }
  6049. parseOpen(node) {
  6050. if (node.name === 'workbookView') {
  6051. const model = this.model = {};
  6052. const addS = function (name, value, dflt) {
  6053. const s = value !== undefined ? model[name] = value : dflt;
  6054. if (s !== undefined) {
  6055. model[name] = s;
  6056. }
  6057. };
  6058. const addN = function (name, value, dflt) {
  6059. const n = value !== undefined ? model[name] = parseInt(value, 10) : dflt;
  6060. if (n !== undefined) {
  6061. model[name] = n;
  6062. }
  6063. };
  6064. addN('x', node.attributes.xWindow, 0);
  6065. addN('y', node.attributes.yWindow, 0);
  6066. addN('width', node.attributes.windowWidth, 25000);
  6067. addN('height', node.attributes.windowHeight, 10000);
  6068. addS('visibility', node.attributes.visibility, 'visible');
  6069. addN('activeTab', node.attributes.activeTab, undefined);
  6070. addN('firstSheet', node.attributes.firstSheet, undefined);
  6071. return true;
  6072. }
  6073. return false;
  6074. }
  6075. parseText() {}
  6076. parseClose() {
  6077. return false;
  6078. }
  6079. }
  6080. module.exports = WorkbookViewXform;
  6081. },{"../base-xform":32}],38:[function(require,module,exports){
  6082. "use strict";
  6083. const _ = require('../../../utils/under-dash');
  6084. const colCache = require('../../../utils/col-cache');
  6085. const XmlStream = require('../../../utils/xml-stream');
  6086. const BaseXform = require('../base-xform');
  6087. const StaticXform = require('../static-xform');
  6088. const ListXform = require('../list-xform');
  6089. const DefinedNameXform = require('./defined-name-xform');
  6090. const SheetXform = require('./sheet-xform');
  6091. const WorkbookViewXform = require('./workbook-view-xform');
  6092. const WorkbookPropertiesXform = require('./workbook-properties-xform');
  6093. const WorkbookCalcPropertiesXform = require('./workbook-calc-properties-xform');
  6094. class WorkbookXform extends BaseXform {
  6095. constructor() {
  6096. super();
  6097. this.map = {
  6098. fileVersion: WorkbookXform.STATIC_XFORMS.fileVersion,
  6099. workbookPr: new WorkbookPropertiesXform(),
  6100. bookViews: new ListXform({
  6101. tag: 'bookViews',
  6102. count: false,
  6103. childXform: new WorkbookViewXform()
  6104. }),
  6105. sheets: new ListXform({
  6106. tag: 'sheets',
  6107. count: false,
  6108. childXform: new SheetXform()
  6109. }),
  6110. definedNames: new ListXform({
  6111. tag: 'definedNames',
  6112. count: false,
  6113. childXform: new DefinedNameXform()
  6114. }),
  6115. calcPr: new WorkbookCalcPropertiesXform()
  6116. };
  6117. }
  6118. prepare(model) {
  6119. model.sheets = model.worksheets;
  6120. // collate all the print areas from all of the sheets and add them to the defined names
  6121. const printAreas = [];
  6122. let index = 0; // sheets is sparse array - calc index manually
  6123. model.sheets.forEach(sheet => {
  6124. if (sheet.pageSetup && sheet.pageSetup.printArea) {
  6125. sheet.pageSetup.printArea.split('&&').forEach(printArea => {
  6126. const printAreaComponents = printArea.split(':');
  6127. const definedName = {
  6128. name: '_xlnm.Print_Area',
  6129. ranges: [`'${sheet.name}'!$${printAreaComponents[0]}:$${printAreaComponents[1]}`],
  6130. localSheetId: index
  6131. };
  6132. printAreas.push(definedName);
  6133. });
  6134. }
  6135. if (sheet.pageSetup && (sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)) {
  6136. const ranges = [];
  6137. if (sheet.pageSetup.printTitlesColumn) {
  6138. const titlesColumns = sheet.pageSetup.printTitlesColumn.split(':');
  6139. ranges.push(`'${sheet.name}'!$${titlesColumns[0]}:$${titlesColumns[1]}`);
  6140. }
  6141. if (sheet.pageSetup.printTitlesRow) {
  6142. const titlesRows = sheet.pageSetup.printTitlesRow.split(':');
  6143. ranges.push(`'${sheet.name}'!$${titlesRows[0]}:$${titlesRows[1]}`);
  6144. }
  6145. const definedName = {
  6146. name: '_xlnm.Print_Titles',
  6147. ranges,
  6148. localSheetId: index
  6149. };
  6150. printAreas.push(definedName);
  6151. }
  6152. index++;
  6153. });
  6154. if (printAreas.length) {
  6155. model.definedNames = model.definedNames.concat(printAreas);
  6156. }
  6157. (model.media || []).forEach((medium, i) => {
  6158. // assign name
  6159. medium.name = medium.type + (i + 1);
  6160. });
  6161. }
  6162. render(xmlStream, model) {
  6163. xmlStream.openXml(XmlStream.StdDocAttributes);
  6164. xmlStream.openNode('workbook', WorkbookXform.WORKBOOK_ATTRIBUTES);
  6165. this.map.fileVersion.render(xmlStream);
  6166. this.map.workbookPr.render(xmlStream, model.properties);
  6167. this.map.bookViews.render(xmlStream, model.views);
  6168. this.map.sheets.render(xmlStream, model.sheets);
  6169. this.map.definedNames.render(xmlStream, model.definedNames);
  6170. this.map.calcPr.render(xmlStream, model.calcProperties);
  6171. xmlStream.closeNode();
  6172. }
  6173. parseOpen(node) {
  6174. if (this.parser) {
  6175. this.parser.parseOpen(node);
  6176. return true;
  6177. }
  6178. switch (node.name) {
  6179. case 'workbook':
  6180. return true;
  6181. default:
  6182. this.parser = this.map[node.name];
  6183. if (this.parser) {
  6184. this.parser.parseOpen(node);
  6185. }
  6186. return true;
  6187. }
  6188. }
  6189. parseText(text) {
  6190. if (this.parser) {
  6191. this.parser.parseText(text);
  6192. }
  6193. }
  6194. parseClose(name) {
  6195. if (this.parser) {
  6196. if (!this.parser.parseClose(name)) {
  6197. this.parser = undefined;
  6198. }
  6199. return true;
  6200. }
  6201. switch (name) {
  6202. case 'workbook':
  6203. this.model = {
  6204. sheets: this.map.sheets.model,
  6205. properties: this.map.workbookPr.model || {},
  6206. views: this.map.bookViews.model,
  6207. calcProperties: {}
  6208. };
  6209. if (this.map.definedNames.model) {
  6210. this.model.definedNames = this.map.definedNames.model;
  6211. }
  6212. return false;
  6213. default:
  6214. // not quite sure how we get here!
  6215. return true;
  6216. }
  6217. }
  6218. reconcile(model) {
  6219. const rels = (model.workbookRels || []).reduce((map, rel) => {
  6220. map[rel.Id] = rel;
  6221. return map;
  6222. }, {});
  6223. // reconcile sheet ids, rIds and names
  6224. const worksheets = [];
  6225. let worksheet;
  6226. let index = 0;
  6227. (model.sheets || []).forEach(sheet => {
  6228. const rel = rels[sheet.rId];
  6229. if (!rel) {
  6230. return;
  6231. }
  6232. // if rel.Target start with `[space]/xl/` or `/xl/` , then it will be replaced with `''` and spliced behind `xl/`,
  6233. // otherwise it will be spliced directly behind `xl/`. i.g.
  6234. worksheet = model.worksheetHash[`xl/${rel.Target.replace(/^(\s|\/xl\/)+/, '')}`];
  6235. // If there are "chartsheets" in the file, rel.Target will
  6236. // come out as chartsheets/sheet1.xml or similar here, and
  6237. // that won't be in model.worksheetHash.
  6238. // As we don't have the infrastructure to support chartsheets,
  6239. // we will ignore them for now:
  6240. if (worksheet) {
  6241. worksheet.name = sheet.name;
  6242. worksheet.id = sheet.id;
  6243. worksheet.state = sheet.state;
  6244. worksheets[index++] = worksheet;
  6245. }
  6246. });
  6247. // reconcile print areas
  6248. const definedNames = [];
  6249. _.each(model.definedNames, definedName => {
  6250. if (definedName.name === '_xlnm.Print_Area') {
  6251. worksheet = worksheets[definedName.localSheetId];
  6252. if (worksheet) {
  6253. if (!worksheet.pageSetup) {
  6254. worksheet.pageSetup = {};
  6255. }
  6256. const range = colCache.decodeEx(definedName.ranges[0]);
  6257. worksheet.pageSetup.printArea = worksheet.pageSetup.printArea ? `${worksheet.pageSetup.printArea}&&${range.dimensions}` : range.dimensions;
  6258. }
  6259. } else if (definedName.name === '_xlnm.Print_Titles') {
  6260. worksheet = worksheets[definedName.localSheetId];
  6261. if (worksheet) {
  6262. if (!worksheet.pageSetup) {
  6263. worksheet.pageSetup = {};
  6264. }
  6265. const rangeString = definedName.ranges.join(',');
  6266. const dollarRegex = /\$/g;
  6267. const rowRangeRegex = /\$\d+:\$\d+/;
  6268. const rowRangeMatches = rangeString.match(rowRangeRegex);
  6269. if (rowRangeMatches && rowRangeMatches.length) {
  6270. const range = rowRangeMatches[0];
  6271. worksheet.pageSetup.printTitlesRow = range.replace(dollarRegex, '');
  6272. }
  6273. const columnRangeRegex = /\$[A-Z]+:\$[A-Z]+/;
  6274. const columnRangeMatches = rangeString.match(columnRangeRegex);
  6275. if (columnRangeMatches && columnRangeMatches.length) {
  6276. const range = columnRangeMatches[0];
  6277. worksheet.pageSetup.printTitlesColumn = range.replace(dollarRegex, '');
  6278. }
  6279. }
  6280. } else {
  6281. definedNames.push(definedName);
  6282. }
  6283. });
  6284. model.definedNames = definedNames;
  6285. // used by sheets to build their image models
  6286. model.media.forEach((media, i) => {
  6287. media.index = i;
  6288. });
  6289. }
  6290. }
  6291. WorkbookXform.WORKBOOK_ATTRIBUTES = {
  6292. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  6293. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  6294. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  6295. 'mc:Ignorable': 'x15',
  6296. 'xmlns:x15': 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main'
  6297. };
  6298. WorkbookXform.STATIC_XFORMS = {
  6299. fileVersion: new StaticXform({
  6300. tag: 'fileVersion',
  6301. $: {
  6302. appName: 'xl',
  6303. lastEdited: 5,
  6304. lowestEdited: 5,
  6305. rupBuild: 9303
  6306. }
  6307. })
  6308. };
  6309. module.exports = WorkbookXform;
  6310. },{"../../../utils/col-cache":19,"../../../utils/under-dash":26,"../../../utils/xml-stream":28,"../base-xform":32,"../list-xform":71,"../static-xform":120,"./defined-name-xform":33,"./sheet-xform":34,"./workbook-calc-properties-xform":35,"./workbook-properties-xform":36,"./workbook-view-xform":37}],39:[function(require,module,exports){
  6311. "use strict";
  6312. const RichTextXform = require('../strings/rich-text-xform');
  6313. const utils = require('../../../utils/utils');
  6314. const BaseXform = require('../base-xform');
  6315. /**
  6316. <comment ref="B1" authorId="0">
  6317. <text>
  6318. <r>
  6319. <rPr>
  6320. <b/>
  6321. <sz val="9"/>
  6322. <rFont val="宋体"/>
  6323. <charset val="134"/>
  6324. </rPr>
  6325. <t>51422:</t>
  6326. </r>
  6327. <r>
  6328. <rPr>
  6329. <sz val="9"/>
  6330. <rFont val="宋体"/>
  6331. <charset val="134"/>
  6332. </rPr>
  6333. <t xml:space="preserve">&#10;test</t>
  6334. </r>
  6335. </text>
  6336. </comment>
  6337. */
  6338. const CommentXform = module.exports = function (model) {
  6339. this.model = model;
  6340. };
  6341. utils.inherits(CommentXform, BaseXform, {
  6342. get tag() {
  6343. return 'r';
  6344. },
  6345. get richTextXform() {
  6346. if (!this._richTextXform) {
  6347. this._richTextXform = new RichTextXform();
  6348. }
  6349. return this._richTextXform;
  6350. },
  6351. render(xmlStream, model) {
  6352. model = model || this.model;
  6353. xmlStream.openNode('comment', {
  6354. ref: model.ref,
  6355. authorId: 0
  6356. });
  6357. xmlStream.openNode('text');
  6358. if (model && model.note && model.note.texts) {
  6359. model.note.texts.forEach(text => {
  6360. this.richTextXform.render(xmlStream, text);
  6361. });
  6362. }
  6363. xmlStream.closeNode();
  6364. xmlStream.closeNode();
  6365. },
  6366. parseOpen(node) {
  6367. if (this.parser) {
  6368. this.parser.parseOpen(node);
  6369. return true;
  6370. }
  6371. switch (node.name) {
  6372. case 'comment':
  6373. this.model = {
  6374. type: 'note',
  6375. note: {
  6376. texts: []
  6377. },
  6378. ...node.attributes
  6379. };
  6380. return true;
  6381. case 'r':
  6382. this.parser = this.richTextXform;
  6383. this.parser.parseOpen(node);
  6384. return true;
  6385. default:
  6386. return false;
  6387. }
  6388. },
  6389. parseText(text) {
  6390. if (this.parser) {
  6391. this.parser.parseText(text);
  6392. }
  6393. },
  6394. parseClose(name) {
  6395. switch (name) {
  6396. case 'comment':
  6397. return false;
  6398. case 'r':
  6399. this.model.note.texts.push(this.parser.model);
  6400. this.parser = undefined;
  6401. return true;
  6402. default:
  6403. if (this.parser) {
  6404. this.parser.parseClose(name);
  6405. }
  6406. return true;
  6407. }
  6408. }
  6409. });
  6410. },{"../../../utils/utils":27,"../base-xform":32,"../strings/rich-text-xform":122}],40:[function(require,module,exports){
  6411. "use strict";
  6412. const XmlStream = require('../../../utils/xml-stream');
  6413. const utils = require('../../../utils/utils');
  6414. const BaseXform = require('../base-xform');
  6415. const CommentXform = require('./comment-xform');
  6416. const CommentsXform = module.exports = function () {
  6417. this.map = {
  6418. comment: new CommentXform()
  6419. };
  6420. };
  6421. utils.inherits(CommentsXform, BaseXform, {
  6422. COMMENTS_ATTRIBUTES: {
  6423. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'
  6424. }
  6425. }, {
  6426. render(xmlStream, model) {
  6427. model = model || this.model;
  6428. xmlStream.openXml(XmlStream.StdDocAttributes);
  6429. xmlStream.openNode('comments', CommentsXform.COMMENTS_ATTRIBUTES);
  6430. // authors
  6431. // TODO: support authors properly
  6432. xmlStream.openNode('authors');
  6433. xmlStream.leafNode('author', null, 'Author');
  6434. xmlStream.closeNode();
  6435. // comments
  6436. xmlStream.openNode('commentList');
  6437. model.comments.forEach(comment => {
  6438. this.map.comment.render(xmlStream, comment);
  6439. });
  6440. xmlStream.closeNode();
  6441. xmlStream.closeNode();
  6442. },
  6443. parseOpen(node) {
  6444. if (this.parser) {
  6445. this.parser.parseOpen(node);
  6446. return true;
  6447. }
  6448. switch (node.name) {
  6449. case 'commentList':
  6450. this.model = {
  6451. comments: []
  6452. };
  6453. return true;
  6454. case 'comment':
  6455. this.parser = this.map.comment;
  6456. this.parser.parseOpen(node);
  6457. return true;
  6458. default:
  6459. return false;
  6460. }
  6461. },
  6462. parseText(text) {
  6463. if (this.parser) {
  6464. this.parser.parseText(text);
  6465. }
  6466. },
  6467. parseClose(name) {
  6468. switch (name) {
  6469. case 'commentList':
  6470. return false;
  6471. case 'comment':
  6472. this.model.comments.push(this.parser.model);
  6473. this.parser = undefined;
  6474. return true;
  6475. default:
  6476. if (this.parser) {
  6477. this.parser.parseClose(name);
  6478. }
  6479. return true;
  6480. }
  6481. }
  6482. });
  6483. },{"../../../utils/utils":27,"../../../utils/xml-stream":28,"../base-xform":32,"./comment-xform":39}],41:[function(require,module,exports){
  6484. "use strict";
  6485. const BaseXform = require('../../base-xform');
  6486. class VmlPositionXform extends BaseXform {
  6487. constructor(model) {
  6488. super();
  6489. this._model = model;
  6490. }
  6491. get tag() {
  6492. return this._model && this._model.tag;
  6493. }
  6494. render(xmlStream, model, type) {
  6495. if (model === type[2]) {
  6496. xmlStream.leafNode(this.tag);
  6497. } else if (this.tag === 'x:SizeWithCells' && model === type[1]) {
  6498. xmlStream.leafNode(this.tag);
  6499. }
  6500. }
  6501. parseOpen(node) {
  6502. switch (node.name) {
  6503. case this.tag:
  6504. this.model = {};
  6505. this.model[this.tag] = true;
  6506. return true;
  6507. default:
  6508. return false;
  6509. }
  6510. }
  6511. parseText() {}
  6512. parseClose() {
  6513. return false;
  6514. }
  6515. }
  6516. module.exports = VmlPositionXform;
  6517. },{"../../base-xform":32}],42:[function(require,module,exports){
  6518. "use strict";
  6519. const BaseXform = require('../../base-xform');
  6520. class VmlProtectionXform extends BaseXform {
  6521. constructor(model) {
  6522. super();
  6523. this._model = model;
  6524. }
  6525. get tag() {
  6526. return this._model && this._model.tag;
  6527. }
  6528. render(xmlStream, model) {
  6529. xmlStream.leafNode(this.tag, null, model);
  6530. }
  6531. parseOpen(node) {
  6532. switch (node.name) {
  6533. case this.tag:
  6534. this.text = '';
  6535. return true;
  6536. default:
  6537. return false;
  6538. }
  6539. }
  6540. parseText(text) {
  6541. this.text = text;
  6542. }
  6543. parseClose() {
  6544. return false;
  6545. }
  6546. }
  6547. module.exports = VmlProtectionXform;
  6548. },{"../../base-xform":32}],43:[function(require,module,exports){
  6549. "use strict";
  6550. const BaseXform = require('../base-xform');
  6551. // render the triangle in the cell for the comment
  6552. class VmlAnchorXform extends BaseXform {
  6553. get tag() {
  6554. return 'x:Anchor';
  6555. }
  6556. getAnchorRect(anchor) {
  6557. const l = Math.floor(anchor.left);
  6558. const lf = Math.floor((anchor.left - l) * 68);
  6559. const t = Math.floor(anchor.top);
  6560. const tf = Math.floor((anchor.top - t) * 18);
  6561. const r = Math.floor(anchor.right);
  6562. const rf = Math.floor((anchor.right - r) * 68);
  6563. const b = Math.floor(anchor.bottom);
  6564. const bf = Math.floor((anchor.bottom - b) * 18);
  6565. return [l, lf, t, tf, r, rf, b, bf];
  6566. }
  6567. getDefaultRect(ref) {
  6568. const l = ref.col;
  6569. const lf = 6;
  6570. const t = Math.max(ref.row - 2, 0);
  6571. const tf = 14;
  6572. const r = l + 2;
  6573. const rf = 2;
  6574. const b = t + 4;
  6575. const bf = 16;
  6576. return [l, lf, t, tf, r, rf, b, bf];
  6577. }
  6578. render(xmlStream, model) {
  6579. const rect = model.anchor ? this.getAnchorRect(model.anchor) : this.getDefaultRect(model.refAddress);
  6580. xmlStream.leafNode('x:Anchor', null, rect.join(', '));
  6581. }
  6582. parseOpen(node) {
  6583. switch (node.name) {
  6584. case this.tag:
  6585. this.text = '';
  6586. return true;
  6587. default:
  6588. return false;
  6589. }
  6590. }
  6591. parseText(text) {
  6592. this.text = text;
  6593. }
  6594. parseClose() {
  6595. return false;
  6596. }
  6597. }
  6598. module.exports = VmlAnchorXform;
  6599. },{"../base-xform":32}],44:[function(require,module,exports){
  6600. "use strict";
  6601. const BaseXform = require('../base-xform');
  6602. const VmlAnchorXform = require('./vml-anchor-xform');
  6603. const VmlProtectionXform = require('./style/vml-protection-xform');
  6604. const VmlPositionXform = require('./style/vml-position-xform');
  6605. const POSITION_TYPE = ['twoCells', 'oneCells', 'absolute'];
  6606. class VmlClientDataXform extends BaseXform {
  6607. constructor() {
  6608. super();
  6609. this.map = {
  6610. 'x:Anchor': new VmlAnchorXform(),
  6611. 'x:Locked': new VmlProtectionXform({
  6612. tag: 'x:Locked'
  6613. }),
  6614. 'x:LockText': new VmlProtectionXform({
  6615. tag: 'x:LockText'
  6616. }),
  6617. 'x:SizeWithCells': new VmlPositionXform({
  6618. tag: 'x:SizeWithCells'
  6619. }),
  6620. 'x:MoveWithCells': new VmlPositionXform({
  6621. tag: 'x:MoveWithCells'
  6622. })
  6623. };
  6624. }
  6625. get tag() {
  6626. return 'x:ClientData';
  6627. }
  6628. render(xmlStream, model) {
  6629. const {
  6630. protection,
  6631. editAs
  6632. } = model.note;
  6633. xmlStream.openNode(this.tag, {
  6634. ObjectType: 'Note'
  6635. });
  6636. this.map['x:MoveWithCells'].render(xmlStream, editAs, POSITION_TYPE);
  6637. this.map['x:SizeWithCells'].render(xmlStream, editAs, POSITION_TYPE);
  6638. this.map['x:Anchor'].render(xmlStream, model);
  6639. this.map['x:Locked'].render(xmlStream, protection.locked);
  6640. xmlStream.leafNode('x:AutoFill', null, 'False');
  6641. this.map['x:LockText'].render(xmlStream, protection.lockText);
  6642. xmlStream.leafNode('x:Row', null, model.refAddress.row - 1);
  6643. xmlStream.leafNode('x:Column', null, model.refAddress.col - 1);
  6644. xmlStream.closeNode();
  6645. }
  6646. parseOpen(node) {
  6647. switch (node.name) {
  6648. case this.tag:
  6649. this.reset();
  6650. this.model = {
  6651. anchor: [],
  6652. protection: {},
  6653. editAs: ''
  6654. };
  6655. break;
  6656. default:
  6657. this.parser = this.map[node.name];
  6658. if (this.parser) {
  6659. this.parser.parseOpen(node);
  6660. }
  6661. break;
  6662. }
  6663. return true;
  6664. }
  6665. parseText(text) {
  6666. if (this.parser) {
  6667. this.parser.parseText(text);
  6668. }
  6669. }
  6670. parseClose(name) {
  6671. if (this.parser) {
  6672. if (!this.parser.parseClose(name)) {
  6673. this.parser = undefined;
  6674. }
  6675. return true;
  6676. }
  6677. switch (name) {
  6678. case this.tag:
  6679. this.normalizeModel();
  6680. return false;
  6681. default:
  6682. return true;
  6683. }
  6684. }
  6685. normalizeModel() {
  6686. const position = Object.assign({}, this.map['x:MoveWithCells'].model, this.map['x:SizeWithCells'].model);
  6687. const len = Object.keys(position).length;
  6688. this.model.editAs = POSITION_TYPE[len];
  6689. this.model.anchor = this.map['x:Anchor'].text;
  6690. this.model.protection.locked = this.map['x:Locked'].text;
  6691. this.model.protection.lockText = this.map['x:LockText'].text;
  6692. }
  6693. }
  6694. module.exports = VmlClientDataXform;
  6695. },{"../base-xform":32,"./style/vml-position-xform":41,"./style/vml-protection-xform":42,"./vml-anchor-xform":43}],45:[function(require,module,exports){
  6696. "use strict";
  6697. const XmlStream = require('../../../utils/xml-stream');
  6698. const BaseXform = require('../base-xform');
  6699. const VmlShapeXform = require('./vml-shape-xform');
  6700. // This class is (currently) single purposed to insert the triangle
  6701. // drawing icons on commented cells
  6702. class VmlNotesXform extends BaseXform {
  6703. constructor() {
  6704. super();
  6705. this.map = {
  6706. 'v:shape': new VmlShapeXform()
  6707. };
  6708. }
  6709. get tag() {
  6710. return 'xml';
  6711. }
  6712. render(xmlStream, model) {
  6713. xmlStream.openXml(XmlStream.StdDocAttributes);
  6714. xmlStream.openNode(this.tag, VmlNotesXform.DRAWING_ATTRIBUTES);
  6715. xmlStream.openNode('o:shapelayout', {
  6716. 'v:ext': 'edit'
  6717. });
  6718. xmlStream.leafNode('o:idmap', {
  6719. 'v:ext': 'edit',
  6720. data: 1
  6721. });
  6722. xmlStream.closeNode();
  6723. xmlStream.openNode('v:shapetype', {
  6724. id: '_x0000_t202',
  6725. coordsize: '21600,21600',
  6726. 'o:spt': 202,
  6727. path: 'm,l,21600r21600,l21600,xe'
  6728. });
  6729. xmlStream.leafNode('v:stroke', {
  6730. joinstyle: 'miter'
  6731. });
  6732. xmlStream.leafNode('v:path', {
  6733. gradientshapeok: 't',
  6734. 'o:connecttype': 'rect'
  6735. });
  6736. xmlStream.closeNode();
  6737. model.comments.forEach((item, index) => {
  6738. this.map['v:shape'].render(xmlStream, item, index);
  6739. });
  6740. xmlStream.closeNode();
  6741. }
  6742. parseOpen(node) {
  6743. if (this.parser) {
  6744. this.parser.parseOpen(node);
  6745. return true;
  6746. }
  6747. switch (node.name) {
  6748. case this.tag:
  6749. this.reset();
  6750. this.model = {
  6751. comments: []
  6752. };
  6753. break;
  6754. default:
  6755. this.parser = this.map[node.name];
  6756. if (this.parser) {
  6757. this.parser.parseOpen(node);
  6758. }
  6759. break;
  6760. }
  6761. return true;
  6762. }
  6763. parseText(text) {
  6764. if (this.parser) {
  6765. this.parser.parseText(text);
  6766. }
  6767. }
  6768. parseClose(name) {
  6769. if (this.parser) {
  6770. if (!this.parser.parseClose(name)) {
  6771. this.model.comments.push(this.parser.model);
  6772. this.parser = undefined;
  6773. }
  6774. return true;
  6775. }
  6776. switch (name) {
  6777. case this.tag:
  6778. return false;
  6779. default:
  6780. // could be some unrecognised tags
  6781. return true;
  6782. }
  6783. }
  6784. reconcile(model, options) {
  6785. model.anchors.forEach(anchor => {
  6786. if (anchor.br) {
  6787. this.map['xdr:twoCellAnchor'].reconcile(anchor, options);
  6788. } else {
  6789. this.map['xdr:oneCellAnchor'].reconcile(anchor, options);
  6790. }
  6791. });
  6792. }
  6793. }
  6794. VmlNotesXform.DRAWING_ATTRIBUTES = {
  6795. 'xmlns:v': 'urn:schemas-microsoft-com:vml',
  6796. 'xmlns:o': 'urn:schemas-microsoft-com:office:office',
  6797. 'xmlns:x': 'urn:schemas-microsoft-com:office:excel'
  6798. };
  6799. module.exports = VmlNotesXform;
  6800. },{"../../../utils/xml-stream":28,"../base-xform":32,"./vml-shape-xform":46}],46:[function(require,module,exports){
  6801. "use strict";
  6802. const BaseXform = require('../base-xform');
  6803. const VmlTextboxXform = require('./vml-textbox-xform');
  6804. const VmlClientDataXform = require('./vml-client-data-xform');
  6805. class VmlShapeXform extends BaseXform {
  6806. constructor() {
  6807. super();
  6808. this.map = {
  6809. 'v:textbox': new VmlTextboxXform(),
  6810. 'x:ClientData': new VmlClientDataXform()
  6811. };
  6812. }
  6813. get tag() {
  6814. return 'v:shape';
  6815. }
  6816. render(xmlStream, model, index) {
  6817. xmlStream.openNode('v:shape', VmlShapeXform.V_SHAPE_ATTRIBUTES(model, index));
  6818. xmlStream.leafNode('v:fill', {
  6819. color2: 'infoBackground [80]'
  6820. });
  6821. xmlStream.leafNode('v:shadow', {
  6822. color: 'none [81]',
  6823. obscured: 't'
  6824. });
  6825. xmlStream.leafNode('v:path', {
  6826. 'o:connecttype': 'none'
  6827. });
  6828. this.map['v:textbox'].render(xmlStream, model);
  6829. this.map['x:ClientData'].render(xmlStream, model);
  6830. xmlStream.closeNode();
  6831. }
  6832. parseOpen(node) {
  6833. if (this.parser) {
  6834. this.parser.parseOpen(node);
  6835. return true;
  6836. }
  6837. switch (node.name) {
  6838. case this.tag:
  6839. this.reset();
  6840. this.model = {
  6841. margins: {
  6842. insetmode: node.attributes['o:insetmode']
  6843. },
  6844. anchor: '',
  6845. editAs: '',
  6846. protection: {}
  6847. };
  6848. break;
  6849. default:
  6850. this.parser = this.map[node.name];
  6851. if (this.parser) {
  6852. this.parser.parseOpen(node);
  6853. }
  6854. break;
  6855. }
  6856. return true;
  6857. }
  6858. parseText(text) {
  6859. if (this.parser) {
  6860. this.parser.parseText(text);
  6861. }
  6862. }
  6863. parseClose(name) {
  6864. if (this.parser) {
  6865. if (!this.parser.parseClose(name)) {
  6866. this.parser = undefined;
  6867. }
  6868. return true;
  6869. }
  6870. switch (name) {
  6871. case this.tag:
  6872. this.model.margins.inset = this.map['v:textbox'].model && this.map['v:textbox'].model.inset;
  6873. this.model.protection = this.map['x:ClientData'].model && this.map['x:ClientData'].model.protection;
  6874. this.model.anchor = this.map['x:ClientData'].model && this.map['x:ClientData'].model.anchor;
  6875. this.model.editAs = this.map['x:ClientData'].model && this.map['x:ClientData'].model.editAs;
  6876. return false;
  6877. default:
  6878. return true;
  6879. }
  6880. }
  6881. }
  6882. VmlShapeXform.V_SHAPE_ATTRIBUTES = (model, index) => ({
  6883. id: `_x0000_s${1025 + index}`,
  6884. type: '#_x0000_t202',
  6885. style: 'position:absolute; margin-left:105.3pt;margin-top:10.5pt;width:97.8pt;height:59.1pt;z-index:1;visibility:hidden',
  6886. fillcolor: 'infoBackground [80]',
  6887. strokecolor: 'none [81]',
  6888. 'o:insetmode': model.note.margins && model.note.margins.insetmode
  6889. });
  6890. module.exports = VmlShapeXform;
  6891. },{"../base-xform":32,"./vml-client-data-xform":44,"./vml-textbox-xform":47}],47:[function(require,module,exports){
  6892. "use strict";
  6893. const BaseXform = require('../base-xform');
  6894. class VmlTextboxXform extends BaseXform {
  6895. get tag() {
  6896. return 'v:textbox';
  6897. }
  6898. conversionUnit(value, multiple, unit) {
  6899. return `${parseFloat(value) * multiple.toFixed(2)}${unit}`;
  6900. }
  6901. reverseConversionUnit(inset) {
  6902. return (inset || '').split(',').map(margin => {
  6903. return Number(parseFloat(this.conversionUnit(parseFloat(margin), 0.1, '')).toFixed(2));
  6904. });
  6905. }
  6906. render(xmlStream, model) {
  6907. const attributes = {
  6908. style: 'mso-direction-alt:auto'
  6909. };
  6910. if (model && model.note) {
  6911. let {
  6912. inset
  6913. } = model.note && model.note.margins;
  6914. if (Array.isArray(inset)) {
  6915. inset = inset.map(margin => {
  6916. return this.conversionUnit(margin, 10, 'mm');
  6917. }).join(',');
  6918. }
  6919. if (inset) {
  6920. attributes.inset = inset;
  6921. }
  6922. }
  6923. xmlStream.openNode('v:textbox', attributes);
  6924. xmlStream.leafNode('div', {
  6925. style: 'text-align:left'
  6926. });
  6927. xmlStream.closeNode();
  6928. }
  6929. parseOpen(node) {
  6930. switch (node.name) {
  6931. case this.tag:
  6932. this.model = {
  6933. inset: this.reverseConversionUnit(node.attributes.inset)
  6934. };
  6935. return true;
  6936. default:
  6937. return true;
  6938. }
  6939. }
  6940. parseText() {}
  6941. parseClose(name) {
  6942. switch (name) {
  6943. case this.tag:
  6944. return false;
  6945. default:
  6946. return true;
  6947. }
  6948. }
  6949. }
  6950. module.exports = VmlTextboxXform;
  6951. },{"../base-xform":32}],48:[function(require,module,exports){
  6952. "use strict";
  6953. const BaseXform = require('./base-xform');
  6954. /* 'virtual' methods used as a form of documentation */
  6955. /* eslint-disable class-methods-use-this */
  6956. // base class for xforms that are composed of other xforms
  6957. // offers some default implementations
  6958. class CompositeXform extends BaseXform {
  6959. createNewModel(node) {
  6960. return {};
  6961. }
  6962. parseOpen(node) {
  6963. // Typical pattern for composite xform
  6964. this.parser = this.parser || this.map[node.name];
  6965. if (this.parser) {
  6966. this.parser.parseOpen(node);
  6967. return true;
  6968. }
  6969. if (node.name === this.tag) {
  6970. this.model = this.createNewModel(node);
  6971. return true;
  6972. }
  6973. return false;
  6974. }
  6975. parseText(text) {
  6976. // Default implementation. Send text to child parser
  6977. if (this.parser) {
  6978. this.parser.parseText(text);
  6979. }
  6980. }
  6981. onParserClose(name, parser) {
  6982. // parseClose has seen a child parser close
  6983. // now need to incorporate into this.model somehow
  6984. this.model[name] = parser.model;
  6985. }
  6986. parseClose(name) {
  6987. // Default implementation
  6988. if (this.parser) {
  6989. if (!this.parser.parseClose(name)) {
  6990. this.onParserClose(name, this.parser);
  6991. this.parser = undefined;
  6992. }
  6993. return true;
  6994. }
  6995. return name !== this.tag;
  6996. }
  6997. }
  6998. module.exports = CompositeXform;
  6999. },{"./base-xform":32}],49:[function(require,module,exports){
  7000. "use strict";
  7001. const BaseXform = require('../base-xform');
  7002. class AppHeadingPairsXform extends BaseXform {
  7003. render(xmlStream, model) {
  7004. xmlStream.openNode('HeadingPairs');
  7005. xmlStream.openNode('vt:vector', {
  7006. size: 2,
  7007. baseType: 'variant'
  7008. });
  7009. xmlStream.openNode('vt:variant');
  7010. xmlStream.leafNode('vt:lpstr', undefined, 'Worksheets');
  7011. xmlStream.closeNode();
  7012. xmlStream.openNode('vt:variant');
  7013. xmlStream.leafNode('vt:i4', undefined, model.length);
  7014. xmlStream.closeNode();
  7015. xmlStream.closeNode();
  7016. xmlStream.closeNode();
  7017. }
  7018. parseOpen(node) {
  7019. // no parsing
  7020. return node.name === 'HeadingPairs';
  7021. }
  7022. parseText() {}
  7023. parseClose(name) {
  7024. return name !== 'HeadingPairs';
  7025. }
  7026. }
  7027. module.exports = AppHeadingPairsXform;
  7028. },{"../base-xform":32}],50:[function(require,module,exports){
  7029. "use strict";
  7030. const BaseXform = require('../base-xform');
  7031. class AppTitlesOfPartsXform extends BaseXform {
  7032. render(xmlStream, model) {
  7033. xmlStream.openNode('TitlesOfParts');
  7034. xmlStream.openNode('vt:vector', {
  7035. size: model.length,
  7036. baseType: 'lpstr'
  7037. });
  7038. model.forEach(sheet => {
  7039. xmlStream.leafNode('vt:lpstr', undefined, sheet.name);
  7040. });
  7041. xmlStream.closeNode();
  7042. xmlStream.closeNode();
  7043. }
  7044. parseOpen(node) {
  7045. // no parsing
  7046. return node.name === 'TitlesOfParts';
  7047. }
  7048. parseText() {}
  7049. parseClose(name) {
  7050. return name !== 'TitlesOfParts';
  7051. }
  7052. }
  7053. module.exports = AppTitlesOfPartsXform;
  7054. },{"../base-xform":32}],51:[function(require,module,exports){
  7055. "use strict";
  7056. const XmlStream = require('../../../utils/xml-stream');
  7057. const BaseXform = require('../base-xform');
  7058. const StringXform = require('../simple/string-xform');
  7059. const AppHeadingPairsXform = require('./app-heading-pairs-xform');
  7060. const AppTitleOfPartsXform = require('./app-titles-of-parts-xform');
  7061. class AppXform extends BaseXform {
  7062. constructor() {
  7063. super();
  7064. this.map = {
  7065. Company: new StringXform({
  7066. tag: 'Company'
  7067. }),
  7068. Manager: new StringXform({
  7069. tag: 'Manager'
  7070. }),
  7071. HeadingPairs: new AppHeadingPairsXform(),
  7072. TitleOfParts: new AppTitleOfPartsXform()
  7073. };
  7074. }
  7075. render(xmlStream, model) {
  7076. xmlStream.openXml(XmlStream.StdDocAttributes);
  7077. xmlStream.openNode('Properties', AppXform.PROPERTY_ATTRIBUTES);
  7078. xmlStream.leafNode('Application', undefined, 'Microsoft Excel');
  7079. xmlStream.leafNode('DocSecurity', undefined, '0');
  7080. xmlStream.leafNode('ScaleCrop', undefined, 'false');
  7081. this.map.HeadingPairs.render(xmlStream, model.worksheets);
  7082. this.map.TitleOfParts.render(xmlStream, model.worksheets);
  7083. this.map.Company.render(xmlStream, model.company || '');
  7084. this.map.Manager.render(xmlStream, model.manager);
  7085. xmlStream.leafNode('LinksUpToDate', undefined, 'false');
  7086. xmlStream.leafNode('SharedDoc', undefined, 'false');
  7087. xmlStream.leafNode('HyperlinksChanged', undefined, 'false');
  7088. xmlStream.leafNode('AppVersion', undefined, '16.0300');
  7089. xmlStream.closeNode();
  7090. }
  7091. parseOpen(node) {
  7092. if (this.parser) {
  7093. this.parser.parseOpen(node);
  7094. return true;
  7095. }
  7096. switch (node.name) {
  7097. case 'Properties':
  7098. return true;
  7099. default:
  7100. this.parser = this.map[node.name];
  7101. if (this.parser) {
  7102. this.parser.parseOpen(node);
  7103. return true;
  7104. }
  7105. // there's a lot we don't bother to parse
  7106. return false;
  7107. }
  7108. }
  7109. parseText(text) {
  7110. if (this.parser) {
  7111. this.parser.parseText(text);
  7112. }
  7113. }
  7114. parseClose(name) {
  7115. if (this.parser) {
  7116. if (!this.parser.parseClose(name)) {
  7117. this.parser = undefined;
  7118. }
  7119. return true;
  7120. }
  7121. switch (name) {
  7122. case 'Properties':
  7123. this.model = {
  7124. worksheets: this.map.TitleOfParts.model,
  7125. company: this.map.Company.model,
  7126. manager: this.map.Manager.model
  7127. };
  7128. return false;
  7129. default:
  7130. return true;
  7131. }
  7132. }
  7133. }
  7134. AppXform.DateFormat = function (dt) {
  7135. return dt.toISOString().replace(/[.]\d{3,6}/, '');
  7136. };
  7137. AppXform.DateAttrs = {
  7138. 'xsi:type': 'dcterms:W3CDTF'
  7139. };
  7140. AppXform.PROPERTY_ATTRIBUTES = {
  7141. xmlns: 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties',
  7142. 'xmlns:vt': 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'
  7143. };
  7144. module.exports = AppXform;
  7145. },{"../../../utils/xml-stream":28,"../base-xform":32,"../simple/string-xform":119,"./app-heading-pairs-xform":49,"./app-titles-of-parts-xform":50}],52:[function(require,module,exports){
  7146. "use strict";
  7147. const XmlStream = require('../../../utils/xml-stream');
  7148. const BaseXform = require('../base-xform');
  7149. // used for rendering the [Content_Types].xml file
  7150. // not used for parsing
  7151. class ContentTypesXform extends BaseXform {
  7152. render(xmlStream, model) {
  7153. xmlStream.openXml(XmlStream.StdDocAttributes);
  7154. xmlStream.openNode('Types', ContentTypesXform.PROPERTY_ATTRIBUTES);
  7155. const mediaHash = {};
  7156. (model.media || []).forEach(medium => {
  7157. if (medium.type === 'image') {
  7158. const imageType = medium.extension;
  7159. if (!mediaHash[imageType]) {
  7160. mediaHash[imageType] = true;
  7161. xmlStream.leafNode('Default', {
  7162. Extension: imageType,
  7163. ContentType: `image/${imageType}`
  7164. });
  7165. }
  7166. }
  7167. });
  7168. xmlStream.leafNode('Default', {
  7169. Extension: 'rels',
  7170. ContentType: 'application/vnd.openxmlformats-package.relationships+xml'
  7171. });
  7172. xmlStream.leafNode('Default', {
  7173. Extension: 'xml',
  7174. ContentType: 'application/xml'
  7175. });
  7176. xmlStream.leafNode('Override', {
  7177. PartName: '/xl/workbook.xml',
  7178. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'
  7179. });
  7180. model.worksheets.forEach(worksheet => {
  7181. const name = `/xl/worksheets/sheet${worksheet.id}.xml`;
  7182. xmlStream.leafNode('Override', {
  7183. PartName: name,
  7184. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'
  7185. });
  7186. });
  7187. xmlStream.leafNode('Override', {
  7188. PartName: '/xl/theme/theme1.xml',
  7189. ContentType: 'application/vnd.openxmlformats-officedocument.theme+xml'
  7190. });
  7191. xmlStream.leafNode('Override', {
  7192. PartName: '/xl/styles.xml',
  7193. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'
  7194. });
  7195. const hasSharedStrings = model.sharedStrings && model.sharedStrings.count;
  7196. if (hasSharedStrings) {
  7197. xmlStream.leafNode('Override', {
  7198. PartName: '/xl/sharedStrings.xml',
  7199. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'
  7200. });
  7201. }
  7202. if (model.tables) {
  7203. model.tables.forEach(table => {
  7204. xmlStream.leafNode('Override', {
  7205. PartName: `/xl/tables/${table.target}`,
  7206. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml'
  7207. });
  7208. });
  7209. }
  7210. if (model.drawings) {
  7211. model.drawings.forEach(drawing => {
  7212. xmlStream.leafNode('Override', {
  7213. PartName: `/xl/drawings/${drawing.name}.xml`,
  7214. ContentType: 'application/vnd.openxmlformats-officedocument.drawing+xml'
  7215. });
  7216. });
  7217. }
  7218. if (model.commentRefs) {
  7219. xmlStream.leafNode('Default', {
  7220. Extension: 'vml',
  7221. ContentType: 'application/vnd.openxmlformats-officedocument.vmlDrawing'
  7222. });
  7223. model.commentRefs.forEach(_ref => {
  7224. let {
  7225. commentName
  7226. } = _ref;
  7227. xmlStream.leafNode('Override', {
  7228. PartName: `/xl/${commentName}.xml`,
  7229. ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml'
  7230. });
  7231. });
  7232. }
  7233. xmlStream.leafNode('Override', {
  7234. PartName: '/docProps/core.xml',
  7235. ContentType: 'application/vnd.openxmlformats-package.core-properties+xml'
  7236. });
  7237. xmlStream.leafNode('Override', {
  7238. PartName: '/docProps/app.xml',
  7239. ContentType: 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
  7240. });
  7241. xmlStream.closeNode();
  7242. }
  7243. parseOpen() {
  7244. return false;
  7245. }
  7246. parseText() {}
  7247. parseClose() {
  7248. return false;
  7249. }
  7250. }
  7251. ContentTypesXform.PROPERTY_ATTRIBUTES = {
  7252. xmlns: 'http://schemas.openxmlformats.org/package/2006/content-types'
  7253. };
  7254. module.exports = ContentTypesXform;
  7255. },{"../../../utils/xml-stream":28,"../base-xform":32}],53:[function(require,module,exports){
  7256. "use strict";
  7257. const XmlStream = require('../../../utils/xml-stream');
  7258. const BaseXform = require('../base-xform');
  7259. const DateXform = require('../simple/date-xform');
  7260. const StringXform = require('../simple/string-xform');
  7261. const IntegerXform = require('../simple/integer-xform');
  7262. class CoreXform extends BaseXform {
  7263. constructor() {
  7264. super();
  7265. this.map = {
  7266. 'dc:creator': new StringXform({
  7267. tag: 'dc:creator'
  7268. }),
  7269. 'dc:title': new StringXform({
  7270. tag: 'dc:title'
  7271. }),
  7272. 'dc:subject': new StringXform({
  7273. tag: 'dc:subject'
  7274. }),
  7275. 'dc:description': new StringXform({
  7276. tag: 'dc:description'
  7277. }),
  7278. 'dc:identifier': new StringXform({
  7279. tag: 'dc:identifier'
  7280. }),
  7281. 'dc:language': new StringXform({
  7282. tag: 'dc:language'
  7283. }),
  7284. 'cp:keywords': new StringXform({
  7285. tag: 'cp:keywords'
  7286. }),
  7287. 'cp:category': new StringXform({
  7288. tag: 'cp:category'
  7289. }),
  7290. 'cp:lastModifiedBy': new StringXform({
  7291. tag: 'cp:lastModifiedBy'
  7292. }),
  7293. 'cp:lastPrinted': new DateXform({
  7294. tag: 'cp:lastPrinted',
  7295. format: CoreXform.DateFormat
  7296. }),
  7297. 'cp:revision': new IntegerXform({
  7298. tag: 'cp:revision'
  7299. }),
  7300. 'cp:version': new StringXform({
  7301. tag: 'cp:version'
  7302. }),
  7303. 'cp:contentStatus': new StringXform({
  7304. tag: 'cp:contentStatus'
  7305. }),
  7306. 'cp:contentType': new StringXform({
  7307. tag: 'cp:contentType'
  7308. }),
  7309. 'dcterms:created': new DateXform({
  7310. tag: 'dcterms:created',
  7311. attrs: CoreXform.DateAttrs,
  7312. format: CoreXform.DateFormat
  7313. }),
  7314. 'dcterms:modified': new DateXform({
  7315. tag: 'dcterms:modified',
  7316. attrs: CoreXform.DateAttrs,
  7317. format: CoreXform.DateFormat
  7318. })
  7319. };
  7320. }
  7321. render(xmlStream, model) {
  7322. xmlStream.openXml(XmlStream.StdDocAttributes);
  7323. xmlStream.openNode('cp:coreProperties', CoreXform.CORE_PROPERTY_ATTRIBUTES);
  7324. this.map['dc:creator'].render(xmlStream, model.creator);
  7325. this.map['dc:title'].render(xmlStream, model.title);
  7326. this.map['dc:subject'].render(xmlStream, model.subject);
  7327. this.map['dc:description'].render(xmlStream, model.description);
  7328. this.map['dc:identifier'].render(xmlStream, model.identifier);
  7329. this.map['dc:language'].render(xmlStream, model.language);
  7330. this.map['cp:keywords'].render(xmlStream, model.keywords);
  7331. this.map['cp:category'].render(xmlStream, model.category);
  7332. this.map['cp:lastModifiedBy'].render(xmlStream, model.lastModifiedBy);
  7333. this.map['cp:lastPrinted'].render(xmlStream, model.lastPrinted);
  7334. this.map['cp:revision'].render(xmlStream, model.revision);
  7335. this.map['cp:version'].render(xmlStream, model.version);
  7336. this.map['cp:contentStatus'].render(xmlStream, model.contentStatus);
  7337. this.map['cp:contentType'].render(xmlStream, model.contentType);
  7338. this.map['dcterms:created'].render(xmlStream, model.created);
  7339. this.map['dcterms:modified'].render(xmlStream, model.modified);
  7340. xmlStream.closeNode();
  7341. }
  7342. parseOpen(node) {
  7343. if (this.parser) {
  7344. this.parser.parseOpen(node);
  7345. return true;
  7346. }
  7347. switch (node.name) {
  7348. case 'cp:coreProperties':
  7349. case 'coreProperties':
  7350. return true;
  7351. default:
  7352. this.parser = this.map[node.name];
  7353. if (this.parser) {
  7354. this.parser.parseOpen(node);
  7355. return true;
  7356. }
  7357. throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
  7358. }
  7359. }
  7360. parseText(text) {
  7361. if (this.parser) {
  7362. this.parser.parseText(text);
  7363. }
  7364. }
  7365. parseClose(name) {
  7366. if (this.parser) {
  7367. if (!this.parser.parseClose(name)) {
  7368. this.parser = undefined;
  7369. }
  7370. return true;
  7371. }
  7372. switch (name) {
  7373. case 'cp:coreProperties':
  7374. case 'coreProperties':
  7375. this.model = {
  7376. creator: this.map['dc:creator'].model,
  7377. title: this.map['dc:title'].model,
  7378. subject: this.map['dc:subject'].model,
  7379. description: this.map['dc:description'].model,
  7380. identifier: this.map['dc:identifier'].model,
  7381. language: this.map['dc:language'].model,
  7382. keywords: this.map['cp:keywords'].model,
  7383. category: this.map['cp:category'].model,
  7384. lastModifiedBy: this.map['cp:lastModifiedBy'].model,
  7385. lastPrinted: this.map['cp:lastPrinted'].model,
  7386. revision: this.map['cp:revision'].model,
  7387. contentStatus: this.map['cp:contentStatus'].model,
  7388. contentType: this.map['cp:contentType'].model,
  7389. created: this.map['dcterms:created'].model,
  7390. modified: this.map['dcterms:modified'].model
  7391. };
  7392. return false;
  7393. default:
  7394. throw new Error(`Unexpected xml node in parseClose: ${name}`);
  7395. }
  7396. }
  7397. }
  7398. CoreXform.DateFormat = function (dt) {
  7399. return dt.toISOString().replace(/[.]\d{3}/, '');
  7400. };
  7401. CoreXform.DateAttrs = {
  7402. 'xsi:type': 'dcterms:W3CDTF'
  7403. };
  7404. CoreXform.CORE_PROPERTY_ATTRIBUTES = {
  7405. 'xmlns:cp': 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
  7406. 'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
  7407. 'xmlns:dcterms': 'http://purl.org/dc/terms/',
  7408. 'xmlns:dcmitype': 'http://purl.org/dc/dcmitype/',
  7409. 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance'
  7410. };
  7411. module.exports = CoreXform;
  7412. },{"../../../utils/xml-stream":28,"../base-xform":32,"../simple/date-xform":117,"../simple/integer-xform":118,"../simple/string-xform":119}],54:[function(require,module,exports){
  7413. "use strict";
  7414. const BaseXform = require('../base-xform');
  7415. class RelationshipXform extends BaseXform {
  7416. render(xmlStream, model) {
  7417. xmlStream.leafNode('Relationship', model);
  7418. }
  7419. parseOpen(node) {
  7420. switch (node.name) {
  7421. case 'Relationship':
  7422. this.model = node.attributes;
  7423. return true;
  7424. default:
  7425. return false;
  7426. }
  7427. }
  7428. parseText() {}
  7429. parseClose() {
  7430. return false;
  7431. }
  7432. }
  7433. module.exports = RelationshipXform;
  7434. },{"../base-xform":32}],55:[function(require,module,exports){
  7435. "use strict";
  7436. const XmlStream = require('../../../utils/xml-stream');
  7437. const BaseXform = require('../base-xform');
  7438. const RelationshipXform = require('./relationship-xform');
  7439. class RelationshipsXform extends BaseXform {
  7440. constructor() {
  7441. super();
  7442. this.map = {
  7443. Relationship: new RelationshipXform()
  7444. };
  7445. }
  7446. render(xmlStream, model) {
  7447. model = model || this._values;
  7448. xmlStream.openXml(XmlStream.StdDocAttributes);
  7449. xmlStream.openNode('Relationships', RelationshipsXform.RELATIONSHIPS_ATTRIBUTES);
  7450. model.forEach(relationship => {
  7451. this.map.Relationship.render(xmlStream, relationship);
  7452. });
  7453. xmlStream.closeNode();
  7454. }
  7455. parseOpen(node) {
  7456. if (this.parser) {
  7457. this.parser.parseOpen(node);
  7458. return true;
  7459. }
  7460. switch (node.name) {
  7461. case 'Relationships':
  7462. this.model = [];
  7463. return true;
  7464. default:
  7465. this.parser = this.map[node.name];
  7466. if (this.parser) {
  7467. this.parser.parseOpen(node);
  7468. return true;
  7469. }
  7470. throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
  7471. }
  7472. }
  7473. parseText(text) {
  7474. if (this.parser) {
  7475. this.parser.parseText(text);
  7476. }
  7477. }
  7478. parseClose(name) {
  7479. if (this.parser) {
  7480. if (!this.parser.parseClose(name)) {
  7481. this.model.push(this.parser.model);
  7482. this.parser = undefined;
  7483. }
  7484. return true;
  7485. }
  7486. switch (name) {
  7487. case 'Relationships':
  7488. return false;
  7489. default:
  7490. throw new Error(`Unexpected xml node in parseClose: ${name}`);
  7491. }
  7492. }
  7493. }
  7494. RelationshipsXform.RELATIONSHIPS_ATTRIBUTES = {
  7495. xmlns: 'http://schemas.openxmlformats.org/package/2006/relationships'
  7496. };
  7497. module.exports = RelationshipsXform;
  7498. },{"../../../utils/xml-stream":28,"../base-xform":32,"./relationship-xform":54}],56:[function(require,module,exports){
  7499. "use strict";
  7500. const BaseXform = require('../base-xform');
  7501. class BaseCellAnchorXform extends BaseXform {
  7502. parseOpen(node) {
  7503. if (this.parser) {
  7504. this.parser.parseOpen(node);
  7505. return true;
  7506. }
  7507. switch (node.name) {
  7508. case this.tag:
  7509. this.reset();
  7510. this.model = {
  7511. range: {
  7512. editAs: node.attributes.editAs || 'oneCell'
  7513. }
  7514. };
  7515. break;
  7516. default:
  7517. this.parser = this.map[node.name];
  7518. if (this.parser) {
  7519. this.parser.parseOpen(node);
  7520. }
  7521. break;
  7522. }
  7523. return true;
  7524. }
  7525. parseText(text) {
  7526. if (this.parser) {
  7527. this.parser.parseText(text);
  7528. }
  7529. }
  7530. reconcilePicture(model, options) {
  7531. if (model && model.rId) {
  7532. const rel = options.rels[model.rId];
  7533. const match = rel.Target.match(/.*\/media\/(.+[.][a-zA-Z]{3,4})/);
  7534. if (match) {
  7535. const name = match[1];
  7536. const mediaId = options.mediaIndex[name];
  7537. return options.media[mediaId];
  7538. }
  7539. }
  7540. return undefined;
  7541. }
  7542. }
  7543. module.exports = BaseCellAnchorXform;
  7544. },{"../base-xform":32}],57:[function(require,module,exports){
  7545. "use strict";
  7546. const BaseXform = require('../base-xform');
  7547. const BlipXform = require('./blip-xform');
  7548. class BlipFillXform extends BaseXform {
  7549. constructor() {
  7550. super();
  7551. this.map = {
  7552. 'a:blip': new BlipXform()
  7553. };
  7554. }
  7555. get tag() {
  7556. return 'xdr:blipFill';
  7557. }
  7558. render(xmlStream, model) {
  7559. xmlStream.openNode(this.tag);
  7560. this.map['a:blip'].render(xmlStream, model);
  7561. // TODO: options for this + parsing
  7562. xmlStream.openNode('a:stretch');
  7563. xmlStream.leafNode('a:fillRect');
  7564. xmlStream.closeNode();
  7565. xmlStream.closeNode();
  7566. }
  7567. parseOpen(node) {
  7568. if (this.parser) {
  7569. this.parser.parseOpen(node);
  7570. return true;
  7571. }
  7572. switch (node.name) {
  7573. case this.tag:
  7574. this.reset();
  7575. break;
  7576. default:
  7577. this.parser = this.map[node.name];
  7578. if (this.parser) {
  7579. this.parser.parseOpen(node);
  7580. }
  7581. break;
  7582. }
  7583. return true;
  7584. }
  7585. parseText() {}
  7586. parseClose(name) {
  7587. if (this.parser) {
  7588. if (!this.parser.parseClose(name)) {
  7589. this.parser = undefined;
  7590. }
  7591. return true;
  7592. }
  7593. switch (name) {
  7594. case this.tag:
  7595. this.model = this.map['a:blip'].model;
  7596. return false;
  7597. default:
  7598. return true;
  7599. }
  7600. }
  7601. }
  7602. module.exports = BlipFillXform;
  7603. },{"../base-xform":32,"./blip-xform":58}],58:[function(require,module,exports){
  7604. "use strict";
  7605. const BaseXform = require('../base-xform');
  7606. class BlipXform extends BaseXform {
  7607. get tag() {
  7608. return 'a:blip';
  7609. }
  7610. render(xmlStream, model) {
  7611. xmlStream.leafNode(this.tag, {
  7612. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  7613. 'r:embed': model.rId,
  7614. cstate: 'print'
  7615. });
  7616. // TODO: handle children (e.g. a:extLst=>a:ext=>a14:useLocalDpi
  7617. }
  7618. parseOpen(node) {
  7619. switch (node.name) {
  7620. case this.tag:
  7621. this.model = {
  7622. rId: node.attributes['r:embed']
  7623. };
  7624. return true;
  7625. default:
  7626. return true;
  7627. }
  7628. }
  7629. parseText() {}
  7630. parseClose(name) {
  7631. switch (name) {
  7632. case this.tag:
  7633. return false;
  7634. default:
  7635. // unprocessed internal nodes
  7636. return true;
  7637. }
  7638. }
  7639. }
  7640. module.exports = BlipXform;
  7641. },{"../base-xform":32}],59:[function(require,module,exports){
  7642. "use strict";
  7643. const BaseXform = require('../base-xform');
  7644. class CNvPicPrXform extends BaseXform {
  7645. get tag() {
  7646. return 'xdr:cNvPicPr';
  7647. }
  7648. render(xmlStream) {
  7649. xmlStream.openNode(this.tag);
  7650. xmlStream.leafNode('a:picLocks', {
  7651. noChangeAspect: '1'
  7652. });
  7653. xmlStream.closeNode();
  7654. }
  7655. parseOpen(node) {
  7656. switch (node.name) {
  7657. case this.tag:
  7658. return true;
  7659. default:
  7660. return true;
  7661. }
  7662. }
  7663. parseText() {}
  7664. parseClose(name) {
  7665. switch (name) {
  7666. case this.tag:
  7667. return false;
  7668. default:
  7669. // unprocessed internal nodes
  7670. return true;
  7671. }
  7672. }
  7673. }
  7674. module.exports = CNvPicPrXform;
  7675. },{"../base-xform":32}],60:[function(require,module,exports){
  7676. "use strict";
  7677. const BaseXform = require('../base-xform');
  7678. const HlickClickXform = require('./hlink-click-xform');
  7679. const ExtLstXform = require('./ext-lst-xform');
  7680. class CNvPrXform extends BaseXform {
  7681. constructor() {
  7682. super();
  7683. this.map = {
  7684. 'a:hlinkClick': new HlickClickXform(),
  7685. 'a:extLst': new ExtLstXform()
  7686. };
  7687. }
  7688. get tag() {
  7689. return 'xdr:cNvPr';
  7690. }
  7691. render(xmlStream, model) {
  7692. xmlStream.openNode(this.tag, {
  7693. id: model.index,
  7694. name: `Picture ${model.index}`
  7695. });
  7696. this.map['a:hlinkClick'].render(xmlStream, model);
  7697. this.map['a:extLst'].render(xmlStream, model);
  7698. xmlStream.closeNode();
  7699. }
  7700. parseOpen(node) {
  7701. if (this.parser) {
  7702. this.parser.parseOpen(node);
  7703. return true;
  7704. }
  7705. switch (node.name) {
  7706. case this.tag:
  7707. this.reset();
  7708. break;
  7709. default:
  7710. this.parser = this.map[node.name];
  7711. if (this.parser) {
  7712. this.parser.parseOpen(node);
  7713. }
  7714. break;
  7715. }
  7716. return true;
  7717. }
  7718. parseText() {}
  7719. parseClose(name) {
  7720. if (this.parser) {
  7721. if (!this.parser.parseClose(name)) {
  7722. this.parser = undefined;
  7723. }
  7724. return true;
  7725. }
  7726. switch (name) {
  7727. case this.tag:
  7728. this.model = this.map['a:hlinkClick'].model;
  7729. return false;
  7730. default:
  7731. return true;
  7732. }
  7733. }
  7734. }
  7735. module.exports = CNvPrXform;
  7736. },{"../base-xform":32,"./ext-lst-xform":63,"./hlink-click-xform":65}],61:[function(require,module,exports){
  7737. "use strict";
  7738. const BaseXform = require('../base-xform');
  7739. const IntegerXform = require('../simple/integer-xform');
  7740. class CellPositionXform extends BaseXform {
  7741. constructor(options) {
  7742. super();
  7743. this.tag = options.tag;
  7744. this.map = {
  7745. 'xdr:col': new IntegerXform({
  7746. tag: 'xdr:col',
  7747. zero: true
  7748. }),
  7749. 'xdr:colOff': new IntegerXform({
  7750. tag: 'xdr:colOff',
  7751. zero: true
  7752. }),
  7753. 'xdr:row': new IntegerXform({
  7754. tag: 'xdr:row',
  7755. zero: true
  7756. }),
  7757. 'xdr:rowOff': new IntegerXform({
  7758. tag: 'xdr:rowOff',
  7759. zero: true
  7760. })
  7761. };
  7762. }
  7763. render(xmlStream, model) {
  7764. xmlStream.openNode(this.tag);
  7765. this.map['xdr:col'].render(xmlStream, model.nativeCol);
  7766. this.map['xdr:colOff'].render(xmlStream, model.nativeColOff);
  7767. this.map['xdr:row'].render(xmlStream, model.nativeRow);
  7768. this.map['xdr:rowOff'].render(xmlStream, model.nativeRowOff);
  7769. xmlStream.closeNode();
  7770. }
  7771. parseOpen(node) {
  7772. if (this.parser) {
  7773. this.parser.parseOpen(node);
  7774. return true;
  7775. }
  7776. switch (node.name) {
  7777. case this.tag:
  7778. this.reset();
  7779. break;
  7780. default:
  7781. this.parser = this.map[node.name];
  7782. if (this.parser) {
  7783. this.parser.parseOpen(node);
  7784. }
  7785. break;
  7786. }
  7787. return true;
  7788. }
  7789. parseText(text) {
  7790. if (this.parser) {
  7791. this.parser.parseText(text);
  7792. }
  7793. }
  7794. parseClose(name) {
  7795. if (this.parser) {
  7796. if (!this.parser.parseClose(name)) {
  7797. this.parser = undefined;
  7798. }
  7799. return true;
  7800. }
  7801. switch (name) {
  7802. case this.tag:
  7803. this.model = {
  7804. nativeCol: this.map['xdr:col'].model,
  7805. nativeColOff: this.map['xdr:colOff'].model,
  7806. nativeRow: this.map['xdr:row'].model,
  7807. nativeRowOff: this.map['xdr:rowOff'].model
  7808. };
  7809. return false;
  7810. default:
  7811. // not quite sure how we get here!
  7812. return true;
  7813. }
  7814. }
  7815. }
  7816. module.exports = CellPositionXform;
  7817. },{"../base-xform":32,"../simple/integer-xform":118}],62:[function(require,module,exports){
  7818. "use strict";
  7819. const colCache = require('../../../utils/col-cache');
  7820. const XmlStream = require('../../../utils/xml-stream');
  7821. const BaseXform = require('../base-xform');
  7822. const TwoCellAnchorXform = require('./two-cell-anchor-xform');
  7823. const OneCellAnchorXform = require('./one-cell-anchor-xform');
  7824. function getAnchorType(model) {
  7825. const range = typeof model.range === 'string' ? colCache.decode(model.range) : model.range;
  7826. return range.br ? 'xdr:twoCellAnchor' : 'xdr:oneCellAnchor';
  7827. }
  7828. class DrawingXform extends BaseXform {
  7829. constructor() {
  7830. super();
  7831. this.map = {
  7832. 'xdr:twoCellAnchor': new TwoCellAnchorXform(),
  7833. 'xdr:oneCellAnchor': new OneCellAnchorXform()
  7834. };
  7835. }
  7836. prepare(model) {
  7837. model.anchors.forEach((item, index) => {
  7838. item.anchorType = getAnchorType(item);
  7839. const anchor = this.map[item.anchorType];
  7840. anchor.prepare(item, {
  7841. index
  7842. });
  7843. });
  7844. }
  7845. get tag() {
  7846. return 'xdr:wsDr';
  7847. }
  7848. render(xmlStream, model) {
  7849. xmlStream.openXml(XmlStream.StdDocAttributes);
  7850. xmlStream.openNode(this.tag, DrawingXform.DRAWING_ATTRIBUTES);
  7851. model.anchors.forEach(item => {
  7852. const anchor = this.map[item.anchorType];
  7853. anchor.render(xmlStream, item);
  7854. });
  7855. xmlStream.closeNode();
  7856. }
  7857. parseOpen(node) {
  7858. if (this.parser) {
  7859. this.parser.parseOpen(node);
  7860. return true;
  7861. }
  7862. switch (node.name) {
  7863. case this.tag:
  7864. this.reset();
  7865. this.model = {
  7866. anchors: []
  7867. };
  7868. break;
  7869. default:
  7870. this.parser = this.map[node.name];
  7871. if (this.parser) {
  7872. this.parser.parseOpen(node);
  7873. }
  7874. break;
  7875. }
  7876. return true;
  7877. }
  7878. parseText(text) {
  7879. if (this.parser) {
  7880. this.parser.parseText(text);
  7881. }
  7882. }
  7883. parseClose(name) {
  7884. if (this.parser) {
  7885. if (!this.parser.parseClose(name)) {
  7886. this.model.anchors.push(this.parser.model);
  7887. this.parser = undefined;
  7888. }
  7889. return true;
  7890. }
  7891. switch (name) {
  7892. case this.tag:
  7893. return false;
  7894. default:
  7895. // could be some unrecognised tags
  7896. return true;
  7897. }
  7898. }
  7899. reconcile(model, options) {
  7900. model.anchors.forEach(anchor => {
  7901. if (anchor.br) {
  7902. this.map['xdr:twoCellAnchor'].reconcile(anchor, options);
  7903. } else {
  7904. this.map['xdr:oneCellAnchor'].reconcile(anchor, options);
  7905. }
  7906. });
  7907. }
  7908. }
  7909. DrawingXform.DRAWING_ATTRIBUTES = {
  7910. 'xmlns:xdr': 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing',
  7911. 'xmlns:a': 'http://schemas.openxmlformats.org/drawingml/2006/main'
  7912. };
  7913. module.exports = DrawingXform;
  7914. },{"../../../utils/col-cache":19,"../../../utils/xml-stream":28,"../base-xform":32,"./one-cell-anchor-xform":67,"./two-cell-anchor-xform":70}],63:[function(require,module,exports){
  7915. "use strict";
  7916. const BaseXform = require('../base-xform');
  7917. class ExtLstXform extends BaseXform {
  7918. get tag() {
  7919. return 'a:extLst';
  7920. }
  7921. render(xmlStream) {
  7922. xmlStream.openNode(this.tag);
  7923. xmlStream.openNode('a:ext', {
  7924. uri: '{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}'
  7925. });
  7926. xmlStream.leafNode('a16:creationId', {
  7927. 'xmlns:a16': 'http://schemas.microsoft.com/office/drawing/2014/main',
  7928. id: '{00000000-0008-0000-0000-000002000000}'
  7929. });
  7930. xmlStream.closeNode();
  7931. xmlStream.closeNode();
  7932. }
  7933. parseOpen(node) {
  7934. switch (node.name) {
  7935. case this.tag:
  7936. return true;
  7937. default:
  7938. return true;
  7939. }
  7940. }
  7941. parseText() {}
  7942. parseClose(name) {
  7943. switch (name) {
  7944. case this.tag:
  7945. return false;
  7946. default:
  7947. // unprocessed internal nodes
  7948. return true;
  7949. }
  7950. }
  7951. }
  7952. module.exports = ExtLstXform;
  7953. },{"../base-xform":32}],64:[function(require,module,exports){
  7954. "use strict";
  7955. const BaseXform = require('../base-xform');
  7956. /** https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML */
  7957. const EMU_PER_PIXEL_AT_96_DPI = 9525;
  7958. class ExtXform extends BaseXform {
  7959. constructor(options) {
  7960. super();
  7961. this.tag = options.tag;
  7962. this.map = {};
  7963. }
  7964. render(xmlStream, model) {
  7965. xmlStream.openNode(this.tag);
  7966. const width = Math.floor(model.width * EMU_PER_PIXEL_AT_96_DPI);
  7967. const height = Math.floor(model.height * EMU_PER_PIXEL_AT_96_DPI);
  7968. xmlStream.addAttribute('cx', width);
  7969. xmlStream.addAttribute('cy', height);
  7970. xmlStream.closeNode();
  7971. }
  7972. parseOpen(node) {
  7973. if (node.name === this.tag) {
  7974. this.model = {
  7975. width: parseInt(node.attributes.cx || '0', 10) / EMU_PER_PIXEL_AT_96_DPI,
  7976. height: parseInt(node.attributes.cy || '0', 10) / EMU_PER_PIXEL_AT_96_DPI
  7977. };
  7978. return true;
  7979. }
  7980. return false;
  7981. }
  7982. parseText( /* text */) {}
  7983. parseClose( /* name */
  7984. ) {
  7985. return false;
  7986. }
  7987. }
  7988. module.exports = ExtXform;
  7989. },{"../base-xform":32}],65:[function(require,module,exports){
  7990. "use strict";
  7991. const BaseXform = require('../base-xform');
  7992. class HLinkClickXform extends BaseXform {
  7993. get tag() {
  7994. return 'a:hlinkClick';
  7995. }
  7996. render(xmlStream, model) {
  7997. if (!(model.hyperlinks && model.hyperlinks.rId)) {
  7998. return;
  7999. }
  8000. xmlStream.leafNode(this.tag, {
  8001. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  8002. 'r:id': model.hyperlinks.rId,
  8003. tooltip: model.hyperlinks.tooltip
  8004. });
  8005. }
  8006. parseOpen(node) {
  8007. switch (node.name) {
  8008. case this.tag:
  8009. this.model = {
  8010. hyperlinks: {
  8011. rId: node.attributes['r:id'],
  8012. tooltip: node.attributes.tooltip
  8013. }
  8014. };
  8015. return true;
  8016. default:
  8017. return true;
  8018. }
  8019. }
  8020. parseText() {}
  8021. parseClose() {
  8022. return false;
  8023. }
  8024. }
  8025. module.exports = HLinkClickXform;
  8026. },{"../base-xform":32}],66:[function(require,module,exports){
  8027. "use strict";
  8028. const BaseXform = require('../base-xform');
  8029. const CNvPrXform = require('./c-nv-pr-xform');
  8030. const CNvPicPrXform = require('./c-nv-pic-pr-xform');
  8031. class NvPicPrXform extends BaseXform {
  8032. constructor() {
  8033. super();
  8034. this.map = {
  8035. 'xdr:cNvPr': new CNvPrXform(),
  8036. 'xdr:cNvPicPr': new CNvPicPrXform()
  8037. };
  8038. }
  8039. get tag() {
  8040. return 'xdr:nvPicPr';
  8041. }
  8042. render(xmlStream, model) {
  8043. xmlStream.openNode(this.tag);
  8044. this.map['xdr:cNvPr'].render(xmlStream, model);
  8045. this.map['xdr:cNvPicPr'].render(xmlStream, model);
  8046. xmlStream.closeNode();
  8047. }
  8048. parseOpen(node) {
  8049. if (this.parser) {
  8050. this.parser.parseOpen(node);
  8051. return true;
  8052. }
  8053. switch (node.name) {
  8054. case this.tag:
  8055. this.reset();
  8056. break;
  8057. default:
  8058. this.parser = this.map[node.name];
  8059. if (this.parser) {
  8060. this.parser.parseOpen(node);
  8061. }
  8062. break;
  8063. }
  8064. return true;
  8065. }
  8066. parseText() {}
  8067. parseClose(name) {
  8068. if (this.parser) {
  8069. if (!this.parser.parseClose(name)) {
  8070. this.parser = undefined;
  8071. }
  8072. return true;
  8073. }
  8074. switch (name) {
  8075. case this.tag:
  8076. this.model = this.map['xdr:cNvPr'].model;
  8077. return false;
  8078. default:
  8079. return true;
  8080. }
  8081. }
  8082. }
  8083. module.exports = NvPicPrXform;
  8084. },{"../base-xform":32,"./c-nv-pic-pr-xform":59,"./c-nv-pr-xform":60}],67:[function(require,module,exports){
  8085. "use strict";
  8086. const BaseCellAnchorXform = require('./base-cell-anchor-xform');
  8087. const StaticXform = require('../static-xform');
  8088. const CellPositionXform = require('./cell-position-xform');
  8089. const ExtXform = require('./ext-xform');
  8090. const PicXform = require('./pic-xform');
  8091. class OneCellAnchorXform extends BaseCellAnchorXform {
  8092. constructor() {
  8093. super();
  8094. this.map = {
  8095. 'xdr:from': new CellPositionXform({
  8096. tag: 'xdr:from'
  8097. }),
  8098. 'xdr:ext': new ExtXform({
  8099. tag: 'xdr:ext'
  8100. }),
  8101. 'xdr:pic': new PicXform(),
  8102. 'xdr:clientData': new StaticXform({
  8103. tag: 'xdr:clientData'
  8104. })
  8105. };
  8106. }
  8107. get tag() {
  8108. return 'xdr:oneCellAnchor';
  8109. }
  8110. prepare(model, options) {
  8111. this.map['xdr:pic'].prepare(model.picture, options);
  8112. }
  8113. render(xmlStream, model) {
  8114. xmlStream.openNode(this.tag, {
  8115. editAs: model.range.editAs || 'oneCell'
  8116. });
  8117. this.map['xdr:from'].render(xmlStream, model.range.tl);
  8118. this.map['xdr:ext'].render(xmlStream, model.range.ext);
  8119. this.map['xdr:pic'].render(xmlStream, model.picture);
  8120. this.map['xdr:clientData'].render(xmlStream, {});
  8121. xmlStream.closeNode();
  8122. }
  8123. parseClose(name) {
  8124. if (this.parser) {
  8125. if (!this.parser.parseClose(name)) {
  8126. this.parser = undefined;
  8127. }
  8128. return true;
  8129. }
  8130. switch (name) {
  8131. case this.tag:
  8132. this.model.range.tl = this.map['xdr:from'].model;
  8133. this.model.range.ext = this.map['xdr:ext'].model;
  8134. this.model.picture = this.map['xdr:pic'].model;
  8135. return false;
  8136. default:
  8137. // could be some unrecognised tags
  8138. return true;
  8139. }
  8140. }
  8141. reconcile(model, options) {
  8142. model.medium = this.reconcilePicture(model.picture, options);
  8143. }
  8144. }
  8145. module.exports = OneCellAnchorXform;
  8146. },{"../static-xform":120,"./base-cell-anchor-xform":56,"./cell-position-xform":61,"./ext-xform":64,"./pic-xform":68}],68:[function(require,module,exports){
  8147. "use strict";
  8148. const BaseXform = require('../base-xform');
  8149. const StaticXform = require('../static-xform');
  8150. const BlipFillXform = require('./blip-fill-xform');
  8151. const NvPicPrXform = require('./nv-pic-pr-xform');
  8152. const spPrJSON = require('./sp-pr');
  8153. class PicXform extends BaseXform {
  8154. constructor() {
  8155. super();
  8156. this.map = {
  8157. 'xdr:nvPicPr': new NvPicPrXform(),
  8158. 'xdr:blipFill': new BlipFillXform(),
  8159. 'xdr:spPr': new StaticXform(spPrJSON)
  8160. };
  8161. }
  8162. get tag() {
  8163. return 'xdr:pic';
  8164. }
  8165. prepare(model, options) {
  8166. model.index = options.index + 1;
  8167. }
  8168. render(xmlStream, model) {
  8169. xmlStream.openNode(this.tag);
  8170. this.map['xdr:nvPicPr'].render(xmlStream, model);
  8171. this.map['xdr:blipFill'].render(xmlStream, model);
  8172. this.map['xdr:spPr'].render(xmlStream, model);
  8173. xmlStream.closeNode();
  8174. }
  8175. parseOpen(node) {
  8176. if (this.parser) {
  8177. this.parser.parseOpen(node);
  8178. return true;
  8179. }
  8180. switch (node.name) {
  8181. case this.tag:
  8182. this.reset();
  8183. break;
  8184. default:
  8185. this.parser = this.map[node.name];
  8186. if (this.parser) {
  8187. this.parser.parseOpen(node);
  8188. }
  8189. break;
  8190. }
  8191. return true;
  8192. }
  8193. parseText() {}
  8194. parseClose(name) {
  8195. if (this.parser) {
  8196. if (!this.parser.parseClose(name)) {
  8197. this.mergeModel(this.parser.model);
  8198. this.parser = undefined;
  8199. }
  8200. return true;
  8201. }
  8202. switch (name) {
  8203. case this.tag:
  8204. return false;
  8205. default:
  8206. // not quite sure how we get here!
  8207. return true;
  8208. }
  8209. }
  8210. }
  8211. module.exports = PicXform;
  8212. },{"../base-xform":32,"../static-xform":120,"./blip-fill-xform":57,"./nv-pic-pr-xform":66,"./sp-pr":69}],69:[function(require,module,exports){
  8213. "use strict";
  8214. module.exports = {
  8215. tag: 'xdr:spPr',
  8216. c: [{
  8217. tag: 'a:xfrm',
  8218. c: [{
  8219. tag: 'a:off',
  8220. $: {
  8221. x: '0',
  8222. y: '0'
  8223. }
  8224. }, {
  8225. tag: 'a:ext',
  8226. $: {
  8227. cx: '0',
  8228. cy: '0'
  8229. }
  8230. }]
  8231. }, {
  8232. tag: 'a:prstGeom',
  8233. $: {
  8234. prst: 'rect'
  8235. },
  8236. c: [{
  8237. tag: 'a:avLst'
  8238. }]
  8239. }]
  8240. };
  8241. },{}],70:[function(require,module,exports){
  8242. "use strict";
  8243. const BaseCellAnchorXform = require('./base-cell-anchor-xform');
  8244. const StaticXform = require('../static-xform');
  8245. const CellPositionXform = require('./cell-position-xform');
  8246. const PicXform = require('./pic-xform');
  8247. class TwoCellAnchorXform extends BaseCellAnchorXform {
  8248. constructor() {
  8249. super();
  8250. this.map = {
  8251. 'xdr:from': new CellPositionXform({
  8252. tag: 'xdr:from'
  8253. }),
  8254. 'xdr:to': new CellPositionXform({
  8255. tag: 'xdr:to'
  8256. }),
  8257. 'xdr:pic': new PicXform(),
  8258. 'xdr:clientData': new StaticXform({
  8259. tag: 'xdr:clientData'
  8260. })
  8261. };
  8262. }
  8263. get tag() {
  8264. return 'xdr:twoCellAnchor';
  8265. }
  8266. prepare(model, options) {
  8267. this.map['xdr:pic'].prepare(model.picture, options);
  8268. }
  8269. render(xmlStream, model) {
  8270. xmlStream.openNode(this.tag, {
  8271. editAs: model.range.editAs || 'oneCell'
  8272. });
  8273. this.map['xdr:from'].render(xmlStream, model.range.tl);
  8274. this.map['xdr:to'].render(xmlStream, model.range.br);
  8275. this.map['xdr:pic'].render(xmlStream, model.picture);
  8276. this.map['xdr:clientData'].render(xmlStream, {});
  8277. xmlStream.closeNode();
  8278. }
  8279. parseClose(name) {
  8280. if (this.parser) {
  8281. if (!this.parser.parseClose(name)) {
  8282. this.parser = undefined;
  8283. }
  8284. return true;
  8285. }
  8286. switch (name) {
  8287. case this.tag:
  8288. this.model.range.tl = this.map['xdr:from'].model;
  8289. this.model.range.br = this.map['xdr:to'].model;
  8290. this.model.picture = this.map['xdr:pic'].model;
  8291. return false;
  8292. default:
  8293. // could be some unrecognised tags
  8294. return true;
  8295. }
  8296. }
  8297. reconcile(model, options) {
  8298. model.medium = this.reconcilePicture(model.picture, options);
  8299. }
  8300. }
  8301. module.exports = TwoCellAnchorXform;
  8302. },{"../static-xform":120,"./base-cell-anchor-xform":56,"./cell-position-xform":61,"./pic-xform":68}],71:[function(require,module,exports){
  8303. "use strict";
  8304. const BaseXform = require('./base-xform');
  8305. class ListXform extends BaseXform {
  8306. constructor(options) {
  8307. super();
  8308. this.tag = options.tag;
  8309. this.always = !!options.always;
  8310. this.count = options.count;
  8311. this.empty = options.empty;
  8312. this.$count = options.$count || 'count';
  8313. this.$ = options.$;
  8314. this.childXform = options.childXform;
  8315. this.maxItems = options.maxItems;
  8316. }
  8317. prepare(model, options) {
  8318. const {
  8319. childXform
  8320. } = this;
  8321. if (model) {
  8322. model.forEach((childModel, index) => {
  8323. options.index = index;
  8324. childXform.prepare(childModel, options);
  8325. });
  8326. }
  8327. }
  8328. render(xmlStream, model) {
  8329. if (this.always || model && model.length) {
  8330. xmlStream.openNode(this.tag, this.$);
  8331. if (this.count) {
  8332. xmlStream.addAttribute(this.$count, model && model.length || 0);
  8333. }
  8334. const {
  8335. childXform
  8336. } = this;
  8337. (model || []).forEach((childModel, index) => {
  8338. childXform.render(xmlStream, childModel, index);
  8339. });
  8340. xmlStream.closeNode();
  8341. } else if (this.empty) {
  8342. xmlStream.leafNode(this.tag);
  8343. }
  8344. }
  8345. parseOpen(node) {
  8346. if (this.parser) {
  8347. this.parser.parseOpen(node);
  8348. return true;
  8349. }
  8350. switch (node.name) {
  8351. case this.tag:
  8352. this.model = [];
  8353. return true;
  8354. default:
  8355. if (this.childXform.parseOpen(node)) {
  8356. this.parser = this.childXform;
  8357. return true;
  8358. }
  8359. return false;
  8360. }
  8361. }
  8362. parseText(text) {
  8363. if (this.parser) {
  8364. this.parser.parseText(text);
  8365. }
  8366. }
  8367. parseClose(name) {
  8368. if (this.parser) {
  8369. if (!this.parser.parseClose(name)) {
  8370. this.model.push(this.parser.model);
  8371. this.parser = undefined;
  8372. if (this.maxItems && this.model.length > this.maxItems) {
  8373. throw new Error(`Max ${this.childXform.tag} count (${this.maxItems}) exceeded`);
  8374. }
  8375. }
  8376. return true;
  8377. }
  8378. return false;
  8379. }
  8380. reconcile(model, options) {
  8381. if (model) {
  8382. const {
  8383. childXform
  8384. } = this;
  8385. model.forEach(childModel => {
  8386. childXform.reconcile(childModel, options);
  8387. });
  8388. }
  8389. }
  8390. }
  8391. module.exports = ListXform;
  8392. },{"./base-xform":32}],72:[function(require,module,exports){
  8393. "use strict";
  8394. const colCache = require('../../../utils/col-cache');
  8395. const BaseXform = require('../base-xform');
  8396. class AutoFilterXform extends BaseXform {
  8397. get tag() {
  8398. return 'autoFilter';
  8399. }
  8400. render(xmlStream, model) {
  8401. if (model) {
  8402. if (typeof model === 'string') {
  8403. // assume range
  8404. xmlStream.leafNode('autoFilter', {
  8405. ref: model
  8406. });
  8407. } else {
  8408. const getAddress = function (addr) {
  8409. if (typeof addr === 'string') {
  8410. return addr;
  8411. }
  8412. return colCache.getAddress(addr.row, addr.column).address;
  8413. };
  8414. const firstAddress = getAddress(model.from);
  8415. const secondAddress = getAddress(model.to);
  8416. if (firstAddress && secondAddress) {
  8417. xmlStream.leafNode('autoFilter', {
  8418. ref: `${firstAddress}:${secondAddress}`
  8419. });
  8420. }
  8421. }
  8422. }
  8423. }
  8424. parseOpen(node) {
  8425. if (node.name === 'autoFilter') {
  8426. this.model = node.attributes.ref;
  8427. }
  8428. }
  8429. }
  8430. module.exports = AutoFilterXform;
  8431. },{"../../../utils/col-cache":19,"../base-xform":32}],73:[function(require,module,exports){
  8432. "use strict";
  8433. const utils = require('../../../utils/utils');
  8434. const BaseXform = require('../base-xform');
  8435. const Range = require('../../../doc/range');
  8436. const Enums = require('../../../doc/enums');
  8437. const RichTextXform = require('../strings/rich-text-xform');
  8438. function getValueType(v) {
  8439. if (v === null || v === undefined) {
  8440. return Enums.ValueType.Null;
  8441. }
  8442. if (v instanceof String || typeof v === 'string') {
  8443. return Enums.ValueType.String;
  8444. }
  8445. if (typeof v === 'number') {
  8446. return Enums.ValueType.Number;
  8447. }
  8448. if (typeof v === 'boolean') {
  8449. return Enums.ValueType.Boolean;
  8450. }
  8451. if (v instanceof Date) {
  8452. return Enums.ValueType.Date;
  8453. }
  8454. if (v.text && v.hyperlink) {
  8455. return Enums.ValueType.Hyperlink;
  8456. }
  8457. if (v.formula) {
  8458. return Enums.ValueType.Formula;
  8459. }
  8460. if (v.error) {
  8461. return Enums.ValueType.Error;
  8462. }
  8463. throw new Error('I could not understand type of value');
  8464. }
  8465. function getEffectiveCellType(cell) {
  8466. switch (cell.type) {
  8467. case Enums.ValueType.Formula:
  8468. return getValueType(cell.result);
  8469. default:
  8470. return cell.type;
  8471. }
  8472. }
  8473. class CellXform extends BaseXform {
  8474. constructor() {
  8475. super();
  8476. this.richTextXForm = new RichTextXform();
  8477. }
  8478. get tag() {
  8479. return 'c';
  8480. }
  8481. prepare(model, options) {
  8482. const styleId = options.styles.addStyleModel(model.style || {}, getEffectiveCellType(model));
  8483. if (styleId) {
  8484. model.styleId = styleId;
  8485. }
  8486. if (model.comment) {
  8487. options.comments.push({
  8488. ...model.comment,
  8489. ref: model.address
  8490. });
  8491. }
  8492. switch (model.type) {
  8493. case Enums.ValueType.String:
  8494. case Enums.ValueType.RichText:
  8495. if (options.sharedStrings) {
  8496. model.ssId = options.sharedStrings.add(model.value);
  8497. }
  8498. break;
  8499. case Enums.ValueType.Date:
  8500. if (options.date1904) {
  8501. model.date1904 = true;
  8502. }
  8503. break;
  8504. case Enums.ValueType.Hyperlink:
  8505. if (options.sharedStrings && model.text !== undefined && model.text !== null) {
  8506. model.ssId = options.sharedStrings.add(model.text);
  8507. }
  8508. options.hyperlinks.push({
  8509. address: model.address,
  8510. target: model.hyperlink,
  8511. tooltip: model.tooltip
  8512. });
  8513. break;
  8514. case Enums.ValueType.Merge:
  8515. options.merges.add(model);
  8516. break;
  8517. case Enums.ValueType.Formula:
  8518. if (options.date1904) {
  8519. // in case valueType is date
  8520. model.date1904 = true;
  8521. }
  8522. if (model.shareType === 'shared') {
  8523. model.si = options.siFormulae++;
  8524. }
  8525. if (model.formula) {
  8526. options.formulae[model.address] = model;
  8527. } else if (model.sharedFormula) {
  8528. const master = options.formulae[model.sharedFormula];
  8529. if (!master) {
  8530. throw new Error(`Shared Formula master must exist above and or left of clone for cell ${model.address}`);
  8531. }
  8532. if (master.si === undefined) {
  8533. master.shareType = 'shared';
  8534. master.si = options.siFormulae++;
  8535. master.range = new Range(master.address, model.address);
  8536. } else if (master.range) {
  8537. master.range.expandToAddress(model.address);
  8538. }
  8539. model.si = master.si;
  8540. }
  8541. break;
  8542. default:
  8543. break;
  8544. }
  8545. }
  8546. renderFormula(xmlStream, model) {
  8547. let attrs = null;
  8548. switch (model.shareType) {
  8549. case 'shared':
  8550. attrs = {
  8551. t: 'shared',
  8552. ref: model.ref || model.range.range,
  8553. si: model.si
  8554. };
  8555. break;
  8556. case 'array':
  8557. attrs = {
  8558. t: 'array',
  8559. ref: model.ref
  8560. };
  8561. break;
  8562. default:
  8563. if (model.si !== undefined) {
  8564. attrs = {
  8565. t: 'shared',
  8566. si: model.si
  8567. };
  8568. }
  8569. break;
  8570. }
  8571. switch (getValueType(model.result)) {
  8572. case Enums.ValueType.Null:
  8573. // ?
  8574. xmlStream.leafNode('f', attrs, model.formula);
  8575. break;
  8576. case Enums.ValueType.String:
  8577. // oddly, formula results don't ever use shared strings
  8578. xmlStream.addAttribute('t', 'str');
  8579. xmlStream.leafNode('f', attrs, model.formula);
  8580. xmlStream.leafNode('v', null, model.result);
  8581. break;
  8582. case Enums.ValueType.Number:
  8583. xmlStream.leafNode('f', attrs, model.formula);
  8584. xmlStream.leafNode('v', null, model.result);
  8585. break;
  8586. case Enums.ValueType.Boolean:
  8587. xmlStream.addAttribute('t', 'b');
  8588. xmlStream.leafNode('f', attrs, model.formula);
  8589. xmlStream.leafNode('v', null, model.result ? 1 : 0);
  8590. break;
  8591. case Enums.ValueType.Error:
  8592. xmlStream.addAttribute('t', 'e');
  8593. xmlStream.leafNode('f', attrs, model.formula);
  8594. xmlStream.leafNode('v', null, model.result.error);
  8595. break;
  8596. case Enums.ValueType.Date:
  8597. xmlStream.leafNode('f', attrs, model.formula);
  8598. xmlStream.leafNode('v', null, utils.dateToExcel(model.result, model.date1904));
  8599. break;
  8600. // case Enums.ValueType.Hyperlink: // ??
  8601. // case Enums.ValueType.Formula:
  8602. default:
  8603. throw new Error('I could not understand type of value');
  8604. }
  8605. }
  8606. render(xmlStream, model) {
  8607. if (model.type === Enums.ValueType.Null && !model.styleId) {
  8608. // if null and no style, exit
  8609. return;
  8610. }
  8611. xmlStream.openNode('c');
  8612. xmlStream.addAttribute('r', model.address);
  8613. if (model.styleId) {
  8614. xmlStream.addAttribute('s', model.styleId);
  8615. }
  8616. switch (model.type) {
  8617. case Enums.ValueType.Null:
  8618. break;
  8619. case Enums.ValueType.Number:
  8620. xmlStream.leafNode('v', null, model.value);
  8621. break;
  8622. case Enums.ValueType.Boolean:
  8623. xmlStream.addAttribute('t', 'b');
  8624. xmlStream.leafNode('v', null, model.value ? '1' : '0');
  8625. break;
  8626. case Enums.ValueType.Error:
  8627. xmlStream.addAttribute('t', 'e');
  8628. xmlStream.leafNode('v', null, model.value.error);
  8629. break;
  8630. case Enums.ValueType.String:
  8631. case Enums.ValueType.RichText:
  8632. if (model.ssId !== undefined) {
  8633. xmlStream.addAttribute('t', 's');
  8634. xmlStream.leafNode('v', null, model.ssId);
  8635. } else if (model.value && model.value.richText) {
  8636. xmlStream.addAttribute('t', 'inlineStr');
  8637. xmlStream.openNode('is');
  8638. model.value.richText.forEach(text => {
  8639. this.richTextXForm.render(xmlStream, text);
  8640. });
  8641. xmlStream.closeNode('is');
  8642. } else {
  8643. xmlStream.addAttribute('t', 'str');
  8644. xmlStream.leafNode('v', null, model.value);
  8645. }
  8646. break;
  8647. case Enums.ValueType.Date:
  8648. xmlStream.leafNode('v', null, utils.dateToExcel(model.value, model.date1904));
  8649. break;
  8650. case Enums.ValueType.Hyperlink:
  8651. if (model.ssId !== undefined) {
  8652. xmlStream.addAttribute('t', 's');
  8653. xmlStream.leafNode('v', null, model.ssId);
  8654. } else {
  8655. xmlStream.addAttribute('t', 'str');
  8656. xmlStream.leafNode('v', null, model.text);
  8657. }
  8658. break;
  8659. case Enums.ValueType.Formula:
  8660. this.renderFormula(xmlStream, model);
  8661. break;
  8662. case Enums.ValueType.Merge:
  8663. // nothing to add
  8664. break;
  8665. default:
  8666. break;
  8667. }
  8668. xmlStream.closeNode(); // </c>
  8669. }
  8670. parseOpen(node) {
  8671. if (this.parser) {
  8672. this.parser.parseOpen(node);
  8673. return true;
  8674. }
  8675. switch (node.name) {
  8676. case 'c':
  8677. // const address = colCache.decodeAddress(node.attributes.r);
  8678. this.model = {
  8679. address: node.attributes.r
  8680. };
  8681. this.t = node.attributes.t;
  8682. if (node.attributes.s) {
  8683. this.model.styleId = parseInt(node.attributes.s, 10);
  8684. }
  8685. return true;
  8686. case 'f':
  8687. this.currentNode = 'f';
  8688. this.model.si = node.attributes.si;
  8689. this.model.shareType = node.attributes.t;
  8690. this.model.ref = node.attributes.ref;
  8691. return true;
  8692. case 'v':
  8693. this.currentNode = 'v';
  8694. return true;
  8695. case 't':
  8696. this.currentNode = 't';
  8697. return true;
  8698. case 'r':
  8699. this.parser = this.richTextXForm;
  8700. this.parser.parseOpen(node);
  8701. return true;
  8702. default:
  8703. return false;
  8704. }
  8705. }
  8706. parseText(text) {
  8707. if (this.parser) {
  8708. this.parser.parseText(text);
  8709. return;
  8710. }
  8711. switch (this.currentNode) {
  8712. case 'f':
  8713. this.model.formula = this.model.formula ? this.model.formula + text : text;
  8714. break;
  8715. case 'v':
  8716. case 't':
  8717. if (this.model.value && this.model.value.richText) {
  8718. this.model.value.richText.text = this.model.value.richText.text ? this.model.value.richText.text + text : text;
  8719. } else {
  8720. this.model.value = this.model.value ? this.model.value + text : text;
  8721. }
  8722. break;
  8723. default:
  8724. break;
  8725. }
  8726. }
  8727. parseClose(name) {
  8728. switch (name) {
  8729. case 'c':
  8730. {
  8731. const {
  8732. model
  8733. } = this;
  8734. // first guess on cell type
  8735. if (model.formula || model.shareType) {
  8736. model.type = Enums.ValueType.Formula;
  8737. if (model.value) {
  8738. if (this.t === 'str') {
  8739. model.result = utils.xmlDecode(model.value);
  8740. } else if (this.t === 'b') {
  8741. model.result = parseInt(model.value, 10) !== 0;
  8742. } else if (this.t === 'e') {
  8743. model.result = {
  8744. error: model.value
  8745. };
  8746. } else {
  8747. model.result = parseFloat(model.value);
  8748. }
  8749. model.value = undefined;
  8750. }
  8751. } else if (model.value !== undefined) {
  8752. switch (this.t) {
  8753. case 's':
  8754. model.type = Enums.ValueType.String;
  8755. model.value = parseInt(model.value, 10);
  8756. break;
  8757. case 'str':
  8758. model.type = Enums.ValueType.String;
  8759. model.value = utils.xmlDecode(model.value);
  8760. break;
  8761. case 'inlineStr':
  8762. model.type = Enums.ValueType.String;
  8763. break;
  8764. case 'b':
  8765. model.type = Enums.ValueType.Boolean;
  8766. model.value = parseInt(model.value, 10) !== 0;
  8767. break;
  8768. case 'e':
  8769. model.type = Enums.ValueType.Error;
  8770. model.value = {
  8771. error: model.value
  8772. };
  8773. break;
  8774. default:
  8775. model.type = Enums.ValueType.Number;
  8776. model.value = parseFloat(model.value);
  8777. break;
  8778. }
  8779. } else if (model.styleId) {
  8780. model.type = Enums.ValueType.Null;
  8781. } else {
  8782. model.type = Enums.ValueType.Merge;
  8783. }
  8784. return false;
  8785. }
  8786. case 'f':
  8787. case 'v':
  8788. case 'is':
  8789. this.currentNode = undefined;
  8790. return true;
  8791. case 't':
  8792. if (this.parser) {
  8793. this.parser.parseClose(name);
  8794. return true;
  8795. }
  8796. this.currentNode = undefined;
  8797. return true;
  8798. case 'r':
  8799. this.model.value = this.model.value || {};
  8800. this.model.value.richText = this.model.value.richText || [];
  8801. this.model.value.richText.push(this.parser.model);
  8802. this.parser = undefined;
  8803. this.currentNode = undefined;
  8804. return true;
  8805. default:
  8806. if (this.parser) {
  8807. this.parser.parseClose(name);
  8808. return true;
  8809. }
  8810. return false;
  8811. }
  8812. }
  8813. reconcile(model, options) {
  8814. const style = model.styleId && options.styles && options.styles.getStyleModel(model.styleId);
  8815. if (style) {
  8816. model.style = style;
  8817. }
  8818. if (model.styleId !== undefined) {
  8819. model.styleId = undefined;
  8820. }
  8821. switch (model.type) {
  8822. case Enums.ValueType.String:
  8823. if (typeof model.value === 'number') {
  8824. if (options.sharedStrings) {
  8825. model.value = options.sharedStrings.getString(model.value);
  8826. }
  8827. }
  8828. if (model.value.richText) {
  8829. model.type = Enums.ValueType.RichText;
  8830. }
  8831. break;
  8832. case Enums.ValueType.Number:
  8833. if (style && utils.isDateFmt(style.numFmt)) {
  8834. model.type = Enums.ValueType.Date;
  8835. model.value = utils.excelToDate(model.value, options.date1904);
  8836. }
  8837. break;
  8838. case Enums.ValueType.Formula:
  8839. if (model.result !== undefined && style && utils.isDateFmt(style.numFmt)) {
  8840. model.result = utils.excelToDate(model.result, options.date1904);
  8841. }
  8842. if (model.shareType === 'shared') {
  8843. if (model.ref) {
  8844. // master
  8845. options.formulae[model.si] = model.address;
  8846. } else {
  8847. // slave
  8848. model.sharedFormula = options.formulae[model.si];
  8849. delete model.shareType;
  8850. }
  8851. delete model.si;
  8852. }
  8853. break;
  8854. default:
  8855. break;
  8856. }
  8857. // look for hyperlink
  8858. const hyperlink = options.hyperlinkMap[model.address];
  8859. if (hyperlink) {
  8860. if (model.type === Enums.ValueType.Formula) {
  8861. model.text = model.result;
  8862. model.result = undefined;
  8863. } else {
  8864. model.text = model.value;
  8865. model.value = undefined;
  8866. }
  8867. model.type = Enums.ValueType.Hyperlink;
  8868. model.hyperlink = hyperlink;
  8869. }
  8870. const comment = options.commentsMap && options.commentsMap[model.address];
  8871. if (comment) {
  8872. model.comment = comment;
  8873. }
  8874. }
  8875. }
  8876. module.exports = CellXform;
  8877. },{"../../../doc/enums":7,"../../../doc/range":10,"../../../utils/utils":27,"../base-xform":32,"../strings/rich-text-xform":122}],74:[function(require,module,exports){
  8878. "use strict";
  8879. const BaseXform = require('../../base-xform');
  8880. class CfIconExtXform extends BaseXform {
  8881. get tag() {
  8882. return 'x14:cfIcon';
  8883. }
  8884. render(xmlStream, model) {
  8885. xmlStream.leafNode(this.tag, {
  8886. iconSet: model.iconSet,
  8887. iconId: model.iconId
  8888. });
  8889. }
  8890. parseOpen(_ref) {
  8891. let {
  8892. attributes
  8893. } = _ref;
  8894. this.model = {
  8895. iconSet: attributes.iconSet,
  8896. iconId: BaseXform.toIntValue(attributes.iconId)
  8897. };
  8898. }
  8899. parseClose(name) {
  8900. return name !== this.tag;
  8901. }
  8902. }
  8903. module.exports = CfIconExtXform;
  8904. },{"../../base-xform":32}],75:[function(require,module,exports){
  8905. "use strict";
  8906. const {
  8907. v4: uuidv4
  8908. } = require('uuid');
  8909. const BaseXform = require('../../base-xform');
  8910. const CompositeXform = require('../../composite-xform');
  8911. const DatabarExtXform = require('./databar-ext-xform');
  8912. const IconSetExtXform = require('./icon-set-ext-xform');
  8913. const extIcons = {
  8914. '3Triangles': true,
  8915. '3Stars': true,
  8916. '5Boxes': true
  8917. };
  8918. class CfRuleExtXform extends CompositeXform {
  8919. constructor() {
  8920. super();
  8921. this.map = {
  8922. 'x14:dataBar': this.databarXform = new DatabarExtXform(),
  8923. 'x14:iconSet': this.iconSetXform = new IconSetExtXform()
  8924. };
  8925. }
  8926. get tag() {
  8927. return 'x14:cfRule';
  8928. }
  8929. static isExt(rule) {
  8930. // is this rule primitive?
  8931. if (rule.type === 'dataBar') {
  8932. return DatabarExtXform.isExt(rule);
  8933. }
  8934. if (rule.type === 'iconSet') {
  8935. if (rule.custom || extIcons[rule.iconSet]) {
  8936. return true;
  8937. }
  8938. }
  8939. return false;
  8940. }
  8941. prepare(model) {
  8942. if (CfRuleExtXform.isExt(model)) {
  8943. model.x14Id = `{${uuidv4()}}`.toUpperCase();
  8944. }
  8945. }
  8946. render(xmlStream, model) {
  8947. if (!CfRuleExtXform.isExt(model)) {
  8948. return;
  8949. }
  8950. switch (model.type) {
  8951. case 'dataBar':
  8952. this.renderDataBar(xmlStream, model);
  8953. break;
  8954. case 'iconSet':
  8955. this.renderIconSet(xmlStream, model);
  8956. break;
  8957. }
  8958. }
  8959. renderDataBar(xmlStream, model) {
  8960. xmlStream.openNode(this.tag, {
  8961. type: 'dataBar',
  8962. id: model.x14Id
  8963. });
  8964. this.databarXform.render(xmlStream, model);
  8965. xmlStream.closeNode();
  8966. }
  8967. renderIconSet(xmlStream, model) {
  8968. xmlStream.openNode(this.tag, {
  8969. type: 'iconSet',
  8970. priority: model.priority,
  8971. id: model.x14Id || `{${uuidv4()}}`
  8972. });
  8973. this.iconSetXform.render(xmlStream, model);
  8974. xmlStream.closeNode();
  8975. }
  8976. createNewModel(_ref) {
  8977. let {
  8978. attributes
  8979. } = _ref;
  8980. return {
  8981. type: attributes.type,
  8982. x14Id: attributes.id,
  8983. priority: BaseXform.toIntValue(attributes.priority)
  8984. };
  8985. }
  8986. onParserClose(name, parser) {
  8987. Object.assign(this.model, parser.model);
  8988. }
  8989. }
  8990. module.exports = CfRuleExtXform;
  8991. },{"../../base-xform":32,"../../composite-xform":48,"./databar-ext-xform":79,"./icon-set-ext-xform":81,"uuid":528}],76:[function(require,module,exports){
  8992. "use strict";
  8993. const CompositeXform = require('../../composite-xform');
  8994. const FExtXform = require('./f-ext-xform');
  8995. class CfvoExtXform extends CompositeXform {
  8996. constructor() {
  8997. super();
  8998. this.map = {
  8999. 'xm:f': this.fExtXform = new FExtXform()
  9000. };
  9001. }
  9002. get tag() {
  9003. return 'x14:cfvo';
  9004. }
  9005. render(xmlStream, model) {
  9006. xmlStream.openNode(this.tag, {
  9007. type: model.type
  9008. });
  9009. if (model.value !== undefined) {
  9010. this.fExtXform.render(xmlStream, model.value);
  9011. }
  9012. xmlStream.closeNode();
  9013. }
  9014. createNewModel(node) {
  9015. return {
  9016. type: node.attributes.type
  9017. };
  9018. }
  9019. onParserClose(name, parser) {
  9020. switch (name) {
  9021. case 'xm:f':
  9022. this.model.value = parser.model ? parseFloat(parser.model) : 0;
  9023. break;
  9024. }
  9025. }
  9026. }
  9027. module.exports = CfvoExtXform;
  9028. },{"../../composite-xform":48,"./f-ext-xform":80}],77:[function(require,module,exports){
  9029. "use strict";
  9030. const CompositeXform = require('../../composite-xform');
  9031. const SqRefExtXform = require('./sqref-ext-xform');
  9032. const CfRuleExtXform = require('./cf-rule-ext-xform');
  9033. class ConditionalFormattingExtXform extends CompositeXform {
  9034. constructor() {
  9035. super();
  9036. this.map = {
  9037. 'xm:sqref': this.sqRef = new SqRefExtXform(),
  9038. 'x14:cfRule': this.cfRule = new CfRuleExtXform()
  9039. };
  9040. }
  9041. get tag() {
  9042. return 'x14:conditionalFormatting';
  9043. }
  9044. prepare(model, options) {
  9045. model.rules.forEach(rule => {
  9046. this.cfRule.prepare(rule, options);
  9047. });
  9048. }
  9049. render(xmlStream, model) {
  9050. if (!model.rules.some(CfRuleExtXform.isExt)) {
  9051. return;
  9052. }
  9053. xmlStream.openNode(this.tag, {
  9054. 'xmlns:xm': 'http://schemas.microsoft.com/office/excel/2006/main'
  9055. });
  9056. model.rules.filter(CfRuleExtXform.isExt).forEach(rule => this.cfRule.render(xmlStream, rule));
  9057. // for some odd reason, Excel needs the <xm:sqref> node to be after the rules
  9058. this.sqRef.render(xmlStream, model.ref);
  9059. xmlStream.closeNode();
  9060. }
  9061. createNewModel() {
  9062. return {
  9063. rules: []
  9064. };
  9065. }
  9066. onParserClose(name, parser) {
  9067. switch (name) {
  9068. case 'xm:sqref':
  9069. this.model.ref = parser.model;
  9070. break;
  9071. case 'x14:cfRule':
  9072. this.model.rules.push(parser.model);
  9073. break;
  9074. }
  9075. }
  9076. }
  9077. module.exports = ConditionalFormattingExtXform;
  9078. },{"../../composite-xform":48,"./cf-rule-ext-xform":75,"./sqref-ext-xform":82}],78:[function(require,module,exports){
  9079. "use strict";
  9080. const CompositeXform = require('../../composite-xform');
  9081. const CfRuleExtXform = require('./cf-rule-ext-xform');
  9082. const ConditionalFormattingExtXform = require('./conditional-formatting-ext-xform');
  9083. class ConditionalFormattingsExtXform extends CompositeXform {
  9084. constructor() {
  9085. super();
  9086. this.map = {
  9087. 'x14:conditionalFormatting': this.cfXform = new ConditionalFormattingExtXform()
  9088. };
  9089. }
  9090. get tag() {
  9091. return 'x14:conditionalFormattings';
  9092. }
  9093. hasContent(model) {
  9094. if (model.hasExtContent === undefined) {
  9095. model.hasExtContent = model.some(cf => cf.rules.some(CfRuleExtXform.isExt));
  9096. }
  9097. return model.hasExtContent;
  9098. }
  9099. prepare(model, options) {
  9100. model.forEach(cf => {
  9101. this.cfXform.prepare(cf, options);
  9102. });
  9103. }
  9104. render(xmlStream, model) {
  9105. if (this.hasContent(model)) {
  9106. xmlStream.openNode(this.tag);
  9107. model.forEach(cf => this.cfXform.render(xmlStream, cf));
  9108. xmlStream.closeNode();
  9109. }
  9110. }
  9111. createNewModel() {
  9112. return [];
  9113. }
  9114. onParserClose(name, parser) {
  9115. // model is array of conditional formatting objects
  9116. this.model.push(parser.model);
  9117. }
  9118. }
  9119. module.exports = ConditionalFormattingsExtXform;
  9120. },{"../../composite-xform":48,"./cf-rule-ext-xform":75,"./conditional-formatting-ext-xform":77}],79:[function(require,module,exports){
  9121. "use strict";
  9122. const BaseXform = require('../../base-xform');
  9123. const CompositeXform = require('../../composite-xform');
  9124. const ColorXform = require('../../style/color-xform');
  9125. const CfvoExtXform = require('./cfvo-ext-xform');
  9126. class DatabarExtXform extends CompositeXform {
  9127. constructor() {
  9128. super();
  9129. this.map = {
  9130. 'x14:cfvo': this.cfvoXform = new CfvoExtXform(),
  9131. 'x14:borderColor': this.borderColorXform = new ColorXform('x14:borderColor'),
  9132. 'x14:negativeBorderColor': this.negativeBorderColorXform = new ColorXform('x14:negativeBorderColor'),
  9133. 'x14:negativeFillColor': this.negativeFillColorXform = new ColorXform('x14:negativeFillColor'),
  9134. 'x14:axisColor': this.axisColorXform = new ColorXform('x14:axisColor')
  9135. };
  9136. }
  9137. static isExt(rule) {
  9138. // not all databars need ext
  9139. // TODO: refine this
  9140. return !rule.gradient;
  9141. }
  9142. get tag() {
  9143. return 'x14:dataBar';
  9144. }
  9145. render(xmlStream, model) {
  9146. xmlStream.openNode(this.tag, {
  9147. minLength: BaseXform.toIntAttribute(model.minLength, 0, true),
  9148. maxLength: BaseXform.toIntAttribute(model.maxLength, 100, true),
  9149. border: BaseXform.toBoolAttribute(model.border, false),
  9150. gradient: BaseXform.toBoolAttribute(model.gradient, true),
  9151. negativeBarColorSameAsPositive: BaseXform.toBoolAttribute(model.negativeBarColorSameAsPositive, true),
  9152. negativeBarBorderColorSameAsPositive: BaseXform.toBoolAttribute(model.negativeBarBorderColorSameAsPositive, true),
  9153. axisPosition: BaseXform.toAttribute(model.axisPosition, 'auto'),
  9154. direction: BaseXform.toAttribute(model.direction, 'leftToRight')
  9155. });
  9156. model.cfvo.forEach(cfvo => {
  9157. this.cfvoXform.render(xmlStream, cfvo);
  9158. });
  9159. this.borderColorXform.render(xmlStream, model.borderColor);
  9160. this.negativeBorderColorXform.render(xmlStream, model.negativeBorderColor);
  9161. this.negativeFillColorXform.render(xmlStream, model.negativeFillColor);
  9162. this.axisColorXform.render(xmlStream, model.axisColor);
  9163. xmlStream.closeNode();
  9164. }
  9165. createNewModel(_ref) {
  9166. let {
  9167. attributes
  9168. } = _ref;
  9169. return {
  9170. cfvo: [],
  9171. minLength: BaseXform.toIntValue(attributes.minLength, 0),
  9172. maxLength: BaseXform.toIntValue(attributes.maxLength, 100),
  9173. border: BaseXform.toBoolValue(attributes.border, false),
  9174. gradient: BaseXform.toBoolValue(attributes.gradient, true),
  9175. negativeBarColorSameAsPositive: BaseXform.toBoolValue(attributes.negativeBarColorSameAsPositive, true),
  9176. negativeBarBorderColorSameAsPositive: BaseXform.toBoolValue(attributes.negativeBarBorderColorSameAsPositive, true),
  9177. axisPosition: BaseXform.toStringValue(attributes.axisPosition, 'auto'),
  9178. direction: BaseXform.toStringValue(attributes.direction, 'leftToRight')
  9179. };
  9180. }
  9181. onParserClose(name, parser) {
  9182. const [, prop] = name.split(':');
  9183. switch (prop) {
  9184. case 'cfvo':
  9185. this.model.cfvo.push(parser.model);
  9186. break;
  9187. default:
  9188. this.model[prop] = parser.model;
  9189. break;
  9190. }
  9191. }
  9192. }
  9193. module.exports = DatabarExtXform;
  9194. },{"../../base-xform":32,"../../composite-xform":48,"../../style/color-xform":128,"./cfvo-ext-xform":76}],80:[function(require,module,exports){
  9195. "use strict";
  9196. const BaseXform = require('../../base-xform');
  9197. class FExtXform extends BaseXform {
  9198. get tag() {
  9199. return 'xm:f';
  9200. }
  9201. render(xmlStream, model) {
  9202. xmlStream.leafNode(this.tag, null, model);
  9203. }
  9204. parseOpen() {
  9205. this.model = '';
  9206. }
  9207. parseText(text) {
  9208. this.model += text;
  9209. }
  9210. parseClose(name) {
  9211. return name !== this.tag;
  9212. }
  9213. }
  9214. module.exports = FExtXform;
  9215. },{"../../base-xform":32}],81:[function(require,module,exports){
  9216. "use strict";
  9217. const BaseXform = require('../../base-xform');
  9218. const CompositeXform = require('../../composite-xform');
  9219. const CfvoExtXform = require('./cfvo-ext-xform');
  9220. const CfIconExtXform = require('./cf-icon-ext-xform');
  9221. class IconSetExtXform extends CompositeXform {
  9222. constructor() {
  9223. super();
  9224. this.map = {
  9225. 'x14:cfvo': this.cfvoXform = new CfvoExtXform(),
  9226. 'x14:cfIcon': this.cfIconXform = new CfIconExtXform()
  9227. };
  9228. }
  9229. get tag() {
  9230. return 'x14:iconSet';
  9231. }
  9232. render(xmlStream, model) {
  9233. xmlStream.openNode(this.tag, {
  9234. iconSet: BaseXform.toStringAttribute(model.iconSet),
  9235. reverse: BaseXform.toBoolAttribute(model.reverse, false),
  9236. showValue: BaseXform.toBoolAttribute(model.showValue, true),
  9237. custom: BaseXform.toBoolAttribute(model.icons, false)
  9238. });
  9239. model.cfvo.forEach(cfvo => {
  9240. this.cfvoXform.render(xmlStream, cfvo);
  9241. });
  9242. if (model.icons) {
  9243. model.icons.forEach((icon, i) => {
  9244. icon.iconId = i;
  9245. this.cfIconXform.render(xmlStream, icon);
  9246. });
  9247. }
  9248. xmlStream.closeNode();
  9249. }
  9250. createNewModel(_ref) {
  9251. let {
  9252. attributes
  9253. } = _ref;
  9254. return {
  9255. cfvo: [],
  9256. iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'),
  9257. reverse: BaseXform.toBoolValue(attributes.reverse, false),
  9258. showValue: BaseXform.toBoolValue(attributes.showValue, true)
  9259. };
  9260. }
  9261. onParserClose(name, parser) {
  9262. const [, prop] = name.split(':');
  9263. switch (prop) {
  9264. case 'cfvo':
  9265. this.model.cfvo.push(parser.model);
  9266. break;
  9267. case 'cfIcon':
  9268. if (!this.model.icons) {
  9269. this.model.icons = [];
  9270. }
  9271. this.model.icons.push(parser.model);
  9272. break;
  9273. default:
  9274. this.model[prop] = parser.model;
  9275. break;
  9276. }
  9277. }
  9278. }
  9279. module.exports = IconSetExtXform;
  9280. },{"../../base-xform":32,"../../composite-xform":48,"./cf-icon-ext-xform":74,"./cfvo-ext-xform":76}],82:[function(require,module,exports){
  9281. "use strict";
  9282. const BaseXform = require('../../base-xform');
  9283. class SqrefExtXform extends BaseXform {
  9284. get tag() {
  9285. return 'xm:sqref';
  9286. }
  9287. render(xmlStream, model) {
  9288. xmlStream.leafNode(this.tag, null, model);
  9289. }
  9290. parseOpen() {
  9291. this.model = '';
  9292. }
  9293. parseText(text) {
  9294. this.model += text;
  9295. }
  9296. parseClose(name) {
  9297. return name !== this.tag;
  9298. }
  9299. }
  9300. module.exports = SqrefExtXform;
  9301. },{"../../base-xform":32}],83:[function(require,module,exports){
  9302. "use strict";
  9303. const BaseXform = require('../../base-xform');
  9304. const CompositeXform = require('../../composite-xform');
  9305. const Range = require('../../../../doc/range');
  9306. const DatabarXform = require('./databar-xform');
  9307. const ExtLstRefXform = require('./ext-lst-ref-xform');
  9308. const FormulaXform = require('./formula-xform');
  9309. const ColorScaleXform = require('./color-scale-xform');
  9310. const IconSetXform = require('./icon-set-xform');
  9311. const extIcons = {
  9312. '3Triangles': true,
  9313. '3Stars': true,
  9314. '5Boxes': true
  9315. };
  9316. const getTextFormula = model => {
  9317. if (model.formulae && model.formulae[0]) {
  9318. return model.formulae[0];
  9319. }
  9320. const range = new Range(model.ref);
  9321. const {
  9322. tl
  9323. } = range;
  9324. switch (model.operator) {
  9325. case 'containsText':
  9326. return `NOT(ISERROR(SEARCH("${model.text}",${tl})))`;
  9327. case 'containsBlanks':
  9328. return `LEN(TRIM(${tl}))=0`;
  9329. case 'notContainsBlanks':
  9330. return `LEN(TRIM(${tl}))>0`;
  9331. case 'containsErrors':
  9332. return `ISERROR(${tl})`;
  9333. case 'notContainsErrors':
  9334. return `NOT(ISERROR(${tl}))`;
  9335. default:
  9336. return undefined;
  9337. }
  9338. };
  9339. const getTimePeriodFormula = model => {
  9340. if (model.formulae && model.formulae[0]) {
  9341. return model.formulae[0];
  9342. }
  9343. const range = new Range(model.ref);
  9344. const {
  9345. tl
  9346. } = range;
  9347. switch (model.timePeriod) {
  9348. case 'thisWeek':
  9349. return `AND(TODAY()-ROUNDDOWN(${tl},0)<=WEEKDAY(TODAY())-1,ROUNDDOWN(${tl},0)-TODAY()<=7-WEEKDAY(TODAY()))`;
  9350. case 'lastWeek':
  9351. return `AND(TODAY()-ROUNDDOWN(${tl},0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN(${tl},0)<(WEEKDAY(TODAY())+7))`;
  9352. case 'nextWeek':
  9353. return `AND(ROUNDDOWN(${tl},0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN(${tl},0)-TODAY()<(15-WEEKDAY(TODAY())))`;
  9354. case 'yesterday':
  9355. return `FLOOR(${tl},1)=TODAY()-1`;
  9356. case 'today':
  9357. return `FLOOR(${tl},1)=TODAY()`;
  9358. case 'tomorrow':
  9359. return `FLOOR(${tl},1)=TODAY()+1`;
  9360. case 'last7Days':
  9361. return `AND(TODAY()-FLOOR(${tl},1)<=6,FLOOR(${tl},1)<=TODAY())`;
  9362. case 'lastMonth':
  9363. return `AND(MONTH(${tl})=MONTH(EDATE(TODAY(),0-1)),YEAR(${tl})=YEAR(EDATE(TODAY(),0-1)))`;
  9364. case 'thisMonth':
  9365. return `AND(MONTH(${tl})=MONTH(TODAY()),YEAR(${tl})=YEAR(TODAY()))`;
  9366. case 'nextMonth':
  9367. return `AND(MONTH(${tl})=MONTH(EDATE(TODAY(),0+1)),YEAR(${tl})=YEAR(EDATE(TODAY(),0+1)))`;
  9368. default:
  9369. return undefined;
  9370. }
  9371. };
  9372. const opType = attributes => {
  9373. const {
  9374. type,
  9375. operator
  9376. } = attributes;
  9377. switch (type) {
  9378. case 'containsText':
  9379. case 'containsBlanks':
  9380. case 'notContainsBlanks':
  9381. case 'containsErrors':
  9382. case 'notContainsErrors':
  9383. return {
  9384. type: 'containsText',
  9385. operator: type
  9386. };
  9387. default:
  9388. return {
  9389. type,
  9390. operator
  9391. };
  9392. }
  9393. };
  9394. class CfRuleXform extends CompositeXform {
  9395. constructor() {
  9396. super();
  9397. this.map = {
  9398. dataBar: this.databarXform = new DatabarXform(),
  9399. extLst: this.extLstRefXform = new ExtLstRefXform(),
  9400. formula: this.formulaXform = new FormulaXform(),
  9401. colorScale: this.colorScaleXform = new ColorScaleXform(),
  9402. iconSet: this.iconSetXform = new IconSetXform()
  9403. };
  9404. }
  9405. get tag() {
  9406. return 'cfRule';
  9407. }
  9408. static isPrimitive(rule) {
  9409. // is this rule primitive?
  9410. if (rule.type === 'iconSet') {
  9411. if (rule.custom || extIcons[rule.iconSet]) {
  9412. return false;
  9413. }
  9414. }
  9415. return true;
  9416. }
  9417. render(xmlStream, model) {
  9418. switch (model.type) {
  9419. case 'expression':
  9420. this.renderExpression(xmlStream, model);
  9421. break;
  9422. case 'cellIs':
  9423. this.renderCellIs(xmlStream, model);
  9424. break;
  9425. case 'top10':
  9426. this.renderTop10(xmlStream, model);
  9427. break;
  9428. case 'aboveAverage':
  9429. this.renderAboveAverage(xmlStream, model);
  9430. break;
  9431. case 'dataBar':
  9432. this.renderDataBar(xmlStream, model);
  9433. break;
  9434. case 'colorScale':
  9435. this.renderColorScale(xmlStream, model);
  9436. break;
  9437. case 'iconSet':
  9438. this.renderIconSet(xmlStream, model);
  9439. break;
  9440. case 'containsText':
  9441. this.renderText(xmlStream, model);
  9442. break;
  9443. case 'timePeriod':
  9444. this.renderTimePeriod(xmlStream, model);
  9445. break;
  9446. }
  9447. }
  9448. renderExpression(xmlStream, model) {
  9449. xmlStream.openNode(this.tag, {
  9450. type: 'expression',
  9451. dxfId: model.dxfId,
  9452. priority: model.priority
  9453. });
  9454. this.formulaXform.render(xmlStream, model.formulae[0]);
  9455. xmlStream.closeNode();
  9456. }
  9457. renderCellIs(xmlStream, model) {
  9458. xmlStream.openNode(this.tag, {
  9459. type: 'cellIs',
  9460. dxfId: model.dxfId,
  9461. priority: model.priority,
  9462. operator: model.operator
  9463. });
  9464. model.formulae.forEach(formula => {
  9465. this.formulaXform.render(xmlStream, formula);
  9466. });
  9467. xmlStream.closeNode();
  9468. }
  9469. renderTop10(xmlStream, model) {
  9470. xmlStream.leafNode(this.tag, {
  9471. type: 'top10',
  9472. dxfId: model.dxfId,
  9473. priority: model.priority,
  9474. percent: BaseXform.toBoolAttribute(model.percent, false),
  9475. bottom: BaseXform.toBoolAttribute(model.bottom, false),
  9476. rank: BaseXform.toIntValue(model.rank, 10, true)
  9477. });
  9478. }
  9479. renderAboveAverage(xmlStream, model) {
  9480. xmlStream.leafNode(this.tag, {
  9481. type: 'aboveAverage',
  9482. dxfId: model.dxfId,
  9483. priority: model.priority,
  9484. aboveAverage: BaseXform.toBoolAttribute(model.aboveAverage, true)
  9485. });
  9486. }
  9487. renderDataBar(xmlStream, model) {
  9488. xmlStream.openNode(this.tag, {
  9489. type: 'dataBar',
  9490. priority: model.priority
  9491. });
  9492. this.databarXform.render(xmlStream, model);
  9493. this.extLstRefXform.render(xmlStream, model);
  9494. xmlStream.closeNode();
  9495. }
  9496. renderColorScale(xmlStream, model) {
  9497. xmlStream.openNode(this.tag, {
  9498. type: 'colorScale',
  9499. priority: model.priority
  9500. });
  9501. this.colorScaleXform.render(xmlStream, model);
  9502. xmlStream.closeNode();
  9503. }
  9504. renderIconSet(xmlStream, model) {
  9505. // iconset is all primitive or all extLst
  9506. if (!CfRuleXform.isPrimitive(model)) {
  9507. return;
  9508. }
  9509. xmlStream.openNode(this.tag, {
  9510. type: 'iconSet',
  9511. priority: model.priority
  9512. });
  9513. this.iconSetXform.render(xmlStream, model);
  9514. xmlStream.closeNode();
  9515. }
  9516. renderText(xmlStream, model) {
  9517. xmlStream.openNode(this.tag, {
  9518. type: model.operator,
  9519. dxfId: model.dxfId,
  9520. priority: model.priority,
  9521. operator: BaseXform.toStringAttribute(model.operator, 'containsText')
  9522. });
  9523. const formula = getTextFormula(model);
  9524. if (formula) {
  9525. this.formulaXform.render(xmlStream, formula);
  9526. }
  9527. xmlStream.closeNode();
  9528. }
  9529. renderTimePeriod(xmlStream, model) {
  9530. xmlStream.openNode(this.tag, {
  9531. type: 'timePeriod',
  9532. dxfId: model.dxfId,
  9533. priority: model.priority,
  9534. timePeriod: model.timePeriod
  9535. });
  9536. const formula = getTimePeriodFormula(model);
  9537. if (formula) {
  9538. this.formulaXform.render(xmlStream, formula);
  9539. }
  9540. xmlStream.closeNode();
  9541. }
  9542. createNewModel(_ref) {
  9543. let {
  9544. attributes
  9545. } = _ref;
  9546. return {
  9547. ...opType(attributes),
  9548. dxfId: BaseXform.toIntValue(attributes.dxfId),
  9549. priority: BaseXform.toIntValue(attributes.priority),
  9550. timePeriod: attributes.timePeriod,
  9551. percent: BaseXform.toBoolValue(attributes.percent),
  9552. bottom: BaseXform.toBoolValue(attributes.bottom),
  9553. rank: BaseXform.toIntValue(attributes.rank),
  9554. aboveAverage: BaseXform.toBoolValue(attributes.aboveAverage)
  9555. };
  9556. }
  9557. onParserClose(name, parser) {
  9558. switch (name) {
  9559. case 'dataBar':
  9560. case 'extLst':
  9561. case 'colorScale':
  9562. case 'iconSet':
  9563. // merge parser model with ours
  9564. Object.assign(this.model, parser.model);
  9565. break;
  9566. case 'formula':
  9567. // except - formula is a string and appends to formulae
  9568. this.model.formulae = this.model.formulae || [];
  9569. this.model.formulae.push(parser.model);
  9570. break;
  9571. }
  9572. }
  9573. }
  9574. module.exports = CfRuleXform;
  9575. },{"../../../../doc/range":10,"../../base-xform":32,"../../composite-xform":48,"./color-scale-xform":85,"./databar-xform":88,"./ext-lst-ref-xform":89,"./formula-xform":90,"./icon-set-xform":91}],84:[function(require,module,exports){
  9576. "use strict";
  9577. const BaseXform = require('../../base-xform');
  9578. class CfvoXform extends BaseXform {
  9579. get tag() {
  9580. return 'cfvo';
  9581. }
  9582. render(xmlStream, model) {
  9583. xmlStream.leafNode(this.tag, {
  9584. type: model.type,
  9585. val: model.value
  9586. });
  9587. }
  9588. parseOpen(node) {
  9589. this.model = {
  9590. type: node.attributes.type,
  9591. value: BaseXform.toFloatValue(node.attributes.val)
  9592. };
  9593. }
  9594. parseClose(name) {
  9595. return name !== this.tag;
  9596. }
  9597. }
  9598. module.exports = CfvoXform;
  9599. },{"../../base-xform":32}],85:[function(require,module,exports){
  9600. "use strict";
  9601. const CompositeXform = require('../../composite-xform');
  9602. const ColorXform = require('../../style/color-xform');
  9603. const CfvoXform = require('./cfvo-xform');
  9604. class ColorScaleXform extends CompositeXform {
  9605. constructor() {
  9606. super();
  9607. this.map = {
  9608. cfvo: this.cfvoXform = new CfvoXform(),
  9609. color: this.colorXform = new ColorXform()
  9610. };
  9611. }
  9612. get tag() {
  9613. return 'colorScale';
  9614. }
  9615. render(xmlStream, model) {
  9616. xmlStream.openNode(this.tag);
  9617. model.cfvo.forEach(cfvo => {
  9618. this.cfvoXform.render(xmlStream, cfvo);
  9619. });
  9620. model.color.forEach(color => {
  9621. this.colorXform.render(xmlStream, color);
  9622. });
  9623. xmlStream.closeNode();
  9624. }
  9625. createNewModel(node) {
  9626. return {
  9627. cfvo: [],
  9628. color: []
  9629. };
  9630. }
  9631. onParserClose(name, parser) {
  9632. this.model[name].push(parser.model);
  9633. }
  9634. }
  9635. module.exports = ColorScaleXform;
  9636. },{"../../composite-xform":48,"../../style/color-xform":128,"./cfvo-xform":84}],86:[function(require,module,exports){
  9637. "use strict";
  9638. const CompositeXform = require('../../composite-xform');
  9639. const CfRuleXform = require('./cf-rule-xform');
  9640. class ConditionalFormattingXform extends CompositeXform {
  9641. constructor() {
  9642. super();
  9643. this.map = {
  9644. cfRule: new CfRuleXform()
  9645. };
  9646. }
  9647. get tag() {
  9648. return 'conditionalFormatting';
  9649. }
  9650. render(xmlStream, model) {
  9651. // if there are no primitive rules, exit now
  9652. if (!model.rules.some(CfRuleXform.isPrimitive)) {
  9653. return;
  9654. }
  9655. xmlStream.openNode(this.tag, {
  9656. sqref: model.ref
  9657. });
  9658. model.rules.forEach(rule => {
  9659. if (CfRuleXform.isPrimitive(rule)) {
  9660. rule.ref = model.ref;
  9661. this.map.cfRule.render(xmlStream, rule);
  9662. }
  9663. });
  9664. xmlStream.closeNode();
  9665. }
  9666. createNewModel(_ref) {
  9667. let {
  9668. attributes
  9669. } = _ref;
  9670. return {
  9671. ref: attributes.sqref,
  9672. rules: []
  9673. };
  9674. }
  9675. onParserClose(name, parser) {
  9676. this.model.rules.push(parser.model);
  9677. }
  9678. }
  9679. module.exports = ConditionalFormattingXform;
  9680. },{"../../composite-xform":48,"./cf-rule-xform":83}],87:[function(require,module,exports){
  9681. "use strict";
  9682. const BaseXform = require('../../base-xform');
  9683. const ConditionalFormattingXform = require('./conditional-formatting-xform');
  9684. class ConditionalFormattingsXform extends BaseXform {
  9685. constructor() {
  9686. super();
  9687. this.cfXform = new ConditionalFormattingXform();
  9688. }
  9689. get tag() {
  9690. return 'conditionalFormatting';
  9691. }
  9692. reset() {
  9693. this.model = [];
  9694. }
  9695. prepare(model, options) {
  9696. // ensure each rule has a priority value
  9697. let nextPriority = model.reduce((p, cf) => Math.max(p, ...cf.rules.map(rule => rule.priority || 0)), 1);
  9698. model.forEach(cf => {
  9699. cf.rules.forEach(rule => {
  9700. if (!rule.priority) {
  9701. rule.priority = nextPriority++;
  9702. }
  9703. if (rule.style) {
  9704. rule.dxfId = options.styles.addDxfStyle(rule.style);
  9705. }
  9706. });
  9707. });
  9708. }
  9709. render(xmlStream, model) {
  9710. model.forEach(cf => {
  9711. this.cfXform.render(xmlStream, cf);
  9712. });
  9713. }
  9714. parseOpen(node) {
  9715. if (this.parser) {
  9716. this.parser.parseOpen(node);
  9717. return true;
  9718. }
  9719. switch (node.name) {
  9720. case 'conditionalFormatting':
  9721. this.parser = this.cfXform;
  9722. this.parser.parseOpen(node);
  9723. return true;
  9724. default:
  9725. return false;
  9726. }
  9727. }
  9728. parseText(text) {
  9729. if (this.parser) {
  9730. this.parser.parseText(text);
  9731. }
  9732. }
  9733. parseClose(name) {
  9734. if (this.parser) {
  9735. if (!this.parser.parseClose(name)) {
  9736. this.model.push(this.parser.model);
  9737. this.parser = undefined;
  9738. return false;
  9739. }
  9740. return true;
  9741. }
  9742. return false;
  9743. }
  9744. reconcile(model, options) {
  9745. model.forEach(cf => {
  9746. cf.rules.forEach(rule => {
  9747. if (rule.dxfId !== undefined) {
  9748. rule.style = options.styles.getDxfStyle(rule.dxfId);
  9749. delete rule.dxfId;
  9750. }
  9751. });
  9752. });
  9753. }
  9754. }
  9755. module.exports = ConditionalFormattingsXform;
  9756. },{"../../base-xform":32,"./conditional-formatting-xform":86}],88:[function(require,module,exports){
  9757. "use strict";
  9758. const CompositeXform = require('../../composite-xform');
  9759. const ColorXform = require('../../style/color-xform');
  9760. const CfvoXform = require('./cfvo-xform');
  9761. class DatabarXform extends CompositeXform {
  9762. constructor() {
  9763. super();
  9764. this.map = {
  9765. cfvo: this.cfvoXform = new CfvoXform(),
  9766. color: this.colorXform = new ColorXform()
  9767. };
  9768. }
  9769. get tag() {
  9770. return 'dataBar';
  9771. }
  9772. render(xmlStream, model) {
  9773. xmlStream.openNode(this.tag);
  9774. model.cfvo.forEach(cfvo => {
  9775. this.cfvoXform.render(xmlStream, cfvo);
  9776. });
  9777. this.colorXform.render(xmlStream, model.color);
  9778. xmlStream.closeNode();
  9779. }
  9780. createNewModel() {
  9781. return {
  9782. cfvo: []
  9783. };
  9784. }
  9785. onParserClose(name, parser) {
  9786. switch (name) {
  9787. case 'cfvo':
  9788. this.model.cfvo.push(parser.model);
  9789. break;
  9790. case 'color':
  9791. this.model.color = parser.model;
  9792. break;
  9793. }
  9794. }
  9795. }
  9796. module.exports = DatabarXform;
  9797. },{"../../composite-xform":48,"../../style/color-xform":128,"./cfvo-xform":84}],89:[function(require,module,exports){
  9798. "use strict";
  9799. /* eslint-disable max-classes-per-file */
  9800. const BaseXform = require('../../base-xform');
  9801. const CompositeXform = require('../../composite-xform');
  9802. class X14IdXform extends BaseXform {
  9803. get tag() {
  9804. return 'x14:id';
  9805. }
  9806. render(xmlStream, model) {
  9807. xmlStream.leafNode(this.tag, null, model);
  9808. }
  9809. parseOpen() {
  9810. this.model = '';
  9811. }
  9812. parseText(text) {
  9813. this.model += text;
  9814. }
  9815. parseClose(name) {
  9816. return name !== this.tag;
  9817. }
  9818. }
  9819. class ExtXform extends CompositeXform {
  9820. constructor() {
  9821. super();
  9822. this.map = {
  9823. 'x14:id': this.idXform = new X14IdXform()
  9824. };
  9825. }
  9826. get tag() {
  9827. return 'ext';
  9828. }
  9829. render(xmlStream, model) {
  9830. xmlStream.openNode(this.tag, {
  9831. uri: '{B025F937-C7B1-47D3-B67F-A62EFF666E3E}',
  9832. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  9833. });
  9834. this.idXform.render(xmlStream, model.x14Id);
  9835. xmlStream.closeNode();
  9836. }
  9837. createNewModel() {
  9838. return {};
  9839. }
  9840. onParserClose(name, parser) {
  9841. this.model.x14Id = parser.model;
  9842. }
  9843. }
  9844. class ExtLstRefXform extends CompositeXform {
  9845. constructor() {
  9846. super();
  9847. this.map = {
  9848. ext: new ExtXform()
  9849. };
  9850. }
  9851. get tag() {
  9852. return 'extLst';
  9853. }
  9854. render(xmlStream, model) {
  9855. xmlStream.openNode(this.tag);
  9856. this.map.ext.render(xmlStream, model);
  9857. xmlStream.closeNode();
  9858. }
  9859. createNewModel() {
  9860. return {};
  9861. }
  9862. onParserClose(name, parser) {
  9863. Object.assign(this.model, parser.model);
  9864. }
  9865. }
  9866. module.exports = ExtLstRefXform;
  9867. },{"../../base-xform":32,"../../composite-xform":48}],90:[function(require,module,exports){
  9868. "use strict";
  9869. const BaseXform = require('../../base-xform');
  9870. class FormulaXform extends BaseXform {
  9871. get tag() {
  9872. return 'formula';
  9873. }
  9874. render(xmlStream, model) {
  9875. xmlStream.leafNode(this.tag, null, model);
  9876. }
  9877. parseOpen() {
  9878. this.model = '';
  9879. }
  9880. parseText(text) {
  9881. this.model += text;
  9882. }
  9883. parseClose(name) {
  9884. return name !== this.tag;
  9885. }
  9886. }
  9887. module.exports = FormulaXform;
  9888. },{"../../base-xform":32}],91:[function(require,module,exports){
  9889. "use strict";
  9890. const BaseXform = require('../../base-xform');
  9891. const CompositeXform = require('../../composite-xform');
  9892. const CfvoXform = require('./cfvo-xform');
  9893. class IconSetXform extends CompositeXform {
  9894. constructor() {
  9895. super();
  9896. this.map = {
  9897. cfvo: this.cfvoXform = new CfvoXform()
  9898. };
  9899. }
  9900. get tag() {
  9901. return 'iconSet';
  9902. }
  9903. render(xmlStream, model) {
  9904. xmlStream.openNode(this.tag, {
  9905. iconSet: BaseXform.toStringAttribute(model.iconSet, '3TrafficLights'),
  9906. reverse: BaseXform.toBoolAttribute(model.reverse, false),
  9907. showValue: BaseXform.toBoolAttribute(model.showValue, true)
  9908. });
  9909. model.cfvo.forEach(cfvo => {
  9910. this.cfvoXform.render(xmlStream, cfvo);
  9911. });
  9912. xmlStream.closeNode();
  9913. }
  9914. createNewModel(_ref) {
  9915. let {
  9916. attributes
  9917. } = _ref;
  9918. return {
  9919. iconSet: BaseXform.toStringValue(attributes.iconSet, '3TrafficLights'),
  9920. reverse: BaseXform.toBoolValue(attributes.reverse),
  9921. showValue: BaseXform.toBoolValue(attributes.showValue),
  9922. cfvo: []
  9923. };
  9924. }
  9925. onParserClose(name, parser) {
  9926. this.model[name].push(parser.model);
  9927. }
  9928. }
  9929. module.exports = IconSetXform;
  9930. },{"../../base-xform":32,"../../composite-xform":48,"./cfvo-xform":84}],92:[function(require,module,exports){
  9931. "use strict";
  9932. const utils = require('../../../utils/utils');
  9933. const BaseXform = require('../base-xform');
  9934. class ColXform extends BaseXform {
  9935. get tag() {
  9936. return 'col';
  9937. }
  9938. prepare(model, options) {
  9939. const styleId = options.styles.addStyleModel(model.style || {});
  9940. if (styleId) {
  9941. model.styleId = styleId;
  9942. }
  9943. }
  9944. render(xmlStream, model) {
  9945. xmlStream.openNode('col');
  9946. xmlStream.addAttribute('min', model.min);
  9947. xmlStream.addAttribute('max', model.max);
  9948. if (model.width) {
  9949. xmlStream.addAttribute('width', model.width);
  9950. }
  9951. if (model.styleId) {
  9952. xmlStream.addAttribute('style', model.styleId);
  9953. }
  9954. if (model.hidden) {
  9955. xmlStream.addAttribute('hidden', '1');
  9956. }
  9957. if (model.bestFit) {
  9958. xmlStream.addAttribute('bestFit', '1');
  9959. }
  9960. if (model.outlineLevel) {
  9961. xmlStream.addAttribute('outlineLevel', model.outlineLevel);
  9962. }
  9963. if (model.collapsed) {
  9964. xmlStream.addAttribute('collapsed', '1');
  9965. }
  9966. xmlStream.addAttribute('customWidth', '1');
  9967. xmlStream.closeNode();
  9968. }
  9969. parseOpen(node) {
  9970. if (node.name === 'col') {
  9971. const model = this.model = {
  9972. min: parseInt(node.attributes.min || '0', 10),
  9973. max: parseInt(node.attributes.max || '0', 10),
  9974. width: node.attributes.width === undefined ? undefined : parseFloat(node.attributes.width || '0')
  9975. };
  9976. if (node.attributes.style) {
  9977. model.styleId = parseInt(node.attributes.style, 10);
  9978. }
  9979. if (utils.parseBoolean(node.attributes.hidden)) {
  9980. model.hidden = true;
  9981. }
  9982. if (utils.parseBoolean(node.attributes.bestFit)) {
  9983. model.bestFit = true;
  9984. }
  9985. if (node.attributes.outlineLevel) {
  9986. model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
  9987. }
  9988. if (utils.parseBoolean(node.attributes.collapsed)) {
  9989. model.collapsed = true;
  9990. }
  9991. return true;
  9992. }
  9993. return false;
  9994. }
  9995. parseText() {}
  9996. parseClose() {
  9997. return false;
  9998. }
  9999. reconcile(model, options) {
  10000. // reconcile column styles
  10001. if (model.styleId) {
  10002. model.style = options.styles.getStyleModel(model.styleId);
  10003. }
  10004. }
  10005. }
  10006. module.exports = ColXform;
  10007. },{"../../../utils/utils":27,"../base-xform":32}],93:[function(require,module,exports){
  10008. "use strict";
  10009. const _ = require('../../../utils/under-dash');
  10010. const utils = require('../../../utils/utils');
  10011. const colCache = require('../../../utils/col-cache');
  10012. const BaseXform = require('../base-xform');
  10013. const Range = require('../../../doc/range');
  10014. function assign(definedName, attributes, name, defaultValue) {
  10015. const value = attributes[name];
  10016. if (value !== undefined) {
  10017. definedName[name] = value;
  10018. } else if (defaultValue !== undefined) {
  10019. definedName[name] = defaultValue;
  10020. }
  10021. }
  10022. function assignBool(definedName, attributes, name, defaultValue) {
  10023. const value = attributes[name];
  10024. if (value !== undefined) {
  10025. definedName[name] = utils.parseBoolean(value);
  10026. } else if (defaultValue !== undefined) {
  10027. definedName[name] = defaultValue;
  10028. }
  10029. }
  10030. function optimiseDataValidations(model) {
  10031. // Squeeze alike data validations together into rectangular ranges
  10032. // to reduce file size and speed up Excel load time
  10033. const dvList = _.map(model, (dataValidation, address) => ({
  10034. address,
  10035. dataValidation,
  10036. marked: false
  10037. })).sort((a, b) => _.strcmp(a.address, b.address));
  10038. const dvMap = _.keyBy(dvList, 'address');
  10039. const matchCol = (addr, height, col) => {
  10040. for (let i = 0; i < height; i++) {
  10041. const otherAddress = colCache.encodeAddress(addr.row + i, col);
  10042. if (!model[otherAddress] || !_.isEqual(model[addr.address], model[otherAddress])) {
  10043. return false;
  10044. }
  10045. }
  10046. return true;
  10047. };
  10048. return dvList.map(dv => {
  10049. if (!dv.marked) {
  10050. const addr = colCache.decodeEx(dv.address);
  10051. if (addr.dimensions) {
  10052. dvMap[addr.dimensions].marked = true;
  10053. return {
  10054. ...dv.dataValidation,
  10055. sqref: dv.address
  10056. };
  10057. }
  10058. // iterate downwards - finding matching cells
  10059. let height = 1;
  10060. let otherAddress = colCache.encodeAddress(addr.row + height, addr.col);
  10061. while (model[otherAddress] && _.isEqual(dv.dataValidation, model[otherAddress])) {
  10062. height++;
  10063. otherAddress = colCache.encodeAddress(addr.row + height, addr.col);
  10064. }
  10065. // iterate rightwards...
  10066. let width = 1;
  10067. while (matchCol(addr, height, addr.col + width)) {
  10068. width++;
  10069. }
  10070. // mark all included addresses
  10071. for (let i = 0; i < height; i++) {
  10072. for (let j = 0; j < width; j++) {
  10073. otherAddress = colCache.encodeAddress(addr.row + i, addr.col + j);
  10074. dvMap[otherAddress].marked = true;
  10075. }
  10076. }
  10077. if (height > 1 || width > 1) {
  10078. const bottom = addr.row + (height - 1);
  10079. const right = addr.col + (width - 1);
  10080. return {
  10081. ...dv.dataValidation,
  10082. sqref: `${dv.address}:${colCache.encodeAddress(bottom, right)}`
  10083. };
  10084. }
  10085. return {
  10086. ...dv.dataValidation,
  10087. sqref: dv.address
  10088. };
  10089. }
  10090. return null;
  10091. }).filter(Boolean);
  10092. }
  10093. class DataValidationsXform extends BaseXform {
  10094. get tag() {
  10095. return 'dataValidations';
  10096. }
  10097. render(xmlStream, model) {
  10098. const optimizedModel = optimiseDataValidations(model);
  10099. if (optimizedModel.length) {
  10100. xmlStream.openNode('dataValidations', {
  10101. count: optimizedModel.length
  10102. });
  10103. optimizedModel.forEach(value => {
  10104. xmlStream.openNode('dataValidation');
  10105. if (value.type !== 'any') {
  10106. xmlStream.addAttribute('type', value.type);
  10107. if (value.operator && value.type !== 'list' && value.operator !== 'between') {
  10108. xmlStream.addAttribute('operator', value.operator);
  10109. }
  10110. if (value.allowBlank) {
  10111. xmlStream.addAttribute('allowBlank', '1');
  10112. }
  10113. }
  10114. if (value.showInputMessage) {
  10115. xmlStream.addAttribute('showInputMessage', '1');
  10116. }
  10117. if (value.promptTitle) {
  10118. xmlStream.addAttribute('promptTitle', value.promptTitle);
  10119. }
  10120. if (value.prompt) {
  10121. xmlStream.addAttribute('prompt', value.prompt);
  10122. }
  10123. if (value.showErrorMessage) {
  10124. xmlStream.addAttribute('showErrorMessage', '1');
  10125. }
  10126. if (value.errorStyle) {
  10127. xmlStream.addAttribute('errorStyle', value.errorStyle);
  10128. }
  10129. if (value.errorTitle) {
  10130. xmlStream.addAttribute('errorTitle', value.errorTitle);
  10131. }
  10132. if (value.error) {
  10133. xmlStream.addAttribute('error', value.error);
  10134. }
  10135. xmlStream.addAttribute('sqref', value.sqref);
  10136. (value.formulae || []).forEach((formula, index) => {
  10137. xmlStream.openNode(`formula${index + 1}`);
  10138. if (value.type === 'date') {
  10139. xmlStream.writeText(utils.dateToExcel(new Date(formula)));
  10140. } else {
  10141. xmlStream.writeText(formula);
  10142. }
  10143. xmlStream.closeNode();
  10144. });
  10145. xmlStream.closeNode();
  10146. });
  10147. xmlStream.closeNode();
  10148. }
  10149. }
  10150. parseOpen(node) {
  10151. switch (node.name) {
  10152. case 'dataValidations':
  10153. this.model = {};
  10154. return true;
  10155. case 'dataValidation':
  10156. {
  10157. this._address = node.attributes.sqref;
  10158. const dataValidation = {
  10159. type: node.attributes.type || 'any',
  10160. formulae: []
  10161. };
  10162. if (node.attributes.type) {
  10163. assignBool(dataValidation, node.attributes, 'allowBlank');
  10164. }
  10165. assignBool(dataValidation, node.attributes, 'showInputMessage');
  10166. assignBool(dataValidation, node.attributes, 'showErrorMessage');
  10167. switch (dataValidation.type) {
  10168. case 'any':
  10169. case 'list':
  10170. case 'custom':
  10171. break;
  10172. default:
  10173. assign(dataValidation, node.attributes, 'operator', 'between');
  10174. break;
  10175. }
  10176. assign(dataValidation, node.attributes, 'promptTitle');
  10177. assign(dataValidation, node.attributes, 'prompt');
  10178. assign(dataValidation, node.attributes, 'errorStyle');
  10179. assign(dataValidation, node.attributes, 'errorTitle');
  10180. assign(dataValidation, node.attributes, 'error');
  10181. this._dataValidation = dataValidation;
  10182. return true;
  10183. }
  10184. case 'formula1':
  10185. case 'formula2':
  10186. this._formula = [];
  10187. return true;
  10188. default:
  10189. return false;
  10190. }
  10191. }
  10192. parseText(text) {
  10193. if (this._formula) {
  10194. this._formula.push(text);
  10195. }
  10196. }
  10197. parseClose(name) {
  10198. switch (name) {
  10199. case 'dataValidations':
  10200. return false;
  10201. case 'dataValidation':
  10202. {
  10203. if (!this._dataValidation.formulae || !this._dataValidation.formulae.length) {
  10204. delete this._dataValidation.formulae;
  10205. delete this._dataValidation.operator;
  10206. }
  10207. // The four known cases: 1. E4:L9 N4:U9 2.E4 L9 3. N4:U9 4. E4
  10208. const list = this._address.split(/\s+/g) || [];
  10209. list.forEach(addr => {
  10210. if (addr.includes(':')) {
  10211. const range = new Range(addr);
  10212. range.forEachAddress(address => {
  10213. this.model[address] = this._dataValidation;
  10214. });
  10215. } else {
  10216. this.model[addr] = this._dataValidation;
  10217. }
  10218. });
  10219. return true;
  10220. }
  10221. case 'formula1':
  10222. case 'formula2':
  10223. {
  10224. let formula = this._formula.join('');
  10225. switch (this._dataValidation.type) {
  10226. case 'whole':
  10227. case 'textLength':
  10228. formula = parseInt(formula, 10);
  10229. break;
  10230. case 'decimal':
  10231. formula = parseFloat(formula);
  10232. break;
  10233. case 'date':
  10234. formula = utils.excelToDate(parseFloat(formula));
  10235. break;
  10236. default:
  10237. break;
  10238. }
  10239. this._dataValidation.formulae.push(formula);
  10240. this._formula = undefined;
  10241. return true;
  10242. }
  10243. default:
  10244. return true;
  10245. }
  10246. }
  10247. }
  10248. module.exports = DataValidationsXform;
  10249. },{"../../../doc/range":10,"../../../utils/col-cache":19,"../../../utils/under-dash":26,"../../../utils/utils":27,"../base-xform":32}],94:[function(require,module,exports){
  10250. "use strict";
  10251. const BaseXform = require('../base-xform');
  10252. class DimensionXform extends BaseXform {
  10253. get tag() {
  10254. return 'dimension';
  10255. }
  10256. render(xmlStream, model) {
  10257. if (model) {
  10258. xmlStream.leafNode('dimension', {
  10259. ref: model
  10260. });
  10261. }
  10262. }
  10263. parseOpen(node) {
  10264. if (node.name === 'dimension') {
  10265. this.model = node.attributes.ref;
  10266. return true;
  10267. }
  10268. return false;
  10269. }
  10270. parseText() {}
  10271. parseClose() {
  10272. return false;
  10273. }
  10274. }
  10275. module.exports = DimensionXform;
  10276. },{"../base-xform":32}],95:[function(require,module,exports){
  10277. "use strict";
  10278. const BaseXform = require('../base-xform');
  10279. class DrawingXform extends BaseXform {
  10280. get tag() {
  10281. return 'drawing';
  10282. }
  10283. render(xmlStream, model) {
  10284. if (model) {
  10285. xmlStream.leafNode(this.tag, {
  10286. 'r:id': model.rId
  10287. });
  10288. }
  10289. }
  10290. parseOpen(node) {
  10291. switch (node.name) {
  10292. case this.tag:
  10293. this.model = {
  10294. rId: node.attributes['r:id']
  10295. };
  10296. return true;
  10297. default:
  10298. return false;
  10299. }
  10300. }
  10301. parseText() {}
  10302. parseClose() {
  10303. return false;
  10304. }
  10305. }
  10306. module.exports = DrawingXform;
  10307. },{"../base-xform":32}],96:[function(require,module,exports){
  10308. "use strict";
  10309. /* eslint-disable max-classes-per-file */
  10310. const CompositeXform = require('../composite-xform');
  10311. const ConditionalFormattingsExt = require('./cf-ext/conditional-formattings-ext-xform');
  10312. class ExtXform extends CompositeXform {
  10313. constructor() {
  10314. super();
  10315. this.map = {
  10316. 'x14:conditionalFormattings': this.conditionalFormattings = new ConditionalFormattingsExt()
  10317. };
  10318. }
  10319. get tag() {
  10320. return 'ext';
  10321. }
  10322. hasContent(model) {
  10323. return this.conditionalFormattings.hasContent(model.conditionalFormattings);
  10324. }
  10325. prepare(model, options) {
  10326. this.conditionalFormattings.prepare(model.conditionalFormattings, options);
  10327. }
  10328. render(xmlStream, model) {
  10329. xmlStream.openNode('ext', {
  10330. uri: '{78C0D931-6437-407d-A8EE-F0AAD7539E65}',
  10331. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  10332. });
  10333. this.conditionalFormattings.render(xmlStream, model.conditionalFormattings);
  10334. xmlStream.closeNode();
  10335. }
  10336. createNewModel() {
  10337. return {};
  10338. }
  10339. onParserClose(name, parser) {
  10340. this.model[name] = parser.model;
  10341. }
  10342. }
  10343. class ExtLstXform extends CompositeXform {
  10344. constructor() {
  10345. super();
  10346. this.map = {
  10347. ext: this.ext = new ExtXform()
  10348. };
  10349. }
  10350. get tag() {
  10351. return 'extLst';
  10352. }
  10353. prepare(model, options) {
  10354. this.ext.prepare(model, options);
  10355. }
  10356. hasContent(model) {
  10357. return this.ext.hasContent(model);
  10358. }
  10359. render(xmlStream, model) {
  10360. if (!this.hasContent(model)) {
  10361. return;
  10362. }
  10363. xmlStream.openNode('extLst');
  10364. this.ext.render(xmlStream, model);
  10365. xmlStream.closeNode();
  10366. }
  10367. createNewModel() {
  10368. return {};
  10369. }
  10370. onParserClose(name, parser) {
  10371. Object.assign(this.model, parser.model);
  10372. }
  10373. }
  10374. module.exports = ExtLstXform;
  10375. },{"../composite-xform":48,"./cf-ext/conditional-formattings-ext-xform":78}],97:[function(require,module,exports){
  10376. "use strict";
  10377. const BaseXform = require('../base-xform');
  10378. class HeaderFooterXform extends BaseXform {
  10379. get tag() {
  10380. return 'headerFooter';
  10381. }
  10382. render(xmlStream, model) {
  10383. if (model) {
  10384. xmlStream.addRollback();
  10385. let createTag = false;
  10386. xmlStream.openNode('headerFooter');
  10387. if (model.differentFirst) {
  10388. xmlStream.addAttribute('differentFirst', '1');
  10389. createTag = true;
  10390. }
  10391. if (model.differentOddEven) {
  10392. xmlStream.addAttribute('differentOddEven', '1');
  10393. createTag = true;
  10394. }
  10395. if (model.oddHeader && typeof model.oddHeader === 'string') {
  10396. xmlStream.leafNode('oddHeader', null, model.oddHeader);
  10397. createTag = true;
  10398. }
  10399. if (model.oddFooter && typeof model.oddFooter === 'string') {
  10400. xmlStream.leafNode('oddFooter', null, model.oddFooter);
  10401. createTag = true;
  10402. }
  10403. if (model.evenHeader && typeof model.evenHeader === 'string') {
  10404. xmlStream.leafNode('evenHeader', null, model.evenHeader);
  10405. createTag = true;
  10406. }
  10407. if (model.evenFooter && typeof model.evenFooter === 'string') {
  10408. xmlStream.leafNode('evenFooter', null, model.evenFooter);
  10409. createTag = true;
  10410. }
  10411. if (model.firstHeader && typeof model.firstHeader === 'string') {
  10412. xmlStream.leafNode('firstHeader', null, model.firstHeader);
  10413. createTag = true;
  10414. }
  10415. if (model.firstFooter && typeof model.firstFooter === 'string') {
  10416. xmlStream.leafNode('firstFooter', null, model.firstFooter);
  10417. createTag = true;
  10418. }
  10419. if (createTag) {
  10420. xmlStream.closeNode();
  10421. xmlStream.commit();
  10422. } else {
  10423. xmlStream.rollback();
  10424. }
  10425. }
  10426. }
  10427. parseOpen(node) {
  10428. switch (node.name) {
  10429. case 'headerFooter':
  10430. this.model = {};
  10431. if (node.attributes.differentFirst) {
  10432. this.model.differentFirst = parseInt(node.attributes.differentFirst, 0) === 1;
  10433. }
  10434. if (node.attributes.differentOddEven) {
  10435. this.model.differentOddEven = parseInt(node.attributes.differentOddEven, 0) === 1;
  10436. }
  10437. return true;
  10438. case 'oddHeader':
  10439. this.currentNode = 'oddHeader';
  10440. return true;
  10441. case 'oddFooter':
  10442. this.currentNode = 'oddFooter';
  10443. return true;
  10444. case 'evenHeader':
  10445. this.currentNode = 'evenHeader';
  10446. return true;
  10447. case 'evenFooter':
  10448. this.currentNode = 'evenFooter';
  10449. return true;
  10450. case 'firstHeader':
  10451. this.currentNode = 'firstHeader';
  10452. return true;
  10453. case 'firstFooter':
  10454. this.currentNode = 'firstFooter';
  10455. return true;
  10456. default:
  10457. return false;
  10458. }
  10459. }
  10460. parseText(text) {
  10461. switch (this.currentNode) {
  10462. case 'oddHeader':
  10463. this.model.oddHeader = text;
  10464. break;
  10465. case 'oddFooter':
  10466. this.model.oddFooter = text;
  10467. break;
  10468. case 'evenHeader':
  10469. this.model.evenHeader = text;
  10470. break;
  10471. case 'evenFooter':
  10472. this.model.evenFooter = text;
  10473. break;
  10474. case 'firstHeader':
  10475. this.model.firstHeader = text;
  10476. break;
  10477. case 'firstFooter':
  10478. this.model.firstFooter = text;
  10479. break;
  10480. default:
  10481. break;
  10482. }
  10483. }
  10484. parseClose() {
  10485. switch (this.currentNode) {
  10486. case 'oddHeader':
  10487. case 'oddFooter':
  10488. case 'evenHeader':
  10489. case 'evenFooter':
  10490. case 'firstHeader':
  10491. case 'firstFooter':
  10492. this.currentNode = undefined;
  10493. return true;
  10494. default:
  10495. return false;
  10496. }
  10497. }
  10498. }
  10499. module.exports = HeaderFooterXform;
  10500. },{"../base-xform":32}],98:[function(require,module,exports){
  10501. "use strict";
  10502. const BaseXform = require('../base-xform');
  10503. class HyperlinkXform extends BaseXform {
  10504. get tag() {
  10505. return 'hyperlink';
  10506. }
  10507. render(xmlStream, model) {
  10508. if (this.isInternalLink(model)) {
  10509. xmlStream.leafNode('hyperlink', {
  10510. ref: model.address,
  10511. 'r:id': model.rId,
  10512. tooltip: model.tooltip,
  10513. location: model.target
  10514. });
  10515. } else {
  10516. xmlStream.leafNode('hyperlink', {
  10517. ref: model.address,
  10518. 'r:id': model.rId,
  10519. tooltip: model.tooltip
  10520. });
  10521. }
  10522. }
  10523. parseOpen(node) {
  10524. if (node.name === 'hyperlink') {
  10525. this.model = {
  10526. address: node.attributes.ref,
  10527. rId: node.attributes['r:id'],
  10528. tooltip: node.attributes.tooltip
  10529. };
  10530. // This is an internal link
  10531. if (node.attributes.location) {
  10532. this.model.target = node.attributes.location;
  10533. }
  10534. return true;
  10535. }
  10536. return false;
  10537. }
  10538. parseText() {}
  10539. parseClose() {
  10540. return false;
  10541. }
  10542. isInternalLink(model) {
  10543. // @example: Sheet2!D3, return true
  10544. return model.target && /^[^!]+![a-zA-Z]+[\d]+$/.test(model.target);
  10545. }
  10546. }
  10547. module.exports = HyperlinkXform;
  10548. },{"../base-xform":32}],99:[function(require,module,exports){
  10549. "use strict";
  10550. const BaseXform = require('../base-xform');
  10551. class MergeCellXform extends BaseXform {
  10552. get tag() {
  10553. return 'mergeCell';
  10554. }
  10555. render(xmlStream, model) {
  10556. xmlStream.leafNode('mergeCell', {
  10557. ref: model
  10558. });
  10559. }
  10560. parseOpen(node) {
  10561. if (node.name === 'mergeCell') {
  10562. this.model = node.attributes.ref;
  10563. return true;
  10564. }
  10565. return false;
  10566. }
  10567. parseText() {}
  10568. parseClose() {
  10569. return false;
  10570. }
  10571. }
  10572. module.exports = MergeCellXform;
  10573. },{"../base-xform":32}],100:[function(require,module,exports){
  10574. "use strict";
  10575. const _ = require('../../../utils/under-dash');
  10576. const Range = require('../../../doc/range');
  10577. const colCache = require('../../../utils/col-cache');
  10578. const Enums = require('../../../doc/enums');
  10579. class Merges {
  10580. constructor() {
  10581. // optional mergeCells is array of ranges (like the xml)
  10582. this.merges = {};
  10583. }
  10584. add(merge) {
  10585. // merge is {address, master}
  10586. if (this.merges[merge.master]) {
  10587. this.merges[merge.master].expandToAddress(merge.address);
  10588. } else {
  10589. const range = `${merge.master}:${merge.address}`;
  10590. this.merges[merge.master] = new Range(range);
  10591. }
  10592. }
  10593. get mergeCells() {
  10594. return _.map(this.merges, merge => merge.range);
  10595. }
  10596. reconcile(mergeCells, rows) {
  10597. // reconcile merge list with merge cells
  10598. _.each(mergeCells, merge => {
  10599. const dimensions = colCache.decode(merge);
  10600. for (let i = dimensions.top; i <= dimensions.bottom; i++) {
  10601. const row = rows[i - 1];
  10602. for (let j = dimensions.left; j <= dimensions.right; j++) {
  10603. const cell = row.cells[j - 1];
  10604. if (!cell) {
  10605. // nulls are not included in document - so if master cell has no value - add a null one here
  10606. row.cells[j] = {
  10607. type: Enums.ValueType.Null,
  10608. address: colCache.encodeAddress(i, j)
  10609. };
  10610. } else if (cell.type === Enums.ValueType.Merge) {
  10611. cell.master = dimensions.tl;
  10612. }
  10613. }
  10614. }
  10615. });
  10616. }
  10617. getMasterAddress(address) {
  10618. // if address has been merged, return its master's address. Assumes reconcile has been called
  10619. const range = this.hash[address];
  10620. return range && range.tl;
  10621. }
  10622. }
  10623. module.exports = Merges;
  10624. },{"../../../doc/enums":7,"../../../doc/range":10,"../../../utils/col-cache":19,"../../../utils/under-dash":26}],101:[function(require,module,exports){
  10625. "use strict";
  10626. const BaseXform = require('../base-xform');
  10627. const isDefined = attr => typeof attr !== 'undefined';
  10628. class OutlinePropertiesXform extends BaseXform {
  10629. get tag() {
  10630. return 'outlinePr';
  10631. }
  10632. render(xmlStream, model) {
  10633. if (model && (isDefined(model.summaryBelow) || isDefined(model.summaryRight))) {
  10634. xmlStream.leafNode(this.tag, {
  10635. summaryBelow: isDefined(model.summaryBelow) ? Number(model.summaryBelow) : undefined,
  10636. summaryRight: isDefined(model.summaryRight) ? Number(model.summaryRight) : undefined
  10637. });
  10638. return true;
  10639. }
  10640. return false;
  10641. }
  10642. parseOpen(node) {
  10643. if (node.name === this.tag) {
  10644. this.model = {
  10645. summaryBelow: isDefined(node.attributes.summaryBelow) ? Boolean(Number(node.attributes.summaryBelow)) : undefined,
  10646. summaryRight: isDefined(node.attributes.summaryRight) ? Boolean(Number(node.attributes.summaryRight)) : undefined
  10647. };
  10648. return true;
  10649. }
  10650. return false;
  10651. }
  10652. parseText() {}
  10653. parseClose() {
  10654. return false;
  10655. }
  10656. }
  10657. module.exports = OutlinePropertiesXform;
  10658. },{"../base-xform":32}],102:[function(require,module,exports){
  10659. "use strict";
  10660. const BaseXform = require('../base-xform');
  10661. class PageBreaksXform extends BaseXform {
  10662. get tag() {
  10663. return 'brk';
  10664. }
  10665. render(xmlStream, model) {
  10666. xmlStream.leafNode('brk', model);
  10667. }
  10668. parseOpen(node) {
  10669. if (node.name === 'brk') {
  10670. this.model = node.attributes.ref;
  10671. return true;
  10672. }
  10673. return false;
  10674. }
  10675. parseText() {}
  10676. parseClose() {
  10677. return false;
  10678. }
  10679. }
  10680. module.exports = PageBreaksXform;
  10681. },{"../base-xform":32}],103:[function(require,module,exports){
  10682. "use strict";
  10683. const _ = require('../../../utils/under-dash');
  10684. const BaseXform = require('../base-xform');
  10685. class PageMarginsXform extends BaseXform {
  10686. get tag() {
  10687. return 'pageMargins';
  10688. }
  10689. render(xmlStream, model) {
  10690. if (model) {
  10691. const attributes = {
  10692. left: model.left,
  10693. right: model.right,
  10694. top: model.top,
  10695. bottom: model.bottom,
  10696. header: model.header,
  10697. footer: model.footer
  10698. };
  10699. if (_.some(attributes, value => value !== undefined)) {
  10700. xmlStream.leafNode(this.tag, attributes);
  10701. }
  10702. }
  10703. }
  10704. parseOpen(node) {
  10705. switch (node.name) {
  10706. case this.tag:
  10707. this.model = {
  10708. left: parseFloat(node.attributes.left || 0.7),
  10709. right: parseFloat(node.attributes.right || 0.7),
  10710. top: parseFloat(node.attributes.top || 0.75),
  10711. bottom: parseFloat(node.attributes.bottom || 0.75),
  10712. header: parseFloat(node.attributes.header || 0.3),
  10713. footer: parseFloat(node.attributes.footer || 0.3)
  10714. };
  10715. return true;
  10716. default:
  10717. return false;
  10718. }
  10719. }
  10720. parseText() {}
  10721. parseClose() {
  10722. return false;
  10723. }
  10724. }
  10725. module.exports = PageMarginsXform;
  10726. },{"../../../utils/under-dash":26,"../base-xform":32}],104:[function(require,module,exports){
  10727. "use strict";
  10728. const BaseXform = require('../base-xform');
  10729. class PageSetupPropertiesXform extends BaseXform {
  10730. get tag() {
  10731. return 'pageSetUpPr';
  10732. }
  10733. render(xmlStream, model) {
  10734. if (model && model.fitToPage) {
  10735. xmlStream.leafNode(this.tag, {
  10736. fitToPage: model.fitToPage ? '1' : undefined
  10737. });
  10738. return true;
  10739. }
  10740. return false;
  10741. }
  10742. parseOpen(node) {
  10743. if (node.name === this.tag) {
  10744. this.model = {
  10745. fitToPage: node.attributes.fitToPage === '1'
  10746. };
  10747. return true;
  10748. }
  10749. return false;
  10750. }
  10751. parseText() {}
  10752. parseClose() {
  10753. return false;
  10754. }
  10755. }
  10756. module.exports = PageSetupPropertiesXform;
  10757. },{"../base-xform":32}],105:[function(require,module,exports){
  10758. "use strict";
  10759. const _ = require('../../../utils/under-dash');
  10760. const BaseXform = require('../base-xform');
  10761. function booleanToXml(model) {
  10762. return model ? '1' : undefined;
  10763. }
  10764. function pageOrderToXml(model) {
  10765. switch (model) {
  10766. case 'overThenDown':
  10767. return model;
  10768. default:
  10769. return undefined;
  10770. }
  10771. }
  10772. function cellCommentsToXml(model) {
  10773. switch (model) {
  10774. case 'atEnd':
  10775. case 'asDisplyed':
  10776. return model;
  10777. default:
  10778. return undefined;
  10779. }
  10780. }
  10781. function errorsToXml(model) {
  10782. switch (model) {
  10783. case 'dash':
  10784. case 'blank':
  10785. case 'NA':
  10786. return model;
  10787. default:
  10788. return undefined;
  10789. }
  10790. }
  10791. function pageSizeToModel(value) {
  10792. return value !== undefined ? parseInt(value, 10) : undefined;
  10793. }
  10794. class PageSetupXform extends BaseXform {
  10795. get tag() {
  10796. return 'pageSetup';
  10797. }
  10798. render(xmlStream, model) {
  10799. if (model) {
  10800. const attributes = {
  10801. paperSize: model.paperSize,
  10802. orientation: model.orientation,
  10803. horizontalDpi: model.horizontalDpi,
  10804. verticalDpi: model.verticalDpi,
  10805. pageOrder: pageOrderToXml(model.pageOrder),
  10806. blackAndWhite: booleanToXml(model.blackAndWhite),
  10807. draft: booleanToXml(model.draft),
  10808. cellComments: cellCommentsToXml(model.cellComments),
  10809. errors: errorsToXml(model.errors),
  10810. scale: model.scale,
  10811. fitToWidth: model.fitToWidth,
  10812. fitToHeight: model.fitToHeight,
  10813. firstPageNumber: model.firstPageNumber,
  10814. useFirstPageNumber: booleanToXml(model.firstPageNumber),
  10815. usePrinterDefaults: booleanToXml(model.usePrinterDefaults),
  10816. copies: model.copies
  10817. };
  10818. if (_.some(attributes, value => value !== undefined)) {
  10819. xmlStream.leafNode(this.tag, attributes);
  10820. }
  10821. }
  10822. }
  10823. parseOpen(node) {
  10824. switch (node.name) {
  10825. case this.tag:
  10826. this.model = {
  10827. paperSize: pageSizeToModel(node.attributes.paperSize),
  10828. orientation: node.attributes.orientation || 'portrait',
  10829. horizontalDpi: parseInt(node.attributes.horizontalDpi || '4294967295', 10),
  10830. verticalDpi: parseInt(node.attributes.verticalDpi || '4294967295', 10),
  10831. pageOrder: node.attributes.pageOrder || 'downThenOver',
  10832. blackAndWhite: node.attributes.blackAndWhite === '1',
  10833. draft: node.attributes.draft === '1',
  10834. cellComments: node.attributes.cellComments || 'None',
  10835. errors: node.attributes.errors || 'displayed',
  10836. scale: parseInt(node.attributes.scale || '100', 10),
  10837. fitToWidth: parseInt(node.attributes.fitToWidth || '1', 10),
  10838. fitToHeight: parseInt(node.attributes.fitToHeight || '1', 10),
  10839. firstPageNumber: parseInt(node.attributes.firstPageNumber || '1', 10),
  10840. useFirstPageNumber: node.attributes.useFirstPageNumber === '1',
  10841. usePrinterDefaults: node.attributes.usePrinterDefaults === '1',
  10842. copies: parseInt(node.attributes.copies || '1', 10)
  10843. };
  10844. return true;
  10845. default:
  10846. return false;
  10847. }
  10848. }
  10849. parseText() {}
  10850. parseClose() {
  10851. return false;
  10852. }
  10853. }
  10854. module.exports = PageSetupXform;
  10855. },{"../../../utils/under-dash":26,"../base-xform":32}],106:[function(require,module,exports){
  10856. "use strict";
  10857. const BaseXform = require('../base-xform');
  10858. class PictureXform extends BaseXform {
  10859. get tag() {
  10860. return 'picture';
  10861. }
  10862. render(xmlStream, model) {
  10863. if (model) {
  10864. xmlStream.leafNode(this.tag, {
  10865. 'r:id': model.rId
  10866. });
  10867. }
  10868. }
  10869. parseOpen(node) {
  10870. switch (node.name) {
  10871. case this.tag:
  10872. this.model = {
  10873. rId: node.attributes['r:id']
  10874. };
  10875. return true;
  10876. default:
  10877. return false;
  10878. }
  10879. }
  10880. parseText() {}
  10881. parseClose() {
  10882. return false;
  10883. }
  10884. }
  10885. module.exports = PictureXform;
  10886. },{"../base-xform":32}],107:[function(require,module,exports){
  10887. "use strict";
  10888. const _ = require('../../../utils/under-dash');
  10889. const BaseXform = require('../base-xform');
  10890. function booleanToXml(model) {
  10891. return model ? '1' : undefined;
  10892. }
  10893. class PrintOptionsXform extends BaseXform {
  10894. get tag() {
  10895. return 'printOptions';
  10896. }
  10897. render(xmlStream, model) {
  10898. if (model) {
  10899. const attributes = {
  10900. headings: booleanToXml(model.showRowColHeaders),
  10901. gridLines: booleanToXml(model.showGridLines),
  10902. horizontalCentered: booleanToXml(model.horizontalCentered),
  10903. verticalCentered: booleanToXml(model.verticalCentered)
  10904. };
  10905. if (_.some(attributes, value => value !== undefined)) {
  10906. xmlStream.leafNode(this.tag, attributes);
  10907. }
  10908. }
  10909. }
  10910. parseOpen(node) {
  10911. switch (node.name) {
  10912. case this.tag:
  10913. this.model = {
  10914. showRowColHeaders: node.attributes.headings === '1',
  10915. showGridLines: node.attributes.gridLines === '1',
  10916. horizontalCentered: node.attributes.horizontalCentered === '1',
  10917. verticalCentered: node.attributes.verticalCentered === '1'
  10918. };
  10919. return true;
  10920. default:
  10921. return false;
  10922. }
  10923. }
  10924. parseText() {}
  10925. parseClose() {
  10926. return false;
  10927. }
  10928. }
  10929. module.exports = PrintOptionsXform;
  10930. },{"../../../utils/under-dash":26,"../base-xform":32}],108:[function(require,module,exports){
  10931. 'use strict';
  10932. const PageBreaksXform = require('./page-breaks-xform');
  10933. const ListXform = require('../list-xform');
  10934. class RowBreaksXform extends ListXform {
  10935. constructor() {
  10936. const options = {
  10937. tag: 'rowBreaks',
  10938. count: true,
  10939. childXform: new PageBreaksXform()
  10940. };
  10941. super(options);
  10942. }
  10943. // get tag() { return 'rowBreaks'; }
  10944. render(xmlStream, model) {
  10945. if (model && model.length) {
  10946. xmlStream.openNode(this.tag, this.$);
  10947. if (this.count) {
  10948. xmlStream.addAttribute(this.$count, model.length);
  10949. xmlStream.addAttribute('manualBreakCount', model.length);
  10950. }
  10951. const {
  10952. childXform
  10953. } = this;
  10954. model.forEach(childModel => {
  10955. childXform.render(xmlStream, childModel);
  10956. });
  10957. xmlStream.closeNode();
  10958. } else if (this.empty) {
  10959. xmlStream.leafNode(this.tag);
  10960. }
  10961. }
  10962. }
  10963. module.exports = RowBreaksXform;
  10964. },{"../list-xform":71,"./page-breaks-xform":102}],109:[function(require,module,exports){
  10965. "use strict";
  10966. const BaseXform = require('../base-xform');
  10967. const utils = require('../../../utils/utils');
  10968. const CellXform = require('./cell-xform');
  10969. class RowXform extends BaseXform {
  10970. constructor(options) {
  10971. super();
  10972. this.maxItems = options && options.maxItems;
  10973. this.map = {
  10974. c: new CellXform()
  10975. };
  10976. }
  10977. get tag() {
  10978. return 'row';
  10979. }
  10980. prepare(model, options) {
  10981. const styleId = options.styles.addStyleModel(model.style);
  10982. if (styleId) {
  10983. model.styleId = styleId;
  10984. }
  10985. const cellXform = this.map.c;
  10986. model.cells.forEach(cellModel => {
  10987. cellXform.prepare(cellModel, options);
  10988. });
  10989. }
  10990. render(xmlStream, model, options) {
  10991. xmlStream.openNode('row');
  10992. xmlStream.addAttribute('r', model.number);
  10993. if (model.height) {
  10994. xmlStream.addAttribute('ht', model.height);
  10995. xmlStream.addAttribute('customHeight', '1');
  10996. }
  10997. if (model.hidden) {
  10998. xmlStream.addAttribute('hidden', '1');
  10999. }
  11000. if (model.min > 0 && model.max > 0 && model.min <= model.max) {
  11001. xmlStream.addAttribute('spans', `${model.min}:${model.max}`);
  11002. }
  11003. if (model.styleId) {
  11004. xmlStream.addAttribute('s', model.styleId);
  11005. xmlStream.addAttribute('customFormat', '1');
  11006. }
  11007. xmlStream.addAttribute('x14ac:dyDescent', '0.25');
  11008. if (model.outlineLevel) {
  11009. xmlStream.addAttribute('outlineLevel', model.outlineLevel);
  11010. }
  11011. if (model.collapsed) {
  11012. xmlStream.addAttribute('collapsed', '1');
  11013. }
  11014. const cellXform = this.map.c;
  11015. model.cells.forEach(cellModel => {
  11016. cellXform.render(xmlStream, cellModel, options);
  11017. });
  11018. xmlStream.closeNode();
  11019. }
  11020. parseOpen(node) {
  11021. if (this.parser) {
  11022. this.parser.parseOpen(node);
  11023. return true;
  11024. }
  11025. if (node.name === 'row') {
  11026. this.numRowsSeen += 1;
  11027. const spans = node.attributes.spans ? node.attributes.spans.split(':').map(span => parseInt(span, 10)) : [undefined, undefined];
  11028. const model = this.model = {
  11029. number: parseInt(node.attributes.r, 10),
  11030. min: spans[0],
  11031. max: spans[1],
  11032. cells: []
  11033. };
  11034. if (node.attributes.s) {
  11035. model.styleId = parseInt(node.attributes.s, 10);
  11036. }
  11037. if (utils.parseBoolean(node.attributes.hidden)) {
  11038. model.hidden = true;
  11039. }
  11040. if (utils.parseBoolean(node.attributes.bestFit)) {
  11041. model.bestFit = true;
  11042. }
  11043. if (node.attributes.ht) {
  11044. model.height = parseFloat(node.attributes.ht);
  11045. }
  11046. if (node.attributes.outlineLevel) {
  11047. model.outlineLevel = parseInt(node.attributes.outlineLevel, 10);
  11048. }
  11049. if (utils.parseBoolean(node.attributes.collapsed)) {
  11050. model.collapsed = true;
  11051. }
  11052. return true;
  11053. }
  11054. this.parser = this.map[node.name];
  11055. if (this.parser) {
  11056. this.parser.parseOpen(node);
  11057. return true;
  11058. }
  11059. return false;
  11060. }
  11061. parseText(text) {
  11062. if (this.parser) {
  11063. this.parser.parseText(text);
  11064. }
  11065. }
  11066. parseClose(name) {
  11067. if (this.parser) {
  11068. if (!this.parser.parseClose(name)) {
  11069. this.model.cells.push(this.parser.model);
  11070. if (this.maxItems && this.model.cells.length > this.maxItems) {
  11071. throw new Error(`Max column count (${this.maxItems}) exceeded`);
  11072. }
  11073. this.parser = undefined;
  11074. }
  11075. return true;
  11076. }
  11077. return false;
  11078. }
  11079. reconcile(model, options) {
  11080. model.style = model.styleId ? options.styles.getStyleModel(model.styleId) : {};
  11081. if (model.styleId !== undefined) {
  11082. model.styleId = undefined;
  11083. }
  11084. const cellXform = this.map.c;
  11085. model.cells.forEach(cellModel => {
  11086. cellXform.reconcile(cellModel, options);
  11087. });
  11088. }
  11089. }
  11090. module.exports = RowXform;
  11091. },{"../../../utils/utils":27,"../base-xform":32,"./cell-xform":73}],110:[function(require,module,exports){
  11092. "use strict";
  11093. const _ = require('../../../utils/under-dash');
  11094. const BaseXform = require('../base-xform');
  11095. class SheetFormatPropertiesXform extends BaseXform {
  11096. get tag() {
  11097. return 'sheetFormatPr';
  11098. }
  11099. render(xmlStream, model) {
  11100. if (model) {
  11101. const attributes = {
  11102. defaultRowHeight: model.defaultRowHeight,
  11103. outlineLevelRow: model.outlineLevelRow,
  11104. outlineLevelCol: model.outlineLevelCol,
  11105. 'x14ac:dyDescent': model.dyDescent
  11106. };
  11107. if (model.defaultColWidth) {
  11108. attributes.defaultColWidth = model.defaultColWidth;
  11109. }
  11110. // default value for 'defaultRowHeight' is 15, this should not be 'custom'
  11111. if (!model.defaultRowHeight || model.defaultRowHeight !== 15) {
  11112. attributes.customHeight = '1';
  11113. }
  11114. if (_.some(attributes, value => value !== undefined)) {
  11115. xmlStream.leafNode('sheetFormatPr', attributes);
  11116. }
  11117. }
  11118. }
  11119. parseOpen(node) {
  11120. if (node.name === 'sheetFormatPr') {
  11121. this.model = {
  11122. defaultRowHeight: parseFloat(node.attributes.defaultRowHeight || '0'),
  11123. dyDescent: parseFloat(node.attributes['x14ac:dyDescent'] || '0'),
  11124. outlineLevelRow: parseInt(node.attributes.outlineLevelRow || '0', 10),
  11125. outlineLevelCol: parseInt(node.attributes.outlineLevelCol || '0', 10)
  11126. };
  11127. if (node.attributes.defaultColWidth) {
  11128. this.model.defaultColWidth = parseFloat(node.attributes.defaultColWidth);
  11129. }
  11130. return true;
  11131. }
  11132. return false;
  11133. }
  11134. parseText() {}
  11135. parseClose() {
  11136. return false;
  11137. }
  11138. }
  11139. module.exports = SheetFormatPropertiesXform;
  11140. },{"../../../utils/under-dash":26,"../base-xform":32}],111:[function(require,module,exports){
  11141. "use strict";
  11142. const BaseXform = require('../base-xform');
  11143. const ColorXform = require('../style/color-xform');
  11144. const PageSetupPropertiesXform = require('./page-setup-properties-xform');
  11145. const OutlinePropertiesXform = require('./outline-properties-xform');
  11146. class SheetPropertiesXform extends BaseXform {
  11147. constructor() {
  11148. super();
  11149. this.map = {
  11150. tabColor: new ColorXform('tabColor'),
  11151. pageSetUpPr: new PageSetupPropertiesXform(),
  11152. outlinePr: new OutlinePropertiesXform()
  11153. };
  11154. }
  11155. get tag() {
  11156. return 'sheetPr';
  11157. }
  11158. render(xmlStream, model) {
  11159. if (model) {
  11160. xmlStream.addRollback();
  11161. xmlStream.openNode('sheetPr');
  11162. let inner = false;
  11163. inner = this.map.tabColor.render(xmlStream, model.tabColor) || inner;
  11164. inner = this.map.pageSetUpPr.render(xmlStream, model.pageSetup) || inner;
  11165. inner = this.map.outlinePr.render(xmlStream, model.outlineProperties) || inner;
  11166. if (inner) {
  11167. xmlStream.closeNode();
  11168. xmlStream.commit();
  11169. } else {
  11170. xmlStream.rollback();
  11171. }
  11172. }
  11173. }
  11174. parseOpen(node) {
  11175. if (this.parser) {
  11176. this.parser.parseOpen(node);
  11177. return true;
  11178. }
  11179. if (node.name === this.tag) {
  11180. this.reset();
  11181. return true;
  11182. }
  11183. if (this.map[node.name]) {
  11184. this.parser = this.map[node.name];
  11185. this.parser.parseOpen(node);
  11186. return true;
  11187. }
  11188. return false;
  11189. }
  11190. parseText(text) {
  11191. if (this.parser) {
  11192. this.parser.parseText(text);
  11193. return true;
  11194. }
  11195. return false;
  11196. }
  11197. parseClose(name) {
  11198. if (this.parser) {
  11199. if (!this.parser.parseClose(name)) {
  11200. this.parser = undefined;
  11201. }
  11202. return true;
  11203. }
  11204. if (this.map.tabColor.model || this.map.pageSetUpPr.model || this.map.outlinePr.model) {
  11205. this.model = {};
  11206. if (this.map.tabColor.model) {
  11207. this.model.tabColor = this.map.tabColor.model;
  11208. }
  11209. if (this.map.pageSetUpPr.model) {
  11210. this.model.pageSetup = this.map.pageSetUpPr.model;
  11211. }
  11212. if (this.map.outlinePr.model) {
  11213. this.model.outlineProperties = this.map.outlinePr.model;
  11214. }
  11215. } else {
  11216. this.model = null;
  11217. }
  11218. return false;
  11219. }
  11220. }
  11221. module.exports = SheetPropertiesXform;
  11222. },{"../base-xform":32,"../style/color-xform":128,"./outline-properties-xform":101,"./page-setup-properties-xform":104}],112:[function(require,module,exports){
  11223. "use strict";
  11224. const _ = require('../../../utils/under-dash');
  11225. const BaseXform = require('../base-xform');
  11226. function booleanToXml(model, value) {
  11227. return model ? value : undefined;
  11228. }
  11229. function xmlToBoolean(value, equals) {
  11230. return value === equals ? true : undefined;
  11231. }
  11232. class SheetProtectionXform extends BaseXform {
  11233. get tag() {
  11234. return 'sheetProtection';
  11235. }
  11236. render(xmlStream, model) {
  11237. if (model) {
  11238. const attributes = {
  11239. sheet: booleanToXml(model.sheet, '1'),
  11240. selectLockedCells: model.selectLockedCells === false ? '1' : undefined,
  11241. selectUnlockedCells: model.selectUnlockedCells === false ? '1' : undefined,
  11242. formatCells: booleanToXml(model.formatCells, '0'),
  11243. formatColumns: booleanToXml(model.formatColumns, '0'),
  11244. formatRows: booleanToXml(model.formatRows, '0'),
  11245. insertColumns: booleanToXml(model.insertColumns, '0'),
  11246. insertRows: booleanToXml(model.insertRows, '0'),
  11247. insertHyperlinks: booleanToXml(model.insertHyperlinks, '0'),
  11248. deleteColumns: booleanToXml(model.deleteColumns, '0'),
  11249. deleteRows: booleanToXml(model.deleteRows, '0'),
  11250. sort: booleanToXml(model.sort, '0'),
  11251. autoFilter: booleanToXml(model.autoFilter, '0'),
  11252. pivotTables: booleanToXml(model.pivotTables, '0')
  11253. };
  11254. if (model.sheet) {
  11255. attributes.algorithmName = model.algorithmName;
  11256. attributes.hashValue = model.hashValue;
  11257. attributes.saltValue = model.saltValue;
  11258. attributes.spinCount = model.spinCount;
  11259. attributes.objects = booleanToXml(model.objects === false, '1');
  11260. attributes.scenarios = booleanToXml(model.scenarios === false, '1');
  11261. }
  11262. if (_.some(attributes, value => value !== undefined)) {
  11263. xmlStream.leafNode(this.tag, attributes);
  11264. }
  11265. }
  11266. }
  11267. parseOpen(node) {
  11268. switch (node.name) {
  11269. case this.tag:
  11270. this.model = {
  11271. sheet: xmlToBoolean(node.attributes.sheet, '1'),
  11272. objects: node.attributes.objects === '1' ? false : undefined,
  11273. scenarios: node.attributes.scenarios === '1' ? false : undefined,
  11274. selectLockedCells: node.attributes.selectLockedCells === '1' ? false : undefined,
  11275. selectUnlockedCells: node.attributes.selectUnlockedCells === '1' ? false : undefined,
  11276. formatCells: xmlToBoolean(node.attributes.formatCells, '0'),
  11277. formatColumns: xmlToBoolean(node.attributes.formatColumns, '0'),
  11278. formatRows: xmlToBoolean(node.attributes.formatRows, '0'),
  11279. insertColumns: xmlToBoolean(node.attributes.insertColumns, '0'),
  11280. insertRows: xmlToBoolean(node.attributes.insertRows, '0'),
  11281. insertHyperlinks: xmlToBoolean(node.attributes.insertHyperlinks, '0'),
  11282. deleteColumns: xmlToBoolean(node.attributes.deleteColumns, '0'),
  11283. deleteRows: xmlToBoolean(node.attributes.deleteRows, '0'),
  11284. sort: xmlToBoolean(node.attributes.sort, '0'),
  11285. autoFilter: xmlToBoolean(node.attributes.autoFilter, '0'),
  11286. pivotTables: xmlToBoolean(node.attributes.pivotTables, '0')
  11287. };
  11288. if (node.attributes.algorithmName) {
  11289. this.model.algorithmName = node.attributes.algorithmName;
  11290. this.model.hashValue = node.attributes.hashValue;
  11291. this.model.saltValue = node.attributes.saltValue;
  11292. this.model.spinCount = parseInt(node.attributes.spinCount, 10);
  11293. }
  11294. return true;
  11295. default:
  11296. return false;
  11297. }
  11298. }
  11299. parseText() {}
  11300. parseClose() {
  11301. return false;
  11302. }
  11303. }
  11304. module.exports = SheetProtectionXform;
  11305. },{"../../../utils/under-dash":26,"../base-xform":32}],113:[function(require,module,exports){
  11306. "use strict";
  11307. const colCache = require('../../../utils/col-cache');
  11308. const BaseXform = require('../base-xform');
  11309. const VIEW_STATES = {
  11310. frozen: 'frozen',
  11311. frozenSplit: 'frozen',
  11312. split: 'split'
  11313. };
  11314. class SheetViewXform extends BaseXform {
  11315. get tag() {
  11316. return 'sheetView';
  11317. }
  11318. prepare(model) {
  11319. switch (model.state) {
  11320. case 'frozen':
  11321. case 'split':
  11322. break;
  11323. default:
  11324. model.state = 'normal';
  11325. break;
  11326. }
  11327. }
  11328. render(xmlStream, model) {
  11329. xmlStream.openNode('sheetView', {
  11330. workbookViewId: model.workbookViewId || 0
  11331. });
  11332. const add = function (name, value, included) {
  11333. if (included) {
  11334. xmlStream.addAttribute(name, value);
  11335. }
  11336. };
  11337. add('rightToLeft', '1', model.rightToLeft === true);
  11338. add('tabSelected', '1', model.tabSelected);
  11339. add('showRuler', '0', model.showRuler === false);
  11340. add('showRowColHeaders', '0', model.showRowColHeaders === false);
  11341. add('showGridLines', '0', model.showGridLines === false);
  11342. add('zoomScale', model.zoomScale, model.zoomScale);
  11343. add('zoomScaleNormal', model.zoomScaleNormal, model.zoomScaleNormal);
  11344. add('view', model.style, model.style);
  11345. let topLeftCell;
  11346. let xSplit;
  11347. let ySplit;
  11348. let activePane;
  11349. switch (model.state) {
  11350. case 'frozen':
  11351. xSplit = model.xSplit || 0;
  11352. ySplit = model.ySplit || 0;
  11353. topLeftCell = model.topLeftCell || colCache.getAddress(ySplit + 1, xSplit + 1).address;
  11354. activePane = model.xSplit && model.ySplit && 'bottomRight' || model.xSplit && 'topRight' || 'bottomLeft';
  11355. xmlStream.leafNode('pane', {
  11356. xSplit: model.xSplit || undefined,
  11357. ySplit: model.ySplit || undefined,
  11358. topLeftCell,
  11359. activePane,
  11360. state: 'frozen'
  11361. });
  11362. xmlStream.leafNode('selection', {
  11363. pane: activePane,
  11364. activeCell: model.activeCell,
  11365. sqref: model.activeCell
  11366. });
  11367. break;
  11368. case 'split':
  11369. if (model.activePane === 'topLeft') {
  11370. model.activePane = undefined;
  11371. }
  11372. xmlStream.leafNode('pane', {
  11373. xSplit: model.xSplit || undefined,
  11374. ySplit: model.ySplit || undefined,
  11375. topLeftCell: model.topLeftCell,
  11376. activePane: model.activePane
  11377. });
  11378. xmlStream.leafNode('selection', {
  11379. pane: model.activePane,
  11380. activeCell: model.activeCell,
  11381. sqref: model.activeCell
  11382. });
  11383. break;
  11384. case 'normal':
  11385. if (model.activeCell) {
  11386. xmlStream.leafNode('selection', {
  11387. activeCell: model.activeCell,
  11388. sqref: model.activeCell
  11389. });
  11390. }
  11391. break;
  11392. default:
  11393. break;
  11394. }
  11395. xmlStream.closeNode();
  11396. }
  11397. parseOpen(node) {
  11398. switch (node.name) {
  11399. case 'sheetView':
  11400. this.sheetView = {
  11401. workbookViewId: parseInt(node.attributes.workbookViewId, 10),
  11402. rightToLeft: node.attributes.rightToLeft === '1',
  11403. tabSelected: node.attributes.tabSelected === '1',
  11404. showRuler: !(node.attributes.showRuler === '0'),
  11405. showRowColHeaders: !(node.attributes.showRowColHeaders === '0'),
  11406. showGridLines: !(node.attributes.showGridLines === '0'),
  11407. zoomScale: parseInt(node.attributes.zoomScale || '100', 10),
  11408. zoomScaleNormal: parseInt(node.attributes.zoomScaleNormal || '100', 10),
  11409. style: node.attributes.view
  11410. };
  11411. this.pane = undefined;
  11412. this.selections = {};
  11413. return true;
  11414. case 'pane':
  11415. this.pane = {
  11416. xSplit: parseInt(node.attributes.xSplit || '0', 10),
  11417. ySplit: parseInt(node.attributes.ySplit || '0', 10),
  11418. topLeftCell: node.attributes.topLeftCell,
  11419. activePane: node.attributes.activePane || 'topLeft',
  11420. state: node.attributes.state
  11421. };
  11422. return true;
  11423. case 'selection':
  11424. {
  11425. const name = node.attributes.pane || 'topLeft';
  11426. this.selections[name] = {
  11427. pane: name,
  11428. activeCell: node.attributes.activeCell
  11429. };
  11430. return true;
  11431. }
  11432. default:
  11433. return false;
  11434. }
  11435. }
  11436. parseText() {}
  11437. parseClose(name) {
  11438. let model;
  11439. let selection;
  11440. switch (name) {
  11441. case 'sheetView':
  11442. if (this.sheetView && this.pane) {
  11443. model = this.model = {
  11444. workbookViewId: this.sheetView.workbookViewId,
  11445. rightToLeft: this.sheetView.rightToLeft,
  11446. state: VIEW_STATES[this.pane.state] || 'split',
  11447. // split is default
  11448. xSplit: this.pane.xSplit,
  11449. ySplit: this.pane.ySplit,
  11450. topLeftCell: this.pane.topLeftCell,
  11451. showRuler: this.sheetView.showRuler,
  11452. showRowColHeaders: this.sheetView.showRowColHeaders,
  11453. showGridLines: this.sheetView.showGridLines,
  11454. zoomScale: this.sheetView.zoomScale,
  11455. zoomScaleNormal: this.sheetView.zoomScaleNormal
  11456. };
  11457. if (this.model.state === 'split') {
  11458. model.activePane = this.pane.activePane;
  11459. }
  11460. selection = this.selections[this.pane.activePane];
  11461. if (selection && selection.activeCell) {
  11462. model.activeCell = selection.activeCell;
  11463. }
  11464. if (this.sheetView.style) {
  11465. model.style = this.sheetView.style;
  11466. }
  11467. } else {
  11468. model = this.model = {
  11469. workbookViewId: this.sheetView.workbookViewId,
  11470. rightToLeft: this.sheetView.rightToLeft,
  11471. state: 'normal',
  11472. showRuler: this.sheetView.showRuler,
  11473. showRowColHeaders: this.sheetView.showRowColHeaders,
  11474. showGridLines: this.sheetView.showGridLines,
  11475. zoomScale: this.sheetView.zoomScale,
  11476. zoomScaleNormal: this.sheetView.zoomScaleNormal
  11477. };
  11478. selection = this.selections.topLeft;
  11479. if (selection && selection.activeCell) {
  11480. model.activeCell = selection.activeCell;
  11481. }
  11482. if (this.sheetView.style) {
  11483. model.style = this.sheetView.style;
  11484. }
  11485. }
  11486. return false;
  11487. default:
  11488. return true;
  11489. }
  11490. }
  11491. reconcile() {}
  11492. }
  11493. module.exports = SheetViewXform;
  11494. },{"../../../utils/col-cache":19,"../base-xform":32}],114:[function(require,module,exports){
  11495. "use strict";
  11496. const BaseXform = require('../base-xform');
  11497. class TablePartXform extends BaseXform {
  11498. get tag() {
  11499. return 'tablePart';
  11500. }
  11501. render(xmlStream, model) {
  11502. if (model) {
  11503. xmlStream.leafNode(this.tag, {
  11504. 'r:id': model.rId
  11505. });
  11506. }
  11507. }
  11508. parseOpen(node) {
  11509. switch (node.name) {
  11510. case this.tag:
  11511. this.model = {
  11512. rId: node.attributes['r:id']
  11513. };
  11514. return true;
  11515. default:
  11516. return false;
  11517. }
  11518. }
  11519. parseText() {}
  11520. parseClose() {
  11521. return false;
  11522. }
  11523. }
  11524. module.exports = TablePartXform;
  11525. },{"../base-xform":32}],115:[function(require,module,exports){
  11526. "use strict";
  11527. const _ = require('../../../utils/under-dash');
  11528. const colCache = require('../../../utils/col-cache');
  11529. const XmlStream = require('../../../utils/xml-stream');
  11530. const RelType = require('../../rel-type');
  11531. const Merges = require('./merges');
  11532. const BaseXform = require('../base-xform');
  11533. const ListXform = require('../list-xform');
  11534. const RowXform = require('./row-xform');
  11535. const ColXform = require('./col-xform');
  11536. const DimensionXform = require('./dimension-xform');
  11537. const HyperlinkXform = require('./hyperlink-xform');
  11538. const MergeCellXform = require('./merge-cell-xform');
  11539. const DataValidationsXform = require('./data-validations-xform');
  11540. const SheetPropertiesXform = require('./sheet-properties-xform');
  11541. const SheetFormatPropertiesXform = require('./sheet-format-properties-xform');
  11542. const SheetViewXform = require('./sheet-view-xform');
  11543. const SheetProtectionXform = require('./sheet-protection-xform');
  11544. const PageMarginsXform = require('./page-margins-xform');
  11545. const PageSetupXform = require('./page-setup-xform');
  11546. const PrintOptionsXform = require('./print-options-xform');
  11547. const AutoFilterXform = require('./auto-filter-xform');
  11548. const PictureXform = require('./picture-xform');
  11549. const DrawingXform = require('./drawing-xform');
  11550. const TablePartXform = require('./table-part-xform');
  11551. const RowBreaksXform = require('./row-breaks-xform');
  11552. const HeaderFooterXform = require('./header-footer-xform');
  11553. const ConditionalFormattingsXform = require('./cf/conditional-formattings-xform');
  11554. const ExtListXform = require('./ext-lst-xform');
  11555. const mergeRule = (rule, extRule) => {
  11556. Object.keys(extRule).forEach(key => {
  11557. const value = rule[key];
  11558. const extValue = extRule[key];
  11559. if (value === undefined && extValue !== undefined) {
  11560. rule[key] = extValue;
  11561. }
  11562. });
  11563. };
  11564. const mergeConditionalFormattings = (model, extModel) => {
  11565. // conditional formattings are rendered in worksheet.conditionalFormatting and also in
  11566. // worksheet.extLst.ext.x14:conditionalFormattings
  11567. // some (e.g. dataBar) are even spread across both!
  11568. if (!extModel || !extModel.length) {
  11569. return model;
  11570. }
  11571. if (!model || !model.length) {
  11572. return extModel;
  11573. }
  11574. // index model rules by x14Id
  11575. const cfMap = {};
  11576. const ruleMap = {};
  11577. model.forEach(cf => {
  11578. cfMap[cf.ref] = cf;
  11579. cf.rules.forEach(rule => {
  11580. const {
  11581. x14Id
  11582. } = rule;
  11583. if (x14Id) {
  11584. ruleMap[x14Id] = rule;
  11585. }
  11586. });
  11587. });
  11588. extModel.forEach(extCf => {
  11589. extCf.rules.forEach(extRule => {
  11590. const rule = ruleMap[extRule.x14Id];
  11591. if (rule) {
  11592. // merge with matching rule
  11593. mergeRule(rule, extRule);
  11594. } else if (cfMap[extCf.ref]) {
  11595. // reuse existing cf ref
  11596. cfMap[extCf.ref].rules.push(extRule);
  11597. } else {
  11598. // create new cf
  11599. model.push({
  11600. ref: extCf.ref,
  11601. rules: [extRule]
  11602. });
  11603. }
  11604. });
  11605. });
  11606. // need to cope with rules in extModel that don't exist in model
  11607. return model;
  11608. };
  11609. class WorkSheetXform extends BaseXform {
  11610. constructor(options) {
  11611. super();
  11612. const {
  11613. maxRows,
  11614. maxCols,
  11615. ignoreNodes
  11616. } = options || {};
  11617. this.ignoreNodes = ignoreNodes || [];
  11618. this.map = {
  11619. sheetPr: new SheetPropertiesXform(),
  11620. dimension: new DimensionXform(),
  11621. sheetViews: new ListXform({
  11622. tag: 'sheetViews',
  11623. count: false,
  11624. childXform: new SheetViewXform()
  11625. }),
  11626. sheetFormatPr: new SheetFormatPropertiesXform(),
  11627. cols: new ListXform({
  11628. tag: 'cols',
  11629. count: false,
  11630. childXform: new ColXform()
  11631. }),
  11632. sheetData: new ListXform({
  11633. tag: 'sheetData',
  11634. count: false,
  11635. empty: true,
  11636. childXform: new RowXform({
  11637. maxItems: maxCols
  11638. }),
  11639. maxItems: maxRows
  11640. }),
  11641. autoFilter: new AutoFilterXform(),
  11642. mergeCells: new ListXform({
  11643. tag: 'mergeCells',
  11644. count: true,
  11645. childXform: new MergeCellXform()
  11646. }),
  11647. rowBreaks: new RowBreaksXform(),
  11648. hyperlinks: new ListXform({
  11649. tag: 'hyperlinks',
  11650. count: false,
  11651. childXform: new HyperlinkXform()
  11652. }),
  11653. pageMargins: new PageMarginsXform(),
  11654. dataValidations: new DataValidationsXform(),
  11655. pageSetup: new PageSetupXform(),
  11656. headerFooter: new HeaderFooterXform(),
  11657. printOptions: new PrintOptionsXform(),
  11658. picture: new PictureXform(),
  11659. drawing: new DrawingXform(),
  11660. sheetProtection: new SheetProtectionXform(),
  11661. tableParts: new ListXform({
  11662. tag: 'tableParts',
  11663. count: true,
  11664. childXform: new TablePartXform()
  11665. }),
  11666. conditionalFormatting: new ConditionalFormattingsXform(),
  11667. extLst: new ExtListXform()
  11668. };
  11669. }
  11670. prepare(model, options) {
  11671. options.merges = new Merges();
  11672. model.hyperlinks = options.hyperlinks = [];
  11673. model.comments = options.comments = [];
  11674. options.formulae = {};
  11675. options.siFormulae = 0;
  11676. this.map.cols.prepare(model.cols, options);
  11677. this.map.sheetData.prepare(model.rows, options);
  11678. this.map.conditionalFormatting.prepare(model.conditionalFormattings, options);
  11679. model.mergeCells = options.merges.mergeCells;
  11680. // prepare relationships
  11681. const rels = model.rels = [];
  11682. function nextRid(r) {
  11683. return `rId${r.length + 1}`;
  11684. }
  11685. model.hyperlinks.forEach(hyperlink => {
  11686. const rId = nextRid(rels);
  11687. hyperlink.rId = rId;
  11688. rels.push({
  11689. Id: rId,
  11690. Type: RelType.Hyperlink,
  11691. Target: hyperlink.target,
  11692. TargetMode: 'External'
  11693. });
  11694. });
  11695. // prepare comment relationships
  11696. if (model.comments.length > 0) {
  11697. const comment = {
  11698. Id: nextRid(rels),
  11699. Type: RelType.Comments,
  11700. Target: `../comments${model.id}.xml`
  11701. };
  11702. rels.push(comment);
  11703. const vmlDrawing = {
  11704. Id: nextRid(rels),
  11705. Type: RelType.VmlDrawing,
  11706. Target: `../drawings/vmlDrawing${model.id}.vml`
  11707. };
  11708. rels.push(vmlDrawing);
  11709. model.comments.forEach(item => {
  11710. item.refAddress = colCache.decodeAddress(item.ref);
  11711. });
  11712. options.commentRefs.push({
  11713. commentName: `comments${model.id}`,
  11714. vmlDrawing: `vmlDrawing${model.id}`
  11715. });
  11716. }
  11717. const drawingRelsHash = [];
  11718. let bookImage;
  11719. model.media.forEach(medium => {
  11720. if (medium.type === 'background') {
  11721. const rId = nextRid(rels);
  11722. bookImage = options.media[medium.imageId];
  11723. rels.push({
  11724. Id: rId,
  11725. Type: RelType.Image,
  11726. Target: `../media/${bookImage.name}.${bookImage.extension}`
  11727. });
  11728. model.background = {
  11729. rId
  11730. };
  11731. model.image = options.media[medium.imageId];
  11732. } else if (medium.type === 'image') {
  11733. let {
  11734. drawing
  11735. } = model;
  11736. bookImage = options.media[medium.imageId];
  11737. if (!drawing) {
  11738. drawing = model.drawing = {
  11739. rId: nextRid(rels),
  11740. name: `drawing${++options.drawingsCount}`,
  11741. anchors: [],
  11742. rels: []
  11743. };
  11744. options.drawings.push(drawing);
  11745. rels.push({
  11746. Id: drawing.rId,
  11747. Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
  11748. Target: `../drawings/${drawing.name}.xml`
  11749. });
  11750. }
  11751. let rIdImage = this.preImageId === medium.imageId ? drawingRelsHash[medium.imageId] : drawingRelsHash[drawing.rels.length];
  11752. if (!rIdImage) {
  11753. rIdImage = nextRid(drawing.rels);
  11754. drawingRelsHash[drawing.rels.length] = rIdImage;
  11755. drawing.rels.push({
  11756. Id: rIdImage,
  11757. Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  11758. Target: `../media/${bookImage.name}.${bookImage.extension}`
  11759. });
  11760. }
  11761. const anchor = {
  11762. picture: {
  11763. rId: rIdImage
  11764. },
  11765. range: medium.range
  11766. };
  11767. if (medium.hyperlinks && medium.hyperlinks.hyperlink) {
  11768. const rIdHyperLink = nextRid(drawing.rels);
  11769. drawingRelsHash[drawing.rels.length] = rIdHyperLink;
  11770. anchor.picture.hyperlinks = {
  11771. tooltip: medium.hyperlinks.tooltip,
  11772. rId: rIdHyperLink
  11773. };
  11774. drawing.rels.push({
  11775. Id: rIdHyperLink,
  11776. Type: RelType.Hyperlink,
  11777. Target: medium.hyperlinks.hyperlink,
  11778. TargetMode: 'External'
  11779. });
  11780. }
  11781. this.preImageId = medium.imageId;
  11782. drawing.anchors.push(anchor);
  11783. }
  11784. });
  11785. // prepare tables
  11786. model.tables.forEach(table => {
  11787. // relationships
  11788. const rId = nextRid(rels);
  11789. table.rId = rId;
  11790. rels.push({
  11791. Id: rId,
  11792. Type: RelType.Table,
  11793. Target: `../tables/${table.target}`
  11794. });
  11795. // dynamic styles
  11796. table.columns.forEach(column => {
  11797. const {
  11798. style
  11799. } = column;
  11800. if (style) {
  11801. column.dxfId = options.styles.addDxfStyle(style);
  11802. }
  11803. });
  11804. });
  11805. // prepare ext items
  11806. this.map.extLst.prepare(model, options);
  11807. }
  11808. render(xmlStream, model) {
  11809. xmlStream.openXml(XmlStream.StdDocAttributes);
  11810. xmlStream.openNode('worksheet', WorkSheetXform.WORKSHEET_ATTRIBUTES);
  11811. const sheetFormatPropertiesModel = model.properties ? {
  11812. defaultRowHeight: model.properties.defaultRowHeight,
  11813. dyDescent: model.properties.dyDescent,
  11814. outlineLevelCol: model.properties.outlineLevelCol,
  11815. outlineLevelRow: model.properties.outlineLevelRow
  11816. } : undefined;
  11817. if (model.properties && model.properties.defaultColWidth) {
  11818. sheetFormatPropertiesModel.defaultColWidth = model.properties.defaultColWidth;
  11819. }
  11820. const sheetPropertiesModel = {
  11821. outlineProperties: model.properties && model.properties.outlineProperties,
  11822. tabColor: model.properties && model.properties.tabColor,
  11823. pageSetup: model.pageSetup && model.pageSetup.fitToPage ? {
  11824. fitToPage: model.pageSetup.fitToPage
  11825. } : undefined
  11826. };
  11827. const pageMarginsModel = model.pageSetup && model.pageSetup.margins;
  11828. const printOptionsModel = {
  11829. showRowColHeaders: model.pageSetup && model.pageSetup.showRowColHeaders,
  11830. showGridLines: model.pageSetup && model.pageSetup.showGridLines,
  11831. horizontalCentered: model.pageSetup && model.pageSetup.horizontalCentered,
  11832. verticalCentered: model.pageSetup && model.pageSetup.verticalCentered
  11833. };
  11834. const sheetProtectionModel = model.sheetProtection;
  11835. this.map.sheetPr.render(xmlStream, sheetPropertiesModel);
  11836. this.map.dimension.render(xmlStream, model.dimensions);
  11837. this.map.sheetViews.render(xmlStream, model.views);
  11838. this.map.sheetFormatPr.render(xmlStream, sheetFormatPropertiesModel);
  11839. this.map.cols.render(xmlStream, model.cols);
  11840. this.map.sheetData.render(xmlStream, model.rows);
  11841. this.map.sheetProtection.render(xmlStream, sheetProtectionModel); // Note: must be after sheetData and before autoFilter
  11842. this.map.autoFilter.render(xmlStream, model.autoFilter);
  11843. this.map.mergeCells.render(xmlStream, model.mergeCells);
  11844. this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings); // Note: must be before dataValidations
  11845. this.map.dataValidations.render(xmlStream, model.dataValidations);
  11846. // For some reason hyperlinks have to be after the data validations
  11847. this.map.hyperlinks.render(xmlStream, model.hyperlinks);
  11848. this.map.printOptions.render(xmlStream, printOptionsModel); // Note: must be before pageMargins
  11849. this.map.pageMargins.render(xmlStream, pageMarginsModel);
  11850. this.map.pageSetup.render(xmlStream, model.pageSetup);
  11851. this.map.headerFooter.render(xmlStream, model.headerFooter);
  11852. this.map.rowBreaks.render(xmlStream, model.rowBreaks);
  11853. this.map.drawing.render(xmlStream, model.drawing); // Note: must be after rowBreaks
  11854. this.map.picture.render(xmlStream, model.background); // Note: must be after drawing
  11855. this.map.tableParts.render(xmlStream, model.tables);
  11856. this.map.extLst.render(xmlStream, model);
  11857. if (model.rels) {
  11858. // add a <legacyDrawing /> node for each comment
  11859. model.rels.forEach(rel => {
  11860. if (rel.Type === RelType.VmlDrawing) {
  11861. xmlStream.leafNode('legacyDrawing', {
  11862. 'r:id': rel.Id
  11863. });
  11864. }
  11865. });
  11866. }
  11867. xmlStream.closeNode();
  11868. }
  11869. parseOpen(node) {
  11870. if (this.parser) {
  11871. this.parser.parseOpen(node);
  11872. return true;
  11873. }
  11874. if (node.name === 'worksheet') {
  11875. _.each(this.map, xform => {
  11876. xform.reset();
  11877. });
  11878. return true;
  11879. }
  11880. if (this.map[node.name] && !this.ignoreNodes.includes(node.name)) {
  11881. this.parser = this.map[node.name];
  11882. this.parser.parseOpen(node);
  11883. }
  11884. return true;
  11885. }
  11886. parseText(text) {
  11887. if (this.parser) {
  11888. this.parser.parseText(text);
  11889. }
  11890. }
  11891. parseClose(name) {
  11892. if (this.parser) {
  11893. if (!this.parser.parseClose(name)) {
  11894. this.parser = undefined;
  11895. }
  11896. return true;
  11897. }
  11898. switch (name) {
  11899. case 'worksheet':
  11900. {
  11901. const properties = this.map.sheetFormatPr.model || {};
  11902. if (this.map.sheetPr.model && this.map.sheetPr.model.tabColor) {
  11903. properties.tabColor = this.map.sheetPr.model.tabColor;
  11904. }
  11905. if (this.map.sheetPr.model && this.map.sheetPr.model.outlineProperties) {
  11906. properties.outlineProperties = this.map.sheetPr.model.outlineProperties;
  11907. }
  11908. const sheetProperties = {
  11909. fitToPage: this.map.sheetPr.model && this.map.sheetPr.model.pageSetup && this.map.sheetPr.model.pageSetup.fitToPage || false,
  11910. margins: this.map.pageMargins.model
  11911. };
  11912. const pageSetup = Object.assign(sheetProperties, this.map.pageSetup.model, this.map.printOptions.model);
  11913. const conditionalFormattings = mergeConditionalFormattings(this.map.conditionalFormatting.model, this.map.extLst.model && this.map.extLst.model['x14:conditionalFormattings']);
  11914. this.model = {
  11915. dimensions: this.map.dimension.model,
  11916. cols: this.map.cols.model,
  11917. rows: this.map.sheetData.model,
  11918. mergeCells: this.map.mergeCells.model,
  11919. hyperlinks: this.map.hyperlinks.model,
  11920. dataValidations: this.map.dataValidations.model,
  11921. properties,
  11922. views: this.map.sheetViews.model,
  11923. pageSetup,
  11924. headerFooter: this.map.headerFooter.model,
  11925. background: this.map.picture.model,
  11926. drawing: this.map.drawing.model,
  11927. tables: this.map.tableParts.model,
  11928. conditionalFormattings
  11929. };
  11930. if (this.map.autoFilter.model) {
  11931. this.model.autoFilter = this.map.autoFilter.model;
  11932. }
  11933. if (this.map.sheetProtection.model) {
  11934. this.model.sheetProtection = this.map.sheetProtection.model;
  11935. }
  11936. return false;
  11937. }
  11938. default:
  11939. // not quite sure how we get here!
  11940. return true;
  11941. }
  11942. }
  11943. reconcile(model, options) {
  11944. // options.merges = new Merges();
  11945. // options.merges.reconcile(model.mergeCells, model.rows);
  11946. const rels = (model.relationships || []).reduce((h, rel) => {
  11947. h[rel.Id] = rel;
  11948. if (rel.Type === RelType.Comments) {
  11949. model.comments = options.comments[rel.Target].comments;
  11950. }
  11951. if (rel.Type === RelType.VmlDrawing && model.comments && model.comments.length) {
  11952. const vmlComment = options.vmlDrawings[rel.Target].comments;
  11953. model.comments.forEach((comment, index) => {
  11954. comment.note = Object.assign({}, comment.note, vmlComment[index]);
  11955. });
  11956. }
  11957. return h;
  11958. }, {});
  11959. options.commentsMap = (model.comments || []).reduce((h, comment) => {
  11960. if (comment.ref) {
  11961. h[comment.ref] = comment;
  11962. }
  11963. return h;
  11964. }, {});
  11965. options.hyperlinkMap = (model.hyperlinks || []).reduce((h, hyperlink) => {
  11966. if (hyperlink.rId) {
  11967. h[hyperlink.address] = rels[hyperlink.rId].Target;
  11968. }
  11969. return h;
  11970. }, {});
  11971. options.formulae = {};
  11972. // compact the rows and cells
  11973. model.rows = model.rows && model.rows.filter(Boolean) || [];
  11974. model.rows.forEach(row => {
  11975. row.cells = row.cells && row.cells.filter(Boolean) || [];
  11976. });
  11977. this.map.cols.reconcile(model.cols, options);
  11978. this.map.sheetData.reconcile(model.rows, options);
  11979. this.map.conditionalFormatting.reconcile(model.conditionalFormattings, options);
  11980. model.media = [];
  11981. if (model.drawing) {
  11982. const drawingRel = rels[model.drawing.rId];
  11983. const match = drawingRel.Target.match(/\/drawings\/([a-zA-Z0-9]+)[.][a-zA-Z]{3,4}$/);
  11984. if (match) {
  11985. const drawingName = match[1];
  11986. const drawing = options.drawings[drawingName];
  11987. drawing.anchors.forEach(anchor => {
  11988. if (anchor.medium) {
  11989. const image = {
  11990. type: 'image',
  11991. imageId: anchor.medium.index,
  11992. range: anchor.range,
  11993. hyperlinks: anchor.picture.hyperlinks
  11994. };
  11995. model.media.push(image);
  11996. }
  11997. });
  11998. }
  11999. }
  12000. const backgroundRel = model.background && rels[model.background.rId];
  12001. if (backgroundRel) {
  12002. const target = backgroundRel.Target.split('/media/')[1];
  12003. const imageId = options.mediaIndex && options.mediaIndex[target];
  12004. if (imageId !== undefined) {
  12005. model.media.push({
  12006. type: 'background',
  12007. imageId
  12008. });
  12009. }
  12010. }
  12011. model.tables = (model.tables || []).map(tablePart => {
  12012. const rel = rels[tablePart.rId];
  12013. return options.tables[rel.Target];
  12014. });
  12015. delete model.relationships;
  12016. delete model.hyperlinks;
  12017. delete model.comments;
  12018. }
  12019. }
  12020. WorkSheetXform.WORKSHEET_ATTRIBUTES = {
  12021. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  12022. 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
  12023. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  12024. 'mc:Ignorable': 'x14ac',
  12025. 'xmlns:x14ac': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac'
  12026. };
  12027. module.exports = WorkSheetXform;
  12028. },{"../../../utils/col-cache":19,"../../../utils/under-dash":26,"../../../utils/xml-stream":28,"../../rel-type":31,"../base-xform":32,"../list-xform":71,"./auto-filter-xform":72,"./cf/conditional-formattings-xform":87,"./col-xform":92,"./data-validations-xform":93,"./dimension-xform":94,"./drawing-xform":95,"./ext-lst-xform":96,"./header-footer-xform":97,"./hyperlink-xform":98,"./merge-cell-xform":99,"./merges":100,"./page-margins-xform":103,"./page-setup-xform":105,"./picture-xform":106,"./print-options-xform":107,"./row-breaks-xform":108,"./row-xform":109,"./sheet-format-properties-xform":110,"./sheet-properties-xform":111,"./sheet-protection-xform":112,"./sheet-view-xform":113,"./table-part-xform":114}],116:[function(require,module,exports){
  12029. "use strict";
  12030. const BaseXform = require('../base-xform');
  12031. class BooleanXform extends BaseXform {
  12032. constructor(options) {
  12033. super();
  12034. this.tag = options.tag;
  12035. this.attr = options.attr;
  12036. }
  12037. render(xmlStream, model) {
  12038. if (model) {
  12039. xmlStream.openNode(this.tag);
  12040. xmlStream.closeNode();
  12041. }
  12042. }
  12043. parseOpen(node) {
  12044. if (node.name === this.tag) {
  12045. this.model = true;
  12046. }
  12047. }
  12048. parseText() {}
  12049. parseClose() {
  12050. return false;
  12051. }
  12052. }
  12053. module.exports = BooleanXform;
  12054. },{"../base-xform":32}],117:[function(require,module,exports){
  12055. "use strict";
  12056. const BaseXform = require('../base-xform');
  12057. class DateXform extends BaseXform {
  12058. constructor(options) {
  12059. super();
  12060. this.tag = options.tag;
  12061. this.attr = options.attr;
  12062. this.attrs = options.attrs;
  12063. this._format = options.format || function (dt) {
  12064. try {
  12065. if (Number.isNaN(dt.getTime())) return '';
  12066. return dt.toISOString();
  12067. } catch (e) {
  12068. return '';
  12069. }
  12070. };
  12071. this._parse = options.parse || function (str) {
  12072. return new Date(str);
  12073. };
  12074. }
  12075. render(xmlStream, model) {
  12076. if (model) {
  12077. xmlStream.openNode(this.tag);
  12078. if (this.attrs) {
  12079. xmlStream.addAttributes(this.attrs);
  12080. }
  12081. if (this.attr) {
  12082. xmlStream.addAttribute(this.attr, this._format(model));
  12083. } else {
  12084. xmlStream.writeText(this._format(model));
  12085. }
  12086. xmlStream.closeNode();
  12087. }
  12088. }
  12089. parseOpen(node) {
  12090. if (node.name === this.tag) {
  12091. if (this.attr) {
  12092. this.model = this._parse(node.attributes[this.attr]);
  12093. } else {
  12094. this.text = [];
  12095. }
  12096. }
  12097. }
  12098. parseText(text) {
  12099. if (!this.attr) {
  12100. this.text.push(text);
  12101. }
  12102. }
  12103. parseClose() {
  12104. if (!this.attr) {
  12105. this.model = this._parse(this.text.join(''));
  12106. }
  12107. return false;
  12108. }
  12109. }
  12110. module.exports = DateXform;
  12111. },{"../base-xform":32}],118:[function(require,module,exports){
  12112. "use strict";
  12113. const BaseXform = require('../base-xform');
  12114. class IntegerXform extends BaseXform {
  12115. constructor(options) {
  12116. super();
  12117. this.tag = options.tag;
  12118. this.attr = options.attr;
  12119. this.attrs = options.attrs;
  12120. // option to render zero
  12121. this.zero = options.zero;
  12122. }
  12123. render(xmlStream, model) {
  12124. // int is different to float in that zero is not rendered
  12125. if (model || this.zero) {
  12126. xmlStream.openNode(this.tag);
  12127. if (this.attrs) {
  12128. xmlStream.addAttributes(this.attrs);
  12129. }
  12130. if (this.attr) {
  12131. xmlStream.addAttribute(this.attr, model);
  12132. } else {
  12133. xmlStream.writeText(model);
  12134. }
  12135. xmlStream.closeNode();
  12136. }
  12137. }
  12138. parseOpen(node) {
  12139. if (node.name === this.tag) {
  12140. if (this.attr) {
  12141. this.model = parseInt(node.attributes[this.attr], 10);
  12142. } else {
  12143. this.text = [];
  12144. }
  12145. return true;
  12146. }
  12147. return false;
  12148. }
  12149. parseText(text) {
  12150. if (!this.attr) {
  12151. this.text.push(text);
  12152. }
  12153. }
  12154. parseClose() {
  12155. if (!this.attr) {
  12156. this.model = parseInt(this.text.join('') || 0, 10);
  12157. }
  12158. return false;
  12159. }
  12160. }
  12161. module.exports = IntegerXform;
  12162. },{"../base-xform":32}],119:[function(require,module,exports){
  12163. "use strict";
  12164. const BaseXform = require('../base-xform');
  12165. class StringXform extends BaseXform {
  12166. constructor(options) {
  12167. super();
  12168. this.tag = options.tag;
  12169. this.attr = options.attr;
  12170. this.attrs = options.attrs;
  12171. }
  12172. render(xmlStream, model) {
  12173. if (model !== undefined) {
  12174. xmlStream.openNode(this.tag);
  12175. if (this.attrs) {
  12176. xmlStream.addAttributes(this.attrs);
  12177. }
  12178. if (this.attr) {
  12179. xmlStream.addAttribute(this.attr, model);
  12180. } else {
  12181. xmlStream.writeText(model);
  12182. }
  12183. xmlStream.closeNode();
  12184. }
  12185. }
  12186. parseOpen(node) {
  12187. if (node.name === this.tag) {
  12188. if (this.attr) {
  12189. this.model = node.attributes[this.attr];
  12190. } else {
  12191. this.text = [];
  12192. }
  12193. }
  12194. }
  12195. parseText(text) {
  12196. if (!this.attr) {
  12197. this.text.push(text);
  12198. }
  12199. }
  12200. parseClose() {
  12201. if (!this.attr) {
  12202. this.model = this.text.join('');
  12203. }
  12204. return false;
  12205. }
  12206. }
  12207. module.exports = StringXform;
  12208. },{"../base-xform":32}],120:[function(require,module,exports){
  12209. "use strict";
  12210. const BaseXform = require('./base-xform');
  12211. const XmlStream = require('../../utils/xml-stream');
  12212. // const model = {
  12213. // tag: 'name',
  12214. // $: {attr: 'value'},
  12215. // c: [
  12216. // { tag: 'child' }
  12217. // ],
  12218. // t: 'some text'
  12219. // };
  12220. function build(xmlStream, model) {
  12221. xmlStream.openNode(model.tag, model.$);
  12222. if (model.c) {
  12223. model.c.forEach(child => {
  12224. build(xmlStream, child);
  12225. });
  12226. }
  12227. if (model.t) {
  12228. xmlStream.writeText(model.t);
  12229. }
  12230. xmlStream.closeNode();
  12231. }
  12232. class StaticXform extends BaseXform {
  12233. constructor(model) {
  12234. super();
  12235. // This class is an optimisation for static (unimportant and unchanging) xml
  12236. // It is stateless - apart from its static model and so can be used as a singleton
  12237. // Being stateless - it will only track entry to and exit from it's root xml tag during parsing and nothing else
  12238. // Known issues:
  12239. // since stateless - parseOpen always returns true. Parent xform must know when to start using this xform
  12240. // if the root tag is recursive, the parsing will behave unpredictably
  12241. this._model = model;
  12242. }
  12243. render(xmlStream) {
  12244. if (!this._xml) {
  12245. const stream = new XmlStream();
  12246. build(stream, this._model);
  12247. this._xml = stream.xml;
  12248. }
  12249. xmlStream.writeXml(this._xml);
  12250. }
  12251. parseOpen() {
  12252. return true;
  12253. }
  12254. parseText() {}
  12255. parseClose(name) {
  12256. switch (name) {
  12257. case this._model.tag:
  12258. return false;
  12259. default:
  12260. return true;
  12261. }
  12262. }
  12263. }
  12264. module.exports = StaticXform;
  12265. },{"../../utils/xml-stream":28,"./base-xform":32}],121:[function(require,module,exports){
  12266. "use strict";
  12267. const TextXform = require('./text-xform');
  12268. const RichTextXform = require('./rich-text-xform');
  12269. const BaseXform = require('../base-xform');
  12270. // <rPh sb="0" eb="1">
  12271. // <t>(its pronounciation in KATAKANA)</t>
  12272. // </rPh>
  12273. class PhoneticTextXform extends BaseXform {
  12274. constructor() {
  12275. super();
  12276. this.map = {
  12277. r: new RichTextXform(),
  12278. t: new TextXform()
  12279. };
  12280. }
  12281. get tag() {
  12282. return 'rPh';
  12283. }
  12284. render(xmlStream, model) {
  12285. xmlStream.openNode(this.tag, {
  12286. sb: model.sb || 0,
  12287. eb: model.eb || 0
  12288. });
  12289. if (model && model.hasOwnProperty('richText') && model.richText) {
  12290. const {
  12291. r
  12292. } = this.map;
  12293. model.richText.forEach(text => {
  12294. r.render(xmlStream, text);
  12295. });
  12296. } else if (model) {
  12297. this.map.t.render(xmlStream, model.text);
  12298. }
  12299. xmlStream.closeNode();
  12300. }
  12301. parseOpen(node) {
  12302. const {
  12303. name
  12304. } = node;
  12305. if (this.parser) {
  12306. this.parser.parseOpen(node);
  12307. return true;
  12308. }
  12309. if (name === this.tag) {
  12310. this.model = {
  12311. sb: parseInt(node.attributes.sb, 10),
  12312. eb: parseInt(node.attributes.eb, 10)
  12313. };
  12314. return true;
  12315. }
  12316. this.parser = this.map[name];
  12317. if (this.parser) {
  12318. this.parser.parseOpen(node);
  12319. return true;
  12320. }
  12321. return false;
  12322. }
  12323. parseText(text) {
  12324. if (this.parser) {
  12325. this.parser.parseText(text);
  12326. }
  12327. }
  12328. parseClose(name) {
  12329. if (this.parser) {
  12330. if (!this.parser.parseClose(name)) {
  12331. switch (name) {
  12332. case 'r':
  12333. {
  12334. let rt = this.model.richText;
  12335. if (!rt) {
  12336. rt = this.model.richText = [];
  12337. }
  12338. rt.push(this.parser.model);
  12339. break;
  12340. }
  12341. case 't':
  12342. this.model.text = this.parser.model;
  12343. break;
  12344. default:
  12345. break;
  12346. }
  12347. this.parser = undefined;
  12348. }
  12349. return true;
  12350. }
  12351. switch (name) {
  12352. case this.tag:
  12353. return false;
  12354. default:
  12355. return true;
  12356. }
  12357. }
  12358. }
  12359. module.exports = PhoneticTextXform;
  12360. },{"../base-xform":32,"./rich-text-xform":122,"./text-xform":125}],122:[function(require,module,exports){
  12361. "use strict";
  12362. const TextXform = require('./text-xform');
  12363. const FontXform = require('../style/font-xform');
  12364. const BaseXform = require('../base-xform');
  12365. // <r>
  12366. // <rPr>
  12367. // <sz val="11"/>
  12368. // <color theme="1" tint="5"/>
  12369. // <rFont val="Calibri"/>
  12370. // <family val="2"/>
  12371. // <scheme val="minor"/>
  12372. // </rPr>
  12373. // <t xml:space="preserve"> is </t>
  12374. // </r>
  12375. class RichTextXform extends BaseXform {
  12376. constructor(model) {
  12377. super();
  12378. this.model = model;
  12379. }
  12380. get tag() {
  12381. return 'r';
  12382. }
  12383. get textXform() {
  12384. return this._textXform || (this._textXform = new TextXform());
  12385. }
  12386. get fontXform() {
  12387. return this._fontXform || (this._fontXform = new FontXform(RichTextXform.FONT_OPTIONS));
  12388. }
  12389. render(xmlStream, model) {
  12390. model = model || this.model;
  12391. xmlStream.openNode('r');
  12392. if (model.font) {
  12393. this.fontXform.render(xmlStream, model.font);
  12394. }
  12395. this.textXform.render(xmlStream, model.text);
  12396. xmlStream.closeNode();
  12397. }
  12398. parseOpen(node) {
  12399. if (this.parser) {
  12400. this.parser.parseOpen(node);
  12401. return true;
  12402. }
  12403. switch (node.name) {
  12404. case 'r':
  12405. this.model = {};
  12406. return true;
  12407. case 't':
  12408. this.parser = this.textXform;
  12409. this.parser.parseOpen(node);
  12410. return true;
  12411. case 'rPr':
  12412. this.parser = this.fontXform;
  12413. this.parser.parseOpen(node);
  12414. return true;
  12415. default:
  12416. return false;
  12417. }
  12418. }
  12419. parseText(text) {
  12420. if (this.parser) {
  12421. this.parser.parseText(text);
  12422. }
  12423. }
  12424. parseClose(name) {
  12425. switch (name) {
  12426. case 'r':
  12427. return false;
  12428. case 't':
  12429. this.model.text = this.parser.model;
  12430. this.parser = undefined;
  12431. return true;
  12432. case 'rPr':
  12433. this.model.font = this.parser.model;
  12434. this.parser = undefined;
  12435. return true;
  12436. default:
  12437. if (this.parser) {
  12438. this.parser.parseClose(name);
  12439. }
  12440. return true;
  12441. }
  12442. }
  12443. }
  12444. RichTextXform.FONT_OPTIONS = {
  12445. tagName: 'rPr',
  12446. fontNameTag: 'rFont'
  12447. };
  12448. module.exports = RichTextXform;
  12449. },{"../base-xform":32,"../style/font-xform":131,"./text-xform":125}],123:[function(require,module,exports){
  12450. "use strict";
  12451. const TextXform = require('./text-xform');
  12452. const RichTextXform = require('./rich-text-xform');
  12453. const PhoneticTextXform = require('./phonetic-text-xform');
  12454. const BaseXform = require('../base-xform');
  12455. // <si>
  12456. // <r></r><r></r>...
  12457. // </si>
  12458. // <si>
  12459. // <t></t>
  12460. // </si>
  12461. class SharedStringXform extends BaseXform {
  12462. constructor(model) {
  12463. super();
  12464. this.model = model;
  12465. this.map = {
  12466. r: new RichTextXform(),
  12467. t: new TextXform(),
  12468. rPh: new PhoneticTextXform()
  12469. };
  12470. }
  12471. get tag() {
  12472. return 'si';
  12473. }
  12474. render(xmlStream, model) {
  12475. xmlStream.openNode(this.tag);
  12476. if (model && model.hasOwnProperty('richText') && model.richText) {
  12477. if (model.richText.length) {
  12478. model.richText.forEach(text => {
  12479. this.map.r.render(xmlStream, text);
  12480. });
  12481. } else {
  12482. this.map.t.render(xmlStream, '');
  12483. }
  12484. } else if (model !== undefined && model !== null) {
  12485. this.map.t.render(xmlStream, model);
  12486. }
  12487. xmlStream.closeNode();
  12488. }
  12489. parseOpen(node) {
  12490. const {
  12491. name
  12492. } = node;
  12493. if (this.parser) {
  12494. this.parser.parseOpen(node);
  12495. return true;
  12496. }
  12497. if (name === this.tag) {
  12498. this.model = {};
  12499. return true;
  12500. }
  12501. this.parser = this.map[name];
  12502. if (this.parser) {
  12503. this.parser.parseOpen(node);
  12504. return true;
  12505. }
  12506. return false;
  12507. }
  12508. parseText(text) {
  12509. if (this.parser) {
  12510. this.parser.parseText(text);
  12511. }
  12512. }
  12513. parseClose(name) {
  12514. if (this.parser) {
  12515. if (!this.parser.parseClose(name)) {
  12516. switch (name) {
  12517. case 'r':
  12518. {
  12519. let rt = this.model.richText;
  12520. if (!rt) {
  12521. rt = this.model.richText = [];
  12522. }
  12523. rt.push(this.parser.model);
  12524. break;
  12525. }
  12526. case 't':
  12527. this.model = this.parser.model;
  12528. break;
  12529. default:
  12530. break;
  12531. }
  12532. this.parser = undefined;
  12533. }
  12534. return true;
  12535. }
  12536. switch (name) {
  12537. case this.tag:
  12538. return false;
  12539. default:
  12540. return true;
  12541. }
  12542. }
  12543. }
  12544. module.exports = SharedStringXform;
  12545. },{"../base-xform":32,"./phonetic-text-xform":121,"./rich-text-xform":122,"./text-xform":125}],124:[function(require,module,exports){
  12546. "use strict";
  12547. const XmlStream = require('../../../utils/xml-stream');
  12548. const BaseXform = require('../base-xform');
  12549. const SharedStringXform = require('./shared-string-xform');
  12550. class SharedStringsXform extends BaseXform {
  12551. constructor(model) {
  12552. super();
  12553. this.model = model || {
  12554. values: [],
  12555. count: 0
  12556. };
  12557. this.hash = Object.create(null);
  12558. this.rich = Object.create(null);
  12559. }
  12560. get sharedStringXform() {
  12561. return this._sharedStringXform || (this._sharedStringXform = new SharedStringXform());
  12562. }
  12563. get values() {
  12564. return this.model.values;
  12565. }
  12566. get uniqueCount() {
  12567. return this.model.values.length;
  12568. }
  12569. get count() {
  12570. return this.model.count;
  12571. }
  12572. getString(index) {
  12573. return this.model.values[index];
  12574. }
  12575. add(value) {
  12576. return value.richText ? this.addRichText(value) : this.addText(value);
  12577. }
  12578. addText(value) {
  12579. let index = this.hash[value];
  12580. if (index === undefined) {
  12581. index = this.hash[value] = this.model.values.length;
  12582. this.model.values.push(value);
  12583. }
  12584. this.model.count++;
  12585. return index;
  12586. }
  12587. addRichText(value) {
  12588. // TODO: add WeakMap here
  12589. const xml = this.sharedStringXform.toXml(value);
  12590. let index = this.rich[xml];
  12591. if (index === undefined) {
  12592. index = this.rich[xml] = this.model.values.length;
  12593. this.model.values.push(value);
  12594. }
  12595. this.model.count++;
  12596. return index;
  12597. }
  12598. // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  12599. // <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="<%=totalRefs%>" uniqueCount="<%=count%>">
  12600. // <si><t><%=text%></t></si>
  12601. // <si><r><rPr></rPr><t></t></r></si>
  12602. // </sst>
  12603. render(xmlStream, model) {
  12604. model = model || this._values;
  12605. xmlStream.openXml(XmlStream.StdDocAttributes);
  12606. xmlStream.openNode('sst', {
  12607. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  12608. count: model.count,
  12609. uniqueCount: model.values.length
  12610. });
  12611. const sx = this.sharedStringXform;
  12612. model.values.forEach(sharedString => {
  12613. sx.render(xmlStream, sharedString);
  12614. });
  12615. xmlStream.closeNode();
  12616. }
  12617. parseOpen(node) {
  12618. if (this.parser) {
  12619. this.parser.parseOpen(node);
  12620. return true;
  12621. }
  12622. switch (node.name) {
  12623. case 'sst':
  12624. return true;
  12625. case 'si':
  12626. this.parser = this.sharedStringXform;
  12627. this.parser.parseOpen(node);
  12628. return true;
  12629. default:
  12630. throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
  12631. }
  12632. }
  12633. parseText(text) {
  12634. if (this.parser) {
  12635. this.parser.parseText(text);
  12636. }
  12637. }
  12638. parseClose(name) {
  12639. if (this.parser) {
  12640. if (!this.parser.parseClose(name)) {
  12641. this.model.values.push(this.parser.model);
  12642. this.model.count++;
  12643. this.parser = undefined;
  12644. }
  12645. return true;
  12646. }
  12647. switch (name) {
  12648. case 'sst':
  12649. return false;
  12650. default:
  12651. throw new Error(`Unexpected xml node in parseClose: ${name}`);
  12652. }
  12653. }
  12654. }
  12655. module.exports = SharedStringsXform;
  12656. },{"../../../utils/xml-stream":28,"../base-xform":32,"./shared-string-xform":123}],125:[function(require,module,exports){
  12657. "use strict";
  12658. const BaseXform = require('../base-xform');
  12659. // <t xml:space="preserve"> is </t>
  12660. class TextXform extends BaseXform {
  12661. get tag() {
  12662. return 't';
  12663. }
  12664. render(xmlStream, model) {
  12665. xmlStream.openNode('t');
  12666. if (/^\s|\n|\s$/.test(model)) {
  12667. xmlStream.addAttribute('xml:space', 'preserve');
  12668. }
  12669. xmlStream.writeText(model);
  12670. xmlStream.closeNode();
  12671. }
  12672. get model() {
  12673. return this._text.join('').replace(/_x([0-9A-F]{4})_/g, ($0, $1) => String.fromCharCode(parseInt($1, 16)));
  12674. }
  12675. parseOpen(node) {
  12676. switch (node.name) {
  12677. case 't':
  12678. this._text = [];
  12679. return true;
  12680. default:
  12681. return false;
  12682. }
  12683. }
  12684. parseText(text) {
  12685. this._text.push(text);
  12686. }
  12687. parseClose() {
  12688. return false;
  12689. }
  12690. }
  12691. module.exports = TextXform;
  12692. },{"../base-xform":32}],126:[function(require,module,exports){
  12693. "use strict";
  12694. const Enums = require('../../../doc/enums');
  12695. const utils = require('../../../utils/utils');
  12696. const BaseXform = require('../base-xform');
  12697. const validation = {
  12698. horizontalValues: ['left', 'center', 'right', 'fill', 'centerContinuous', 'distributed', 'justify'].reduce((p, v) => {
  12699. p[v] = true;
  12700. return p;
  12701. }, {}),
  12702. horizontal(value) {
  12703. return this.horizontalValues[value] ? value : undefined;
  12704. },
  12705. verticalValues: ['top', 'middle', 'bottom', 'distributed', 'justify'].reduce((p, v) => {
  12706. p[v] = true;
  12707. return p;
  12708. }, {}),
  12709. vertical(value) {
  12710. if (value === 'middle') return 'center';
  12711. return this.verticalValues[value] ? value : undefined;
  12712. },
  12713. wrapText(value) {
  12714. return value ? true : undefined;
  12715. },
  12716. shrinkToFit(value) {
  12717. return value ? true : undefined;
  12718. },
  12719. textRotation(value) {
  12720. switch (value) {
  12721. case 'vertical':
  12722. return value;
  12723. default:
  12724. value = utils.validInt(value);
  12725. return value >= -90 && value <= 90 ? value : undefined;
  12726. }
  12727. },
  12728. indent(value) {
  12729. value = utils.validInt(value);
  12730. return Math.max(0, value);
  12731. },
  12732. readingOrder(value) {
  12733. switch (value) {
  12734. case 'ltr':
  12735. return Enums.ReadingOrder.LeftToRight;
  12736. case 'rtl':
  12737. return Enums.ReadingOrder.RightToLeft;
  12738. default:
  12739. return undefined;
  12740. }
  12741. }
  12742. };
  12743. const textRotationXform = {
  12744. toXml(textRotation) {
  12745. textRotation = validation.textRotation(textRotation);
  12746. if (textRotation) {
  12747. if (textRotation === 'vertical') {
  12748. return 255;
  12749. }
  12750. const tr = Math.round(textRotation);
  12751. if (tr >= 0 && tr <= 90) {
  12752. return tr;
  12753. }
  12754. if (tr < 0 && tr >= -90) {
  12755. return 90 - tr;
  12756. }
  12757. }
  12758. return undefined;
  12759. },
  12760. toModel(textRotation) {
  12761. const tr = utils.validInt(textRotation);
  12762. if (tr !== undefined) {
  12763. if (tr === 255) {
  12764. return 'vertical';
  12765. }
  12766. if (tr >= 0 && tr <= 90) {
  12767. return tr;
  12768. }
  12769. if (tr > 90 && tr <= 180) {
  12770. return 90 - tr;
  12771. }
  12772. }
  12773. return undefined;
  12774. }
  12775. };
  12776. // Alignment encapsulates translation from style.alignment model to/from xlsx
  12777. class AlignmentXform extends BaseXform {
  12778. get tag() {
  12779. return 'alignment';
  12780. }
  12781. render(xmlStream, model) {
  12782. xmlStream.addRollback();
  12783. xmlStream.openNode('alignment');
  12784. let isValid = false;
  12785. function add(name, value) {
  12786. if (value) {
  12787. xmlStream.addAttribute(name, value);
  12788. isValid = true;
  12789. }
  12790. }
  12791. add('horizontal', validation.horizontal(model.horizontal));
  12792. add('vertical', validation.vertical(model.vertical));
  12793. add('wrapText', validation.wrapText(model.wrapText) ? '1' : false);
  12794. add('shrinkToFit', validation.shrinkToFit(model.shrinkToFit) ? '1' : false);
  12795. add('indent', validation.indent(model.indent));
  12796. add('textRotation', textRotationXform.toXml(model.textRotation));
  12797. add('readingOrder', validation.readingOrder(model.readingOrder));
  12798. xmlStream.closeNode();
  12799. if (isValid) {
  12800. xmlStream.commit();
  12801. } else {
  12802. xmlStream.rollback();
  12803. }
  12804. }
  12805. parseOpen(node) {
  12806. const model = {};
  12807. let valid = false;
  12808. function add(truthy, name, value) {
  12809. if (truthy) {
  12810. model[name] = value;
  12811. valid = true;
  12812. }
  12813. }
  12814. add(node.attributes.horizontal, 'horizontal', node.attributes.horizontal);
  12815. add(node.attributes.vertical, 'vertical', node.attributes.vertical === 'center' ? 'middle' : node.attributes.vertical);
  12816. add(node.attributes.wrapText, 'wrapText', utils.parseBoolean(node.attributes.wrapText));
  12817. add(node.attributes.shrinkToFit, 'shrinkToFit', utils.parseBoolean(node.attributes.shrinkToFit));
  12818. add(node.attributes.indent, 'indent', parseInt(node.attributes.indent, 10));
  12819. add(node.attributes.textRotation, 'textRotation', textRotationXform.toModel(node.attributes.textRotation));
  12820. add(node.attributes.readingOrder, 'readingOrder', node.attributes.readingOrder === '2' ? 'rtl' : 'ltr');
  12821. this.model = valid ? model : null;
  12822. }
  12823. parseText() {}
  12824. parseClose() {
  12825. return false;
  12826. }
  12827. }
  12828. module.exports = AlignmentXform;
  12829. },{"../../../doc/enums":7,"../../../utils/utils":27,"../base-xform":32}],127:[function(require,module,exports){
  12830. "use strict";
  12831. /* eslint-disable max-classes-per-file */
  12832. const BaseXform = require('../base-xform');
  12833. const utils = require('../../../utils/utils');
  12834. const ColorXform = require('./color-xform');
  12835. class EdgeXform extends BaseXform {
  12836. constructor(name) {
  12837. super();
  12838. this.name = name;
  12839. this.map = {
  12840. color: new ColorXform()
  12841. };
  12842. }
  12843. get tag() {
  12844. return this.name;
  12845. }
  12846. render(xmlStream, model, defaultColor) {
  12847. const color = model && model.color || defaultColor || this.defaultColor;
  12848. xmlStream.openNode(this.name);
  12849. if (model && model.style) {
  12850. xmlStream.addAttribute('style', model.style);
  12851. if (color) {
  12852. this.map.color.render(xmlStream, color);
  12853. }
  12854. }
  12855. xmlStream.closeNode();
  12856. }
  12857. parseOpen(node) {
  12858. if (this.parser) {
  12859. this.parser.parseOpen(node);
  12860. return true;
  12861. }
  12862. switch (node.name) {
  12863. case this.name:
  12864. {
  12865. const {
  12866. style
  12867. } = node.attributes;
  12868. if (style) {
  12869. this.model = {
  12870. style
  12871. };
  12872. } else {
  12873. this.model = undefined;
  12874. }
  12875. return true;
  12876. }
  12877. case 'color':
  12878. this.parser = this.map.color;
  12879. this.parser.parseOpen(node);
  12880. return true;
  12881. default:
  12882. return false;
  12883. }
  12884. }
  12885. parseText(text) {
  12886. if (this.parser) {
  12887. this.parser.parseText(text);
  12888. }
  12889. }
  12890. parseClose(name) {
  12891. if (this.parser) {
  12892. if (!this.parser.parseClose(name)) {
  12893. this.parser = undefined;
  12894. }
  12895. return true;
  12896. }
  12897. if (name === this.name) {
  12898. if (this.map.color.model) {
  12899. if (!this.model) {
  12900. this.model = {};
  12901. }
  12902. this.model.color = this.map.color.model;
  12903. }
  12904. }
  12905. return false;
  12906. }
  12907. validStyle(value) {
  12908. return EdgeXform.validStyleValues[value];
  12909. }
  12910. }
  12911. EdgeXform.validStyleValues = ['thin', 'dashed', 'dotted', 'dashDot', 'hair', 'dashDotDot', 'slantDashDot', 'mediumDashed', 'mediumDashDotDot', 'mediumDashDot', 'medium', 'double', 'thick'].reduce((p, v) => {
  12912. p[v] = true;
  12913. return p;
  12914. }, {});
  12915. // Border encapsulates translation from border model to/from xlsx
  12916. class BorderXform extends BaseXform {
  12917. constructor() {
  12918. super();
  12919. this.map = {
  12920. top: new EdgeXform('top'),
  12921. left: new EdgeXform('left'),
  12922. bottom: new EdgeXform('bottom'),
  12923. right: new EdgeXform('right'),
  12924. diagonal: new EdgeXform('diagonal')
  12925. };
  12926. }
  12927. render(xmlStream, model) {
  12928. const {
  12929. color
  12930. } = model;
  12931. xmlStream.openNode('border');
  12932. if (model.diagonal && model.diagonal.style) {
  12933. if (model.diagonal.up) {
  12934. xmlStream.addAttribute('diagonalUp', '1');
  12935. }
  12936. if (model.diagonal.down) {
  12937. xmlStream.addAttribute('diagonalDown', '1');
  12938. }
  12939. }
  12940. function add(edgeModel, edgeXform) {
  12941. if (edgeModel && !edgeModel.color && model.color) {
  12942. // don't mess with incoming models
  12943. edgeModel = {
  12944. ...edgeModel,
  12945. color: model.color
  12946. };
  12947. }
  12948. edgeXform.render(xmlStream, edgeModel, color);
  12949. }
  12950. add(model.left, this.map.left);
  12951. add(model.right, this.map.right);
  12952. add(model.top, this.map.top);
  12953. add(model.bottom, this.map.bottom);
  12954. add(model.diagonal, this.map.diagonal);
  12955. xmlStream.closeNode();
  12956. }
  12957. parseOpen(node) {
  12958. if (this.parser) {
  12959. this.parser.parseOpen(node);
  12960. return true;
  12961. }
  12962. switch (node.name) {
  12963. case 'border':
  12964. this.reset();
  12965. this.diagonalUp = utils.parseBoolean(node.attributes.diagonalUp);
  12966. this.diagonalDown = utils.parseBoolean(node.attributes.diagonalDown);
  12967. return true;
  12968. default:
  12969. this.parser = this.map[node.name];
  12970. if (this.parser) {
  12971. this.parser.parseOpen(node);
  12972. return true;
  12973. }
  12974. return false;
  12975. }
  12976. }
  12977. parseText(text) {
  12978. if (this.parser) {
  12979. this.parser.parseText(text);
  12980. }
  12981. }
  12982. parseClose(name) {
  12983. if (this.parser) {
  12984. if (!this.parser.parseClose(name)) {
  12985. this.parser = undefined;
  12986. }
  12987. return true;
  12988. }
  12989. if (name === 'border') {
  12990. const model = this.model = {};
  12991. const add = function (key, edgeModel, extensions) {
  12992. if (edgeModel) {
  12993. if (extensions) {
  12994. Object.assign(edgeModel, extensions);
  12995. }
  12996. model[key] = edgeModel;
  12997. }
  12998. };
  12999. add('left', this.map.left.model);
  13000. add('right', this.map.right.model);
  13001. add('top', this.map.top.model);
  13002. add('bottom', this.map.bottom.model);
  13003. add('diagonal', this.map.diagonal.model, {
  13004. up: this.diagonalUp,
  13005. down: this.diagonalDown
  13006. });
  13007. }
  13008. return false;
  13009. }
  13010. }
  13011. module.exports = BorderXform;
  13012. },{"../../../utils/utils":27,"../base-xform":32,"./color-xform":128}],128:[function(require,module,exports){
  13013. "use strict";
  13014. const BaseXform = require('../base-xform');
  13015. // Color encapsulates translation from color model to/from xlsx
  13016. class ColorXform extends BaseXform {
  13017. constructor(name) {
  13018. super();
  13019. // this.name controls the xm node name
  13020. this.name = name || 'color';
  13021. }
  13022. get tag() {
  13023. return this.name;
  13024. }
  13025. render(xmlStream, model) {
  13026. if (model) {
  13027. xmlStream.openNode(this.name);
  13028. if (model.argb) {
  13029. xmlStream.addAttribute('rgb', model.argb);
  13030. } else if (model.theme !== undefined) {
  13031. xmlStream.addAttribute('theme', model.theme);
  13032. if (model.tint !== undefined) {
  13033. xmlStream.addAttribute('tint', model.tint);
  13034. }
  13035. } else if (model.indexed !== undefined) {
  13036. xmlStream.addAttribute('indexed', model.indexed);
  13037. } else {
  13038. xmlStream.addAttribute('auto', '1');
  13039. }
  13040. xmlStream.closeNode();
  13041. return true;
  13042. }
  13043. return false;
  13044. }
  13045. parseOpen(node) {
  13046. if (node.name === this.name) {
  13047. if (node.attributes.rgb) {
  13048. this.model = {
  13049. argb: node.attributes.rgb
  13050. };
  13051. } else if (node.attributes.theme) {
  13052. this.model = {
  13053. theme: parseInt(node.attributes.theme, 10)
  13054. };
  13055. if (node.attributes.tint) {
  13056. this.model.tint = parseFloat(node.attributes.tint);
  13057. }
  13058. } else if (node.attributes.indexed) {
  13059. this.model = {
  13060. indexed: parseInt(node.attributes.indexed, 10)
  13061. };
  13062. } else {
  13063. this.model = undefined;
  13064. }
  13065. return true;
  13066. }
  13067. return false;
  13068. }
  13069. parseText() {}
  13070. parseClose() {
  13071. return false;
  13072. }
  13073. }
  13074. module.exports = ColorXform;
  13075. },{"../base-xform":32}],129:[function(require,module,exports){
  13076. "use strict";
  13077. const BaseXform = require('../base-xform');
  13078. const AlignmentXform = require('./alignment-xform');
  13079. const BorderXform = require('./border-xform');
  13080. const FillXform = require('./fill-xform');
  13081. const FontXform = require('./font-xform');
  13082. const NumFmtXform = require('./numfmt-xform');
  13083. const ProtectionXform = require('./protection-xform');
  13084. // <xf numFmtId="[numFmtId]" fontId="[fontId]" fillId="[fillId]" borderId="[xf.borderId]" xfId="[xfId]">
  13085. // Optional <alignment>
  13086. // Optional <protection>
  13087. // </xf>
  13088. // Style assists translation from style model to/from xlsx
  13089. class DxfXform extends BaseXform {
  13090. constructor() {
  13091. super();
  13092. this.map = {
  13093. alignment: new AlignmentXform(),
  13094. border: new BorderXform(),
  13095. fill: new FillXform(),
  13096. font: new FontXform(),
  13097. numFmt: new NumFmtXform(),
  13098. protection: new ProtectionXform()
  13099. };
  13100. }
  13101. get tag() {
  13102. return 'dxf';
  13103. }
  13104. // how do we generate dxfid?
  13105. render(xmlStream, model) {
  13106. xmlStream.openNode(this.tag);
  13107. if (model.font) {
  13108. this.map.font.render(xmlStream, model.font);
  13109. }
  13110. if (model.numFmt && model.numFmtId) {
  13111. const numFmtModel = {
  13112. id: model.numFmtId,
  13113. formatCode: model.numFmt
  13114. };
  13115. this.map.numFmt.render(xmlStream, numFmtModel);
  13116. }
  13117. if (model.fill) {
  13118. this.map.fill.render(xmlStream, model.fill);
  13119. }
  13120. if (model.alignment) {
  13121. this.map.alignment.render(xmlStream, model.alignment);
  13122. }
  13123. if (model.border) {
  13124. this.map.border.render(xmlStream, model.border);
  13125. }
  13126. if (model.protection) {
  13127. this.map.protection.render(xmlStream, model.protection);
  13128. }
  13129. xmlStream.closeNode();
  13130. }
  13131. parseOpen(node) {
  13132. if (this.parser) {
  13133. this.parser.parseOpen(node);
  13134. return true;
  13135. }
  13136. switch (node.name) {
  13137. case this.tag:
  13138. // this node is often repeated. Need to reset children
  13139. this.reset();
  13140. return true;
  13141. default:
  13142. this.parser = this.map[node.name];
  13143. if (this.parser) {
  13144. this.parser.parseOpen(node);
  13145. }
  13146. return true;
  13147. }
  13148. }
  13149. parseText(text) {
  13150. if (this.parser) {
  13151. this.parser.parseText(text);
  13152. }
  13153. }
  13154. parseClose(name) {
  13155. if (this.parser) {
  13156. if (!this.parser.parseClose(name)) {
  13157. this.parser = undefined;
  13158. }
  13159. return true;
  13160. }
  13161. if (name === this.tag) {
  13162. this.model = {
  13163. alignment: this.map.alignment.model,
  13164. border: this.map.border.model,
  13165. fill: this.map.fill.model,
  13166. font: this.map.font.model,
  13167. numFmt: this.map.numFmt.model,
  13168. protection: this.map.protection.model
  13169. };
  13170. return false;
  13171. }
  13172. return true;
  13173. }
  13174. }
  13175. module.exports = DxfXform;
  13176. },{"../base-xform":32,"./alignment-xform":126,"./border-xform":127,"./fill-xform":130,"./font-xform":131,"./numfmt-xform":132,"./protection-xform":133}],130:[function(require,module,exports){
  13177. "use strict";
  13178. /* eslint-disable max-classes-per-file */
  13179. const BaseXform = require('../base-xform');
  13180. const ColorXform = require('./color-xform');
  13181. class StopXform extends BaseXform {
  13182. constructor() {
  13183. super();
  13184. this.map = {
  13185. color: new ColorXform()
  13186. };
  13187. }
  13188. get tag() {
  13189. return 'stop';
  13190. }
  13191. render(xmlStream, model) {
  13192. xmlStream.openNode('stop');
  13193. xmlStream.addAttribute('position', model.position);
  13194. this.map.color.render(xmlStream, model.color);
  13195. xmlStream.closeNode();
  13196. }
  13197. parseOpen(node) {
  13198. if (this.parser) {
  13199. this.parser.parseOpen(node);
  13200. return true;
  13201. }
  13202. switch (node.name) {
  13203. case 'stop':
  13204. this.model = {
  13205. position: parseFloat(node.attributes.position)
  13206. };
  13207. return true;
  13208. case 'color':
  13209. this.parser = this.map.color;
  13210. this.parser.parseOpen(node);
  13211. return true;
  13212. default:
  13213. return false;
  13214. }
  13215. }
  13216. parseText() {}
  13217. parseClose(name) {
  13218. if (this.parser) {
  13219. if (!this.parser.parseClose(name)) {
  13220. this.model.color = this.parser.model;
  13221. this.parser = undefined;
  13222. }
  13223. return true;
  13224. }
  13225. return false;
  13226. }
  13227. }
  13228. class PatternFillXform extends BaseXform {
  13229. constructor() {
  13230. super();
  13231. this.map = {
  13232. fgColor: new ColorXform('fgColor'),
  13233. bgColor: new ColorXform('bgColor')
  13234. };
  13235. }
  13236. get name() {
  13237. return 'pattern';
  13238. }
  13239. get tag() {
  13240. return 'patternFill';
  13241. }
  13242. render(xmlStream, model) {
  13243. xmlStream.openNode('patternFill');
  13244. xmlStream.addAttribute('patternType', model.pattern);
  13245. if (model.fgColor) {
  13246. this.map.fgColor.render(xmlStream, model.fgColor);
  13247. }
  13248. if (model.bgColor) {
  13249. this.map.bgColor.render(xmlStream, model.bgColor);
  13250. }
  13251. xmlStream.closeNode();
  13252. }
  13253. parseOpen(node) {
  13254. if (this.parser) {
  13255. this.parser.parseOpen(node);
  13256. return true;
  13257. }
  13258. switch (node.name) {
  13259. case 'patternFill':
  13260. this.model = {
  13261. type: 'pattern',
  13262. pattern: node.attributes.patternType
  13263. };
  13264. return true;
  13265. default:
  13266. this.parser = this.map[node.name];
  13267. if (this.parser) {
  13268. this.parser.parseOpen(node);
  13269. return true;
  13270. }
  13271. return false;
  13272. }
  13273. }
  13274. parseText(text) {
  13275. if (this.parser) {
  13276. this.parser.parseText(text);
  13277. }
  13278. }
  13279. parseClose(name) {
  13280. if (this.parser) {
  13281. if (!this.parser.parseClose(name)) {
  13282. if (this.parser.model) {
  13283. this.model[name] = this.parser.model;
  13284. }
  13285. this.parser = undefined;
  13286. }
  13287. return true;
  13288. }
  13289. return false;
  13290. }
  13291. }
  13292. class GradientFillXform extends BaseXform {
  13293. constructor() {
  13294. super();
  13295. this.map = {
  13296. stop: new StopXform()
  13297. };
  13298. // if (model) {
  13299. // this.gradient = model.gradient;
  13300. // if (model.center) {
  13301. // this.center = model.center;
  13302. // }
  13303. // if (model.degree !== undefined) {
  13304. // this.degree = model.degree;
  13305. // }
  13306. // this.stops = model.stops.map(function(stop) { return new StopXform(stop); });
  13307. // } else {
  13308. // this.stops = [];
  13309. // }
  13310. }
  13311. get name() {
  13312. return 'gradient';
  13313. }
  13314. get tag() {
  13315. return 'gradientFill';
  13316. }
  13317. render(xmlStream, model) {
  13318. xmlStream.openNode('gradientFill');
  13319. switch (model.gradient) {
  13320. case 'angle':
  13321. xmlStream.addAttribute('degree', model.degree);
  13322. break;
  13323. case 'path':
  13324. xmlStream.addAttribute('type', 'path');
  13325. if (model.center.left) {
  13326. xmlStream.addAttribute('left', model.center.left);
  13327. if (model.center.right === undefined) {
  13328. xmlStream.addAttribute('right', model.center.left);
  13329. }
  13330. }
  13331. if (model.center.right) {
  13332. xmlStream.addAttribute('right', model.center.right);
  13333. }
  13334. if (model.center.top) {
  13335. xmlStream.addAttribute('top', model.center.top);
  13336. if (model.center.bottom === undefined) {
  13337. xmlStream.addAttribute('bottom', model.center.top);
  13338. }
  13339. }
  13340. if (model.center.bottom) {
  13341. xmlStream.addAttribute('bottom', model.center.bottom);
  13342. }
  13343. break;
  13344. default:
  13345. break;
  13346. }
  13347. const stopXform = this.map.stop;
  13348. model.stops.forEach(stopModel => {
  13349. stopXform.render(xmlStream, stopModel);
  13350. });
  13351. xmlStream.closeNode();
  13352. }
  13353. parseOpen(node) {
  13354. if (this.parser) {
  13355. this.parser.parseOpen(node);
  13356. return true;
  13357. }
  13358. switch (node.name) {
  13359. case 'gradientFill':
  13360. {
  13361. const model = this.model = {
  13362. stops: []
  13363. };
  13364. if (node.attributes.degree) {
  13365. model.gradient = 'angle';
  13366. model.degree = parseInt(node.attributes.degree, 10);
  13367. } else if (node.attributes.type === 'path') {
  13368. model.gradient = 'path';
  13369. model.center = {
  13370. left: node.attributes.left ? parseFloat(node.attributes.left) : 0,
  13371. top: node.attributes.top ? parseFloat(node.attributes.top) : 0
  13372. };
  13373. if (node.attributes.right !== node.attributes.left) {
  13374. model.center.right = node.attributes.right ? parseFloat(node.attributes.right) : 0;
  13375. }
  13376. if (node.attributes.bottom !== node.attributes.top) {
  13377. model.center.bottom = node.attributes.bottom ? parseFloat(node.attributes.bottom) : 0;
  13378. }
  13379. }
  13380. return true;
  13381. }
  13382. case 'stop':
  13383. this.parser = this.map.stop;
  13384. this.parser.parseOpen(node);
  13385. return true;
  13386. default:
  13387. return false;
  13388. }
  13389. }
  13390. parseText(text) {
  13391. if (this.parser) {
  13392. this.parser.parseText(text);
  13393. }
  13394. }
  13395. parseClose(name) {
  13396. if (this.parser) {
  13397. if (!this.parser.parseClose(name)) {
  13398. this.model.stops.push(this.parser.model);
  13399. this.parser = undefined;
  13400. }
  13401. return true;
  13402. }
  13403. return false;
  13404. }
  13405. }
  13406. // Fill encapsulates translation from fill model to/from xlsx
  13407. class FillXform extends BaseXform {
  13408. constructor() {
  13409. super();
  13410. this.map = {
  13411. patternFill: new PatternFillXform(),
  13412. gradientFill: new GradientFillXform()
  13413. };
  13414. }
  13415. get tag() {
  13416. return 'fill';
  13417. }
  13418. render(xmlStream, model) {
  13419. xmlStream.addRollback();
  13420. xmlStream.openNode('fill');
  13421. switch (model.type) {
  13422. case 'pattern':
  13423. this.map.patternFill.render(xmlStream, model);
  13424. break;
  13425. case 'gradient':
  13426. this.map.gradientFill.render(xmlStream, model);
  13427. break;
  13428. default:
  13429. xmlStream.rollback();
  13430. return;
  13431. }
  13432. xmlStream.closeNode();
  13433. xmlStream.commit();
  13434. }
  13435. parseOpen(node) {
  13436. if (this.parser) {
  13437. this.parser.parseOpen(node);
  13438. return true;
  13439. }
  13440. switch (node.name) {
  13441. case 'fill':
  13442. this.model = {};
  13443. return true;
  13444. default:
  13445. this.parser = this.map[node.name];
  13446. if (this.parser) {
  13447. this.parser.parseOpen(node);
  13448. return true;
  13449. }
  13450. return false;
  13451. }
  13452. }
  13453. parseText(text) {
  13454. if (this.parser) {
  13455. this.parser.parseText(text);
  13456. }
  13457. }
  13458. parseClose(name) {
  13459. if (this.parser) {
  13460. if (!this.parser.parseClose(name)) {
  13461. this.model = this.parser.model;
  13462. this.model.type = this.parser.name;
  13463. this.parser = undefined;
  13464. }
  13465. return true;
  13466. }
  13467. return false;
  13468. }
  13469. validStyle(value) {
  13470. return FillXform.validPatternValues[value];
  13471. }
  13472. }
  13473. FillXform.validPatternValues = ['none', 'solid', 'darkVertical', 'darkGray', 'mediumGray', 'lightGray', 'gray125', 'gray0625', 'darkHorizontal', 'darkVertical', 'darkDown', 'darkUp', 'darkGrid', 'darkTrellis', 'lightHorizontal', 'lightVertical', 'lightDown', 'lightUp', 'lightGrid', 'lightTrellis', 'lightGrid'].reduce((p, v) => {
  13474. p[v] = true;
  13475. return p;
  13476. }, {});
  13477. FillXform.StopXform = StopXform;
  13478. FillXform.PatternFillXform = PatternFillXform;
  13479. FillXform.GradientFillXform = GradientFillXform;
  13480. module.exports = FillXform;
  13481. },{"../base-xform":32,"./color-xform":128}],131:[function(require,module,exports){
  13482. 'use strict';
  13483. const ColorXform = require('./color-xform');
  13484. const BooleanXform = require('../simple/boolean-xform');
  13485. const IntegerXform = require('../simple/integer-xform');
  13486. const StringXform = require('../simple/string-xform');
  13487. const UnderlineXform = require('./underline-xform');
  13488. const _ = require('../../../utils/under-dash');
  13489. const BaseXform = require('../base-xform');
  13490. // Font encapsulates translation from font model to xlsx
  13491. class FontXform extends BaseXform {
  13492. constructor(options) {
  13493. super();
  13494. this.options = options || FontXform.OPTIONS;
  13495. this.map = {
  13496. b: {
  13497. prop: 'bold',
  13498. xform: new BooleanXform({
  13499. tag: 'b',
  13500. attr: 'val'
  13501. })
  13502. },
  13503. i: {
  13504. prop: 'italic',
  13505. xform: new BooleanXform({
  13506. tag: 'i',
  13507. attr: 'val'
  13508. })
  13509. },
  13510. u: {
  13511. prop: 'underline',
  13512. xform: new UnderlineXform()
  13513. },
  13514. charset: {
  13515. prop: 'charset',
  13516. xform: new IntegerXform({
  13517. tag: 'charset',
  13518. attr: 'val'
  13519. })
  13520. },
  13521. color: {
  13522. prop: 'color',
  13523. xform: new ColorXform()
  13524. },
  13525. condense: {
  13526. prop: 'condense',
  13527. xform: new BooleanXform({
  13528. tag: 'condense',
  13529. attr: 'val'
  13530. })
  13531. },
  13532. extend: {
  13533. prop: 'extend',
  13534. xform: new BooleanXform({
  13535. tag: 'extend',
  13536. attr: 'val'
  13537. })
  13538. },
  13539. family: {
  13540. prop: 'family',
  13541. xform: new IntegerXform({
  13542. tag: 'family',
  13543. attr: 'val'
  13544. })
  13545. },
  13546. outline: {
  13547. prop: 'outline',
  13548. xform: new BooleanXform({
  13549. tag: 'outline',
  13550. attr: 'val'
  13551. })
  13552. },
  13553. vertAlign: {
  13554. prop: 'vertAlign',
  13555. xform: new StringXform({
  13556. tag: 'vertAlign',
  13557. attr: 'val'
  13558. })
  13559. },
  13560. scheme: {
  13561. prop: 'scheme',
  13562. xform: new StringXform({
  13563. tag: 'scheme',
  13564. attr: 'val'
  13565. })
  13566. },
  13567. shadow: {
  13568. prop: 'shadow',
  13569. xform: new BooleanXform({
  13570. tag: 'shadow',
  13571. attr: 'val'
  13572. })
  13573. },
  13574. strike: {
  13575. prop: 'strike',
  13576. xform: new BooleanXform({
  13577. tag: 'strike',
  13578. attr: 'val'
  13579. })
  13580. },
  13581. sz: {
  13582. prop: 'size',
  13583. xform: new IntegerXform({
  13584. tag: 'sz',
  13585. attr: 'val'
  13586. })
  13587. }
  13588. };
  13589. this.map[this.options.fontNameTag] = {
  13590. prop: 'name',
  13591. xform: new StringXform({
  13592. tag: this.options.fontNameTag,
  13593. attr: 'val'
  13594. })
  13595. };
  13596. }
  13597. get tag() {
  13598. return this.options.tagName;
  13599. }
  13600. render(xmlStream, model) {
  13601. const {
  13602. map
  13603. } = this;
  13604. xmlStream.openNode(this.options.tagName);
  13605. _.each(this.map, (defn, tag) => {
  13606. map[tag].xform.render(xmlStream, model[defn.prop]);
  13607. });
  13608. xmlStream.closeNode();
  13609. }
  13610. parseOpen(node) {
  13611. if (this.parser) {
  13612. this.parser.parseOpen(node);
  13613. return true;
  13614. }
  13615. if (this.map[node.name]) {
  13616. this.parser = this.map[node.name].xform;
  13617. return this.parser.parseOpen(node);
  13618. }
  13619. switch (node.name) {
  13620. case this.options.tagName:
  13621. this.model = {};
  13622. return true;
  13623. default:
  13624. return false;
  13625. }
  13626. }
  13627. parseText(text) {
  13628. if (this.parser) {
  13629. this.parser.parseText(text);
  13630. }
  13631. }
  13632. parseClose(name) {
  13633. if (this.parser && !this.parser.parseClose(name)) {
  13634. const item = this.map[name];
  13635. if (this.parser.model) {
  13636. this.model[item.prop] = this.parser.model;
  13637. }
  13638. this.parser = undefined;
  13639. return true;
  13640. }
  13641. switch (name) {
  13642. case this.options.tagName:
  13643. return false;
  13644. default:
  13645. return true;
  13646. }
  13647. }
  13648. }
  13649. FontXform.OPTIONS = {
  13650. tagName: 'font',
  13651. fontNameTag: 'name'
  13652. };
  13653. module.exports = FontXform;
  13654. },{"../../../utils/under-dash":26,"../base-xform":32,"../simple/boolean-xform":116,"../simple/integer-xform":118,"../simple/string-xform":119,"./color-xform":128,"./underline-xform":136}],132:[function(require,module,exports){
  13655. "use strict";
  13656. const _ = require('../../../utils/under-dash');
  13657. const defaultNumFormats = require('../../defaultnumformats');
  13658. const BaseXform = require('../base-xform');
  13659. function hashDefaultFormats() {
  13660. const hash = {};
  13661. _.each(defaultNumFormats, (dnf, id) => {
  13662. if (dnf.f) {
  13663. hash[dnf.f] = parseInt(id, 10);
  13664. }
  13665. // at some point, add the other cultures here...
  13666. });
  13667. return hash;
  13668. }
  13669. const defaultFmtHash = hashDefaultFormats();
  13670. // NumFmt encapsulates translation between number format and xlsx
  13671. class NumFmtXform extends BaseXform {
  13672. constructor(id, formatCode) {
  13673. super();
  13674. this.id = id;
  13675. this.formatCode = formatCode;
  13676. }
  13677. get tag() {
  13678. return 'numFmt';
  13679. }
  13680. render(xmlStream, model) {
  13681. xmlStream.leafNode('numFmt', {
  13682. numFmtId: model.id,
  13683. formatCode: model.formatCode
  13684. });
  13685. }
  13686. parseOpen(node) {
  13687. switch (node.name) {
  13688. case 'numFmt':
  13689. this.model = {
  13690. id: parseInt(node.attributes.numFmtId, 10),
  13691. formatCode: node.attributes.formatCode.replace(/[\\](.)/g, '$1')
  13692. };
  13693. return true;
  13694. default:
  13695. return false;
  13696. }
  13697. }
  13698. parseText() {}
  13699. parseClose() {
  13700. return false;
  13701. }
  13702. }
  13703. NumFmtXform.getDefaultFmtId = function getDefaultFmtId(formatCode) {
  13704. return defaultFmtHash[formatCode];
  13705. };
  13706. NumFmtXform.getDefaultFmtCode = function getDefaultFmtCode(numFmtId) {
  13707. return defaultNumFormats[numFmtId] && defaultNumFormats[numFmtId].f;
  13708. };
  13709. module.exports = NumFmtXform;
  13710. },{"../../../utils/under-dash":26,"../../defaultnumformats":30,"../base-xform":32}],133:[function(require,module,exports){
  13711. "use strict";
  13712. const BaseXform = require('../base-xform');
  13713. const validation = {
  13714. boolean(value, dflt) {
  13715. if (value === undefined) {
  13716. return dflt;
  13717. }
  13718. return value;
  13719. }
  13720. };
  13721. // Protection encapsulates translation from style.protection model to/from xlsx
  13722. class ProtectionXform extends BaseXform {
  13723. get tag() {
  13724. return 'protection';
  13725. }
  13726. render(xmlStream, model) {
  13727. xmlStream.addRollback();
  13728. xmlStream.openNode('protection');
  13729. let isValid = false;
  13730. function add(name, value) {
  13731. if (value !== undefined) {
  13732. xmlStream.addAttribute(name, value);
  13733. isValid = true;
  13734. }
  13735. }
  13736. add('locked', validation.boolean(model.locked, true) ? undefined : '0');
  13737. add('hidden', validation.boolean(model.hidden, false) ? '1' : undefined);
  13738. xmlStream.closeNode();
  13739. if (isValid) {
  13740. xmlStream.commit();
  13741. } else {
  13742. xmlStream.rollback();
  13743. }
  13744. }
  13745. parseOpen(node) {
  13746. const model = {
  13747. locked: !(node.attributes.locked === '0'),
  13748. hidden: node.attributes.hidden === '1'
  13749. };
  13750. // only want to record models that differ from defaults
  13751. const isSignificant = !model.locked || model.hidden;
  13752. this.model = isSignificant ? model : null;
  13753. }
  13754. parseText() {}
  13755. parseClose() {
  13756. return false;
  13757. }
  13758. }
  13759. module.exports = ProtectionXform;
  13760. },{"../base-xform":32}],134:[function(require,module,exports){
  13761. "use strict";
  13762. const BaseXform = require('../base-xform');
  13763. const AlignmentXform = require('./alignment-xform');
  13764. const ProtectionXform = require('./protection-xform');
  13765. // <xf numFmtId="[numFmtId]" fontId="[fontId]" fillId="[fillId]" borderId="[xf.borderId]" xfId="[xfId]">
  13766. // Optional <alignment>
  13767. // Optional <protection>
  13768. // </xf>
  13769. // Style assists translation from style model to/from xlsx
  13770. class StyleXform extends BaseXform {
  13771. constructor(options) {
  13772. super();
  13773. this.xfId = !!(options && options.xfId);
  13774. this.map = {
  13775. alignment: new AlignmentXform(),
  13776. protection: new ProtectionXform()
  13777. };
  13778. }
  13779. get tag() {
  13780. return 'xf';
  13781. }
  13782. render(xmlStream, model) {
  13783. xmlStream.openNode('xf', {
  13784. numFmtId: model.numFmtId || 0,
  13785. fontId: model.fontId || 0,
  13786. fillId: model.fillId || 0,
  13787. borderId: model.borderId || 0
  13788. });
  13789. if (this.xfId) {
  13790. xmlStream.addAttribute('xfId', model.xfId || 0);
  13791. }
  13792. if (model.numFmtId) {
  13793. xmlStream.addAttribute('applyNumberFormat', '1');
  13794. }
  13795. if (model.fontId) {
  13796. xmlStream.addAttribute('applyFont', '1');
  13797. }
  13798. if (model.fillId) {
  13799. xmlStream.addAttribute('applyFill', '1');
  13800. }
  13801. if (model.borderId) {
  13802. xmlStream.addAttribute('applyBorder', '1');
  13803. }
  13804. if (model.alignment) {
  13805. xmlStream.addAttribute('applyAlignment', '1');
  13806. }
  13807. if (model.protection) {
  13808. xmlStream.addAttribute('applyProtection', '1');
  13809. }
  13810. /**
  13811. * Rendering tags causes close of XML stream.
  13812. * Therefore adding attributes must be done before rendering tags.
  13813. */
  13814. if (model.alignment) {
  13815. this.map.alignment.render(xmlStream, model.alignment);
  13816. }
  13817. if (model.protection) {
  13818. this.map.protection.render(xmlStream, model.protection);
  13819. }
  13820. xmlStream.closeNode();
  13821. }
  13822. parseOpen(node) {
  13823. if (this.parser) {
  13824. this.parser.parseOpen(node);
  13825. return true;
  13826. }
  13827. // used during sax parsing of xml to build font object
  13828. switch (node.name) {
  13829. case 'xf':
  13830. this.model = {
  13831. numFmtId: parseInt(node.attributes.numFmtId, 10),
  13832. fontId: parseInt(node.attributes.fontId, 10),
  13833. fillId: parseInt(node.attributes.fillId, 10),
  13834. borderId: parseInt(node.attributes.borderId, 10)
  13835. };
  13836. if (this.xfId) {
  13837. this.model.xfId = parseInt(node.attributes.xfId, 10);
  13838. }
  13839. return true;
  13840. case 'alignment':
  13841. this.parser = this.map.alignment;
  13842. this.parser.parseOpen(node);
  13843. return true;
  13844. case 'protection':
  13845. this.parser = this.map.protection;
  13846. this.parser.parseOpen(node);
  13847. return true;
  13848. default:
  13849. return false;
  13850. }
  13851. }
  13852. parseText(text) {
  13853. if (this.parser) {
  13854. this.parser.parseText(text);
  13855. }
  13856. }
  13857. parseClose(name) {
  13858. if (this.parser) {
  13859. if (!this.parser.parseClose(name)) {
  13860. if (this.map.protection === this.parser) {
  13861. this.model.protection = this.parser.model;
  13862. } else {
  13863. this.model.alignment = this.parser.model;
  13864. }
  13865. this.parser = undefined;
  13866. }
  13867. return true;
  13868. }
  13869. return name !== 'xf';
  13870. }
  13871. }
  13872. module.exports = StyleXform;
  13873. },{"../base-xform":32,"./alignment-xform":126,"./protection-xform":133}],135:[function(require,module,exports){
  13874. "use strict";
  13875. /* eslint-disable max-classes-per-file */
  13876. const Enums = require('../../../doc/enums');
  13877. const XmlStream = require('../../../utils/xml-stream');
  13878. const BaseXform = require('../base-xform');
  13879. const StaticXform = require('../static-xform');
  13880. const ListXform = require('../list-xform');
  13881. const FontXform = require('./font-xform');
  13882. const FillXform = require('./fill-xform');
  13883. const BorderXform = require('./border-xform');
  13884. const NumFmtXform = require('./numfmt-xform');
  13885. const StyleXform = require('./style-xform');
  13886. const DxfXform = require('./dxf-xform');
  13887. // custom numfmt ids start here
  13888. const NUMFMT_BASE = 164;
  13889. // =============================================================================
  13890. // StylesXform is used to generate and parse the styles.xml file
  13891. // it manages the collections of fonts, number formats, alignments, etc
  13892. class StylesXform extends BaseXform {
  13893. constructor(initialise) {
  13894. super();
  13895. this.map = {
  13896. numFmts: new ListXform({
  13897. tag: 'numFmts',
  13898. count: true,
  13899. childXform: new NumFmtXform()
  13900. }),
  13901. fonts: new ListXform({
  13902. tag: 'fonts',
  13903. count: true,
  13904. childXform: new FontXform(),
  13905. $: {
  13906. 'x14ac:knownFonts': 1
  13907. }
  13908. }),
  13909. fills: new ListXform({
  13910. tag: 'fills',
  13911. count: true,
  13912. childXform: new FillXform()
  13913. }),
  13914. borders: new ListXform({
  13915. tag: 'borders',
  13916. count: true,
  13917. childXform: new BorderXform()
  13918. }),
  13919. cellStyleXfs: new ListXform({
  13920. tag: 'cellStyleXfs',
  13921. count: true,
  13922. childXform: new StyleXform()
  13923. }),
  13924. cellXfs: new ListXform({
  13925. tag: 'cellXfs',
  13926. count: true,
  13927. childXform: new StyleXform({
  13928. xfId: true
  13929. })
  13930. }),
  13931. dxfs: new ListXform({
  13932. tag: 'dxfs',
  13933. always: true,
  13934. count: true,
  13935. childXform: new DxfXform()
  13936. }),
  13937. // for style manager
  13938. numFmt: new NumFmtXform(),
  13939. font: new FontXform(),
  13940. fill: new FillXform(),
  13941. border: new BorderXform(),
  13942. style: new StyleXform({
  13943. xfId: true
  13944. }),
  13945. cellStyles: StylesXform.STATIC_XFORMS.cellStyles,
  13946. tableStyles: StylesXform.STATIC_XFORMS.tableStyles,
  13947. extLst: StylesXform.STATIC_XFORMS.extLst
  13948. };
  13949. if (initialise) {
  13950. // StylesXform also acts as style manager and is used to build up styles-model during worksheet processing
  13951. this.init();
  13952. }
  13953. }
  13954. initIndex() {
  13955. this.index = {
  13956. style: {},
  13957. numFmt: {},
  13958. numFmtNextId: 164,
  13959. // start custom format ids here
  13960. font: {},
  13961. border: {},
  13962. fill: {}
  13963. };
  13964. }
  13965. init() {
  13966. // Prepare for Style Manager role
  13967. this.model = {
  13968. styles: [],
  13969. numFmts: [],
  13970. fonts: [],
  13971. borders: [],
  13972. fills: [],
  13973. dxfs: []
  13974. };
  13975. this.initIndex();
  13976. // default (zero) border
  13977. this._addBorder({});
  13978. // add default (all zero) style
  13979. this._addStyle({
  13980. numFmtId: 0,
  13981. fontId: 0,
  13982. fillId: 0,
  13983. borderId: 0,
  13984. xfId: 0
  13985. });
  13986. // add default fills
  13987. this._addFill({
  13988. type: 'pattern',
  13989. pattern: 'none'
  13990. });
  13991. this._addFill({
  13992. type: 'pattern',
  13993. pattern: 'gray125'
  13994. });
  13995. this.weakMap = new WeakMap();
  13996. }
  13997. render(xmlStream, model) {
  13998. model = model || this.model;
  13999. //
  14000. // <fonts count="2" x14ac:knownFonts="1">
  14001. xmlStream.openXml(XmlStream.StdDocAttributes);
  14002. xmlStream.openNode('styleSheet', StylesXform.STYLESHEET_ATTRIBUTES);
  14003. if (this.index) {
  14004. // model has been built by style manager role (contains xml)
  14005. if (model.numFmts && model.numFmts.length) {
  14006. xmlStream.openNode('numFmts', {
  14007. count: model.numFmts.length
  14008. });
  14009. model.numFmts.forEach(numFmtXml => {
  14010. xmlStream.writeXml(numFmtXml);
  14011. });
  14012. xmlStream.closeNode();
  14013. }
  14014. if (!model.fonts.length) {
  14015. // default (zero) font
  14016. this._addFont({
  14017. size: 11,
  14018. color: {
  14019. theme: 1
  14020. },
  14021. name: 'Calibri',
  14022. family: 2,
  14023. scheme: 'minor'
  14024. });
  14025. }
  14026. xmlStream.openNode('fonts', {
  14027. count: model.fonts.length,
  14028. 'x14ac:knownFonts': 1
  14029. });
  14030. model.fonts.forEach(fontXml => {
  14031. xmlStream.writeXml(fontXml);
  14032. });
  14033. xmlStream.closeNode();
  14034. xmlStream.openNode('fills', {
  14035. count: model.fills.length
  14036. });
  14037. model.fills.forEach(fillXml => {
  14038. xmlStream.writeXml(fillXml);
  14039. });
  14040. xmlStream.closeNode();
  14041. xmlStream.openNode('borders', {
  14042. count: model.borders.length
  14043. });
  14044. model.borders.forEach(borderXml => {
  14045. xmlStream.writeXml(borderXml);
  14046. });
  14047. xmlStream.closeNode();
  14048. this.map.cellStyleXfs.render(xmlStream, [{
  14049. numFmtId: 0,
  14050. fontId: 0,
  14051. fillId: 0,
  14052. borderId: 0,
  14053. xfId: 0
  14054. }]);
  14055. xmlStream.openNode('cellXfs', {
  14056. count: model.styles.length
  14057. });
  14058. model.styles.forEach(styleXml => {
  14059. xmlStream.writeXml(styleXml);
  14060. });
  14061. xmlStream.closeNode();
  14062. } else {
  14063. // model is plain JSON and needs to be xformed
  14064. this.map.numFmts.render(xmlStream, model.numFmts);
  14065. this.map.fonts.render(xmlStream, model.fonts);
  14066. this.map.fills.render(xmlStream, model.fills);
  14067. this.map.borders.render(xmlStream, model.borders);
  14068. this.map.cellStyleXfs.render(xmlStream, [{
  14069. numFmtId: 0,
  14070. fontId: 0,
  14071. fillId: 0,
  14072. borderId: 0,
  14073. xfId: 0
  14074. }]);
  14075. this.map.cellXfs.render(xmlStream, model.styles);
  14076. }
  14077. StylesXform.STATIC_XFORMS.cellStyles.render(xmlStream);
  14078. this.map.dxfs.render(xmlStream, model.dxfs);
  14079. StylesXform.STATIC_XFORMS.tableStyles.render(xmlStream);
  14080. StylesXform.STATIC_XFORMS.extLst.render(xmlStream);
  14081. xmlStream.closeNode();
  14082. }
  14083. parseOpen(node) {
  14084. if (this.parser) {
  14085. this.parser.parseOpen(node);
  14086. return true;
  14087. }
  14088. switch (node.name) {
  14089. case 'styleSheet':
  14090. this.initIndex();
  14091. return true;
  14092. default:
  14093. this.parser = this.map[node.name];
  14094. if (this.parser) {
  14095. this.parser.parseOpen(node);
  14096. }
  14097. return true;
  14098. }
  14099. }
  14100. parseText(text) {
  14101. if (this.parser) {
  14102. this.parser.parseText(text);
  14103. }
  14104. }
  14105. parseClose(name) {
  14106. if (this.parser) {
  14107. if (!this.parser.parseClose(name)) {
  14108. this.parser = undefined;
  14109. }
  14110. return true;
  14111. }
  14112. switch (name) {
  14113. case 'styleSheet':
  14114. {
  14115. this.model = {};
  14116. const add = (propName, xform) => {
  14117. if (xform.model && xform.model.length) {
  14118. this.model[propName] = xform.model;
  14119. }
  14120. };
  14121. add('numFmts', this.map.numFmts);
  14122. add('fonts', this.map.fonts);
  14123. add('fills', this.map.fills);
  14124. add('borders', this.map.borders);
  14125. add('styles', this.map.cellXfs);
  14126. add('dxfs', this.map.dxfs);
  14127. // index numFmts
  14128. this.index = {
  14129. model: [],
  14130. numFmt: []
  14131. };
  14132. if (this.model.numFmts) {
  14133. const numFmtIndex = this.index.numFmt;
  14134. this.model.numFmts.forEach(numFmt => {
  14135. numFmtIndex[numFmt.id] = numFmt.formatCode;
  14136. });
  14137. }
  14138. return false;
  14139. }
  14140. default:
  14141. // not quite sure how we get here!
  14142. return true;
  14143. }
  14144. }
  14145. // add a cell's style model to the collection
  14146. // each style property is processed and cross-referenced, etc.
  14147. // the styleId is returned. Note: cellType is used when numFmt not defined
  14148. addStyleModel(model, cellType) {
  14149. if (!model) {
  14150. return 0;
  14151. }
  14152. // if we have no default font, add it here now
  14153. if (!this.model.fonts.length) {
  14154. // default (zero) font
  14155. this._addFont({
  14156. size: 11,
  14157. color: {
  14158. theme: 1
  14159. },
  14160. name: 'Calibri',
  14161. family: 2,
  14162. scheme: 'minor'
  14163. });
  14164. }
  14165. // if we have seen this style object before, assume it has the same styleId
  14166. if (this.weakMap && this.weakMap.has(model)) {
  14167. return this.weakMap.get(model);
  14168. }
  14169. const style = {};
  14170. cellType = cellType || Enums.ValueType.Number;
  14171. if (model.numFmt) {
  14172. style.numFmtId = this._addNumFmtStr(model.numFmt);
  14173. } else {
  14174. switch (cellType) {
  14175. case Enums.ValueType.Number:
  14176. style.numFmtId = this._addNumFmtStr('General');
  14177. break;
  14178. case Enums.ValueType.Date:
  14179. style.numFmtId = this._addNumFmtStr('mm-dd-yy');
  14180. break;
  14181. default:
  14182. break;
  14183. }
  14184. }
  14185. if (model.font) {
  14186. style.fontId = this._addFont(model.font);
  14187. }
  14188. if (model.border) {
  14189. style.borderId = this._addBorder(model.border);
  14190. }
  14191. if (model.fill) {
  14192. style.fillId = this._addFill(model.fill);
  14193. }
  14194. if (model.alignment) {
  14195. style.alignment = model.alignment;
  14196. }
  14197. if (model.protection) {
  14198. style.protection = model.protection;
  14199. }
  14200. const styleId = this._addStyle(style);
  14201. if (this.weakMap) {
  14202. this.weakMap.set(model, styleId);
  14203. }
  14204. return styleId;
  14205. }
  14206. // given a styleId (i.e. s="n"), get the cell's style model
  14207. // objects are shared where possible.
  14208. getStyleModel(id) {
  14209. // if the style doesn't exist return null
  14210. const style = this.model.styles[id];
  14211. if (!style) return null;
  14212. // have we built this model before?
  14213. let model = this.index.model[id];
  14214. if (model) return model;
  14215. // build a new model
  14216. model = this.index.model[id] = {};
  14217. // -------------------------------------------------------
  14218. // number format
  14219. if (style.numFmtId) {
  14220. const numFmt = this.index.numFmt[style.numFmtId] || NumFmtXform.getDefaultFmtCode(style.numFmtId);
  14221. if (numFmt) {
  14222. model.numFmt = numFmt;
  14223. }
  14224. }
  14225. function addStyle(name, group, styleId) {
  14226. if (styleId || styleId === 0) {
  14227. const part = group[styleId];
  14228. if (part) {
  14229. model[name] = part;
  14230. }
  14231. }
  14232. }
  14233. addStyle('font', this.model.fonts, style.fontId);
  14234. addStyle('border', this.model.borders, style.borderId);
  14235. addStyle('fill', this.model.fills, style.fillId);
  14236. // -------------------------------------------------------
  14237. // alignment
  14238. if (style.alignment) {
  14239. model.alignment = style.alignment;
  14240. }
  14241. // -------------------------------------------------------
  14242. // protection
  14243. if (style.protection) {
  14244. model.protection = style.protection;
  14245. }
  14246. return model;
  14247. }
  14248. addDxfStyle(style) {
  14249. if (style.numFmt) {
  14250. // register numFmtId to use it during dxf-xform rendering
  14251. style.numFmtId = this._addNumFmtStr(style.numFmt);
  14252. }
  14253. this.model.dxfs.push(style);
  14254. return this.model.dxfs.length - 1;
  14255. }
  14256. getDxfStyle(id) {
  14257. return this.model.dxfs[id];
  14258. }
  14259. // =========================================================================
  14260. // Private Interface
  14261. _addStyle(style) {
  14262. const xml = this.map.style.toXml(style);
  14263. let index = this.index.style[xml];
  14264. if (index === undefined) {
  14265. index = this.index.style[xml] = this.model.styles.length;
  14266. this.model.styles.push(xml);
  14267. }
  14268. return index;
  14269. }
  14270. // =========================================================================
  14271. // Number Formats
  14272. _addNumFmtStr(formatCode) {
  14273. // check if default format
  14274. let index = NumFmtXform.getDefaultFmtId(formatCode);
  14275. if (index !== undefined) return index;
  14276. // check if already in
  14277. index = this.index.numFmt[formatCode];
  14278. if (index !== undefined) return index;
  14279. index = this.index.numFmt[formatCode] = NUMFMT_BASE + this.model.numFmts.length;
  14280. const xml = this.map.numFmt.toXml({
  14281. id: index,
  14282. formatCode
  14283. });
  14284. this.model.numFmts.push(xml);
  14285. return index;
  14286. }
  14287. // =========================================================================
  14288. // Fonts
  14289. _addFont(font) {
  14290. const xml = this.map.font.toXml(font);
  14291. let index = this.index.font[xml];
  14292. if (index === undefined) {
  14293. index = this.index.font[xml] = this.model.fonts.length;
  14294. this.model.fonts.push(xml);
  14295. }
  14296. return index;
  14297. }
  14298. // =========================================================================
  14299. // Borders
  14300. _addBorder(border) {
  14301. const xml = this.map.border.toXml(border);
  14302. let index = this.index.border[xml];
  14303. if (index === undefined) {
  14304. index = this.index.border[xml] = this.model.borders.length;
  14305. this.model.borders.push(xml);
  14306. }
  14307. return index;
  14308. }
  14309. // =========================================================================
  14310. // Fills
  14311. _addFill(fill) {
  14312. const xml = this.map.fill.toXml(fill);
  14313. let index = this.index.fill[xml];
  14314. if (index === undefined) {
  14315. index = this.index.fill[xml] = this.model.fills.length;
  14316. this.model.fills.push(xml);
  14317. }
  14318. return index;
  14319. }
  14320. // =========================================================================
  14321. }
  14322. StylesXform.STYLESHEET_ATTRIBUTES = {
  14323. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  14324. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  14325. 'mc:Ignorable': 'x14ac x16r2',
  14326. 'xmlns:x14ac': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac',
  14327. 'xmlns:x16r2': 'http://schemas.microsoft.com/office/spreadsheetml/2015/02/main'
  14328. };
  14329. StylesXform.STATIC_XFORMS = {
  14330. cellStyles: new StaticXform({
  14331. tag: 'cellStyles',
  14332. $: {
  14333. count: 1
  14334. },
  14335. c: [{
  14336. tag: 'cellStyle',
  14337. $: {
  14338. name: 'Normal',
  14339. xfId: 0,
  14340. builtinId: 0
  14341. }
  14342. }]
  14343. }),
  14344. dxfs: new StaticXform({
  14345. tag: 'dxfs',
  14346. $: {
  14347. count: 0
  14348. }
  14349. }),
  14350. tableStyles: new StaticXform({
  14351. tag: 'tableStyles',
  14352. $: {
  14353. count: 0,
  14354. defaultTableStyle: 'TableStyleMedium2',
  14355. defaultPivotStyle: 'PivotStyleLight16'
  14356. }
  14357. }),
  14358. extLst: new StaticXform({
  14359. tag: 'extLst',
  14360. c: [{
  14361. tag: 'ext',
  14362. $: {
  14363. uri: '{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}',
  14364. 'xmlns:x14': 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/main'
  14365. },
  14366. c: [{
  14367. tag: 'x14:slicerStyles',
  14368. $: {
  14369. defaultSlicerStyle: 'SlicerStyleLight1'
  14370. }
  14371. }]
  14372. }, {
  14373. tag: 'ext',
  14374. $: {
  14375. uri: '{9260A510-F301-46a8-8635-F512D64BE5F5}',
  14376. 'xmlns:x15': 'http://schemas.microsoft.com/office/spreadsheetml/2010/11/main'
  14377. },
  14378. c: [{
  14379. tag: 'x15:timelineStyles',
  14380. $: {
  14381. defaultTimelineStyle: 'TimeSlicerStyleLight1'
  14382. }
  14383. }]
  14384. }]
  14385. })
  14386. };
  14387. // the stylemanager mock acts like StyleManager except that it always returns 0 or {}
  14388. class StylesXformMock extends StylesXform {
  14389. constructor() {
  14390. super();
  14391. this.model = {
  14392. styles: [{
  14393. numFmtId: 0,
  14394. fontId: 0,
  14395. fillId: 0,
  14396. borderId: 0,
  14397. xfId: 0
  14398. }],
  14399. numFmts: [],
  14400. fonts: [{
  14401. size: 11,
  14402. color: {
  14403. theme: 1
  14404. },
  14405. name: 'Calibri',
  14406. family: 2,
  14407. scheme: 'minor'
  14408. }],
  14409. borders: [{}],
  14410. fills: [{
  14411. type: 'pattern',
  14412. pattern: 'none'
  14413. }, {
  14414. type: 'pattern',
  14415. pattern: 'gray125'
  14416. }]
  14417. };
  14418. }
  14419. // =========================================================================
  14420. // Style Manager Interface
  14421. // override normal behaviour - consume and dispose
  14422. parseStream(stream) {
  14423. stream.autodrain();
  14424. return Promise.resolve();
  14425. }
  14426. // add a cell's style model to the collection
  14427. // each style property is processed and cross-referenced, etc.
  14428. // the styleId is returned. Note: cellType is used when numFmt not defined
  14429. addStyleModel(model, cellType) {
  14430. switch (cellType) {
  14431. case Enums.ValueType.Date:
  14432. return this.dateStyleId;
  14433. default:
  14434. return 0;
  14435. }
  14436. }
  14437. get dateStyleId() {
  14438. if (!this._dateStyleId) {
  14439. const dateStyle = {
  14440. numFmtId: NumFmtXform.getDefaultFmtId('mm-dd-yy')
  14441. };
  14442. this._dateStyleId = this.model.styles.length;
  14443. this.model.styles.push(dateStyle);
  14444. }
  14445. return this._dateStyleId;
  14446. }
  14447. // given a styleId (i.e. s="n"), get the cell's style model
  14448. // objects are shared where possible.
  14449. getStyleModel( /* id */
  14450. ) {
  14451. return {};
  14452. }
  14453. }
  14454. StylesXform.Mock = StylesXformMock;
  14455. module.exports = StylesXform;
  14456. },{"../../../doc/enums":7,"../../../utils/xml-stream":28,"../base-xform":32,"../list-xform":71,"../static-xform":120,"./border-xform":127,"./dxf-xform":129,"./fill-xform":130,"./font-xform":131,"./numfmt-xform":132,"./style-xform":134}],136:[function(require,module,exports){
  14457. "use strict";
  14458. const BaseXform = require('../base-xform');
  14459. class UnderlineXform extends BaseXform {
  14460. constructor(model) {
  14461. super();
  14462. this.model = model;
  14463. }
  14464. get tag() {
  14465. return 'u';
  14466. }
  14467. render(xmlStream, model) {
  14468. model = model || this.model;
  14469. if (model === true) {
  14470. xmlStream.leafNode('u');
  14471. } else {
  14472. const attr = UnderlineXform.Attributes[model];
  14473. if (attr) {
  14474. xmlStream.leafNode('u', attr);
  14475. }
  14476. }
  14477. }
  14478. parseOpen(node) {
  14479. if (node.name === 'u') {
  14480. this.model = node.attributes.val || true;
  14481. }
  14482. }
  14483. parseText() {}
  14484. parseClose() {
  14485. return false;
  14486. }
  14487. }
  14488. UnderlineXform.Attributes = {
  14489. single: {},
  14490. double: {
  14491. val: 'double'
  14492. },
  14493. singleAccounting: {
  14494. val: 'singleAccounting'
  14495. },
  14496. doubleAccounting: {
  14497. val: 'doubleAccounting'
  14498. }
  14499. };
  14500. module.exports = UnderlineXform;
  14501. },{"../base-xform":32}],137:[function(require,module,exports){
  14502. "use strict";
  14503. const BaseXform = require('../base-xform');
  14504. const FilterColumnXform = require('./filter-column-xform');
  14505. class AutoFilterXform extends BaseXform {
  14506. constructor() {
  14507. super();
  14508. this.map = {
  14509. filterColumn: new FilterColumnXform()
  14510. };
  14511. }
  14512. get tag() {
  14513. return 'autoFilter';
  14514. }
  14515. prepare(model) {
  14516. model.columns.forEach((column, index) => {
  14517. this.map.filterColumn.prepare(column, {
  14518. index
  14519. });
  14520. });
  14521. }
  14522. render(xmlStream, model) {
  14523. xmlStream.openNode(this.tag, {
  14524. ref: model.autoFilterRef
  14525. });
  14526. model.columns.forEach(column => {
  14527. this.map.filterColumn.render(xmlStream, column);
  14528. });
  14529. xmlStream.closeNode();
  14530. return true;
  14531. }
  14532. parseOpen(node) {
  14533. if (this.parser) {
  14534. this.parser.parseOpen(node);
  14535. return true;
  14536. }
  14537. switch (node.name) {
  14538. case this.tag:
  14539. this.model = {
  14540. autoFilterRef: node.attributes.ref,
  14541. columns: []
  14542. };
  14543. return true;
  14544. default:
  14545. this.parser = this.map[node.name];
  14546. if (this.parser) {
  14547. this.parseOpen(node);
  14548. return true;
  14549. }
  14550. throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
  14551. }
  14552. }
  14553. parseText(text) {
  14554. if (this.parser) {
  14555. this.parser.parseText(text);
  14556. }
  14557. }
  14558. parseClose(name) {
  14559. if (this.parser) {
  14560. if (!this.parser.parseClose(name)) {
  14561. this.model.columns.push(this.parser.model);
  14562. this.parser = undefined;
  14563. }
  14564. return true;
  14565. }
  14566. switch (name) {
  14567. case this.tag:
  14568. return false;
  14569. default:
  14570. throw new Error(`Unexpected xml node in parseClose: ${name}`);
  14571. }
  14572. }
  14573. }
  14574. module.exports = AutoFilterXform;
  14575. },{"../base-xform":32,"./filter-column-xform":139}],138:[function(require,module,exports){
  14576. "use strict";
  14577. const BaseXform = require('../base-xform');
  14578. class CustomFilterXform extends BaseXform {
  14579. get tag() {
  14580. return 'customFilter';
  14581. }
  14582. render(xmlStream, model) {
  14583. xmlStream.leafNode(this.tag, {
  14584. val: model.val,
  14585. operator: model.operator
  14586. });
  14587. }
  14588. parseOpen(node) {
  14589. if (node.name === this.tag) {
  14590. this.model = {
  14591. val: node.attributes.val,
  14592. operator: node.attributes.operator
  14593. };
  14594. return true;
  14595. }
  14596. return false;
  14597. }
  14598. parseText() {}
  14599. parseClose() {
  14600. return false;
  14601. }
  14602. }
  14603. module.exports = CustomFilterXform;
  14604. },{"../base-xform":32}],139:[function(require,module,exports){
  14605. "use strict";
  14606. const BaseXform = require('../base-xform');
  14607. const ListXform = require('../list-xform');
  14608. const CustomFilterXform = require('./custom-filter-xform');
  14609. const FilterXform = require('./filter-xform');
  14610. class FilterColumnXform extends BaseXform {
  14611. constructor() {
  14612. super();
  14613. this.map = {
  14614. customFilters: new ListXform({
  14615. tag: 'customFilters',
  14616. count: false,
  14617. empty: true,
  14618. childXform: new CustomFilterXform()
  14619. }),
  14620. filters: new ListXform({
  14621. tag: 'filters',
  14622. count: false,
  14623. empty: true,
  14624. childXform: new FilterXform()
  14625. })
  14626. };
  14627. }
  14628. get tag() {
  14629. return 'filterColumn';
  14630. }
  14631. prepare(model, options) {
  14632. model.colId = options.index.toString();
  14633. }
  14634. render(xmlStream, model) {
  14635. if (model.customFilters) {
  14636. xmlStream.openNode(this.tag, {
  14637. colId: model.colId,
  14638. hiddenButton: model.filterButton ? '0' : '1'
  14639. });
  14640. this.map.customFilters.render(xmlStream, model.customFilters);
  14641. xmlStream.closeNode();
  14642. return true;
  14643. }
  14644. xmlStream.leafNode(this.tag, {
  14645. colId: model.colId,
  14646. hiddenButton: model.filterButton ? '0' : '1'
  14647. });
  14648. return true;
  14649. }
  14650. parseOpen(node) {
  14651. if (this.parser) {
  14652. this.parser.parseOpen(node);
  14653. return true;
  14654. }
  14655. const {
  14656. attributes
  14657. } = node;
  14658. switch (node.name) {
  14659. case this.tag:
  14660. this.model = {
  14661. filterButton: attributes.hiddenButton === '0'
  14662. };
  14663. return true;
  14664. default:
  14665. this.parser = this.map[node.name];
  14666. if (this.parser) {
  14667. this.parseOpen(node);
  14668. return true;
  14669. }
  14670. throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
  14671. }
  14672. }
  14673. parseText() {}
  14674. parseClose(name) {
  14675. if (this.parser) {
  14676. if (!this.parser.parseClose(name)) {
  14677. this.parser = undefined;
  14678. }
  14679. return true;
  14680. }
  14681. switch (name) {
  14682. case this.tag:
  14683. this.model.customFilters = this.map.customFilters.model;
  14684. return false;
  14685. default:
  14686. // could be some unrecognised tags
  14687. return true;
  14688. }
  14689. }
  14690. }
  14691. module.exports = FilterColumnXform;
  14692. },{"../base-xform":32,"../list-xform":71,"./custom-filter-xform":138,"./filter-xform":140}],140:[function(require,module,exports){
  14693. "use strict";
  14694. const BaseXform = require('../base-xform');
  14695. class FilterXform extends BaseXform {
  14696. get tag() {
  14697. return 'filter';
  14698. }
  14699. render(xmlStream, model) {
  14700. xmlStream.leafNode(this.tag, {
  14701. val: model.val
  14702. });
  14703. }
  14704. parseOpen(node) {
  14705. if (node.name === this.tag) {
  14706. this.model = {
  14707. val: node.attributes.val
  14708. };
  14709. return true;
  14710. }
  14711. return false;
  14712. }
  14713. parseText() {}
  14714. parseClose() {
  14715. return false;
  14716. }
  14717. }
  14718. module.exports = FilterXform;
  14719. },{"../base-xform":32}],141:[function(require,module,exports){
  14720. "use strict";
  14721. const BaseXform = require('../base-xform');
  14722. class TableColumnXform extends BaseXform {
  14723. get tag() {
  14724. return 'tableColumn';
  14725. }
  14726. prepare(model, options) {
  14727. model.id = options.index + 1;
  14728. }
  14729. render(xmlStream, model) {
  14730. xmlStream.leafNode(this.tag, {
  14731. id: model.id.toString(),
  14732. name: model.name,
  14733. totalsRowLabel: model.totalsRowLabel,
  14734. totalsRowFunction: model.totalsRowFunction,
  14735. dxfId: model.dxfId
  14736. });
  14737. return true;
  14738. }
  14739. parseOpen(node) {
  14740. if (node.name === this.tag) {
  14741. const {
  14742. attributes
  14743. } = node;
  14744. this.model = {
  14745. name: attributes.name,
  14746. totalsRowLabel: attributes.totalsRowLabel,
  14747. totalsRowFunction: attributes.totalsRowFunction,
  14748. dxfId: attributes.dxfId
  14749. };
  14750. return true;
  14751. }
  14752. return false;
  14753. }
  14754. parseText() {}
  14755. parseClose() {
  14756. return false;
  14757. }
  14758. }
  14759. module.exports = TableColumnXform;
  14760. },{"../base-xform":32}],142:[function(require,module,exports){
  14761. "use strict";
  14762. const BaseXform = require('../base-xform');
  14763. class TableStyleInfoXform extends BaseXform {
  14764. get tag() {
  14765. return 'tableStyleInfo';
  14766. }
  14767. render(xmlStream, model) {
  14768. xmlStream.leafNode(this.tag, {
  14769. name: model.theme ? model.theme : undefined,
  14770. showFirstColumn: model.showFirstColumn ? '1' : '0',
  14771. showLastColumn: model.showLastColumn ? '1' : '0',
  14772. showRowStripes: model.showRowStripes ? '1' : '0',
  14773. showColumnStripes: model.showColumnStripes ? '1' : '0'
  14774. });
  14775. return true;
  14776. }
  14777. parseOpen(node) {
  14778. if (node.name === this.tag) {
  14779. const {
  14780. attributes
  14781. } = node;
  14782. this.model = {
  14783. theme: attributes.name ? attributes.name : null,
  14784. showFirstColumn: attributes.showFirstColumn === '1',
  14785. showLastColumn: attributes.showLastColumn === '1',
  14786. showRowStripes: attributes.showRowStripes === '1',
  14787. showColumnStripes: attributes.showColumnStripes === '1'
  14788. };
  14789. return true;
  14790. }
  14791. return false;
  14792. }
  14793. parseText() {}
  14794. parseClose() {
  14795. return false;
  14796. }
  14797. }
  14798. module.exports = TableStyleInfoXform;
  14799. },{"../base-xform":32}],143:[function(require,module,exports){
  14800. "use strict";
  14801. const XmlStream = require('../../../utils/xml-stream');
  14802. const BaseXform = require('../base-xform');
  14803. const ListXform = require('../list-xform');
  14804. const AutoFilterXform = require('./auto-filter-xform');
  14805. const TableColumnXform = require('./table-column-xform');
  14806. const TableStyleInfoXform = require('./table-style-info-xform');
  14807. class TableXform extends BaseXform {
  14808. constructor() {
  14809. super();
  14810. this.map = {
  14811. autoFilter: new AutoFilterXform(),
  14812. tableColumns: new ListXform({
  14813. tag: 'tableColumns',
  14814. count: true,
  14815. empty: true,
  14816. childXform: new TableColumnXform()
  14817. }),
  14818. tableStyleInfo: new TableStyleInfoXform()
  14819. };
  14820. }
  14821. prepare(model, options) {
  14822. this.map.autoFilter.prepare(model);
  14823. this.map.tableColumns.prepare(model.columns, options);
  14824. }
  14825. get tag() {
  14826. return 'table';
  14827. }
  14828. render(xmlStream, model) {
  14829. xmlStream.openXml(XmlStream.StdDocAttributes);
  14830. xmlStream.openNode(this.tag, {
  14831. ...TableXform.TABLE_ATTRIBUTES,
  14832. id: model.id,
  14833. name: model.name,
  14834. displayName: model.displayName || model.name,
  14835. ref: model.tableRef,
  14836. totalsRowCount: model.totalsRow ? '1' : undefined,
  14837. totalsRowShown: model.totalsRow ? undefined : '1',
  14838. headerRowCount: model.headerRow ? '1' : '0'
  14839. });
  14840. this.map.autoFilter.render(xmlStream, model);
  14841. this.map.tableColumns.render(xmlStream, model.columns);
  14842. this.map.tableStyleInfo.render(xmlStream, model.style);
  14843. xmlStream.closeNode();
  14844. }
  14845. parseOpen(node) {
  14846. if (this.parser) {
  14847. this.parser.parseOpen(node);
  14848. return true;
  14849. }
  14850. const {
  14851. name,
  14852. attributes
  14853. } = node;
  14854. switch (name) {
  14855. case this.tag:
  14856. this.reset();
  14857. this.model = {
  14858. name: attributes.name,
  14859. displayName: attributes.displayName || attributes.name,
  14860. tableRef: attributes.ref,
  14861. totalsRow: attributes.totalsRowCount === '1',
  14862. headerRow: attributes.headerRowCount === '1'
  14863. };
  14864. break;
  14865. default:
  14866. this.parser = this.map[node.name];
  14867. if (this.parser) {
  14868. this.parser.parseOpen(node);
  14869. }
  14870. break;
  14871. }
  14872. return true;
  14873. }
  14874. parseText(text) {
  14875. if (this.parser) {
  14876. this.parser.parseText(text);
  14877. }
  14878. }
  14879. parseClose(name) {
  14880. if (this.parser) {
  14881. if (!this.parser.parseClose(name)) {
  14882. this.parser = undefined;
  14883. }
  14884. return true;
  14885. }
  14886. switch (name) {
  14887. case this.tag:
  14888. this.model.columns = this.map.tableColumns.model;
  14889. if (this.map.autoFilter.model) {
  14890. this.model.autoFilterRef = this.map.autoFilter.model.autoFilterRef;
  14891. this.map.autoFilter.model.columns.forEach((column, index) => {
  14892. this.model.columns[index].filterButton = column.filterButton;
  14893. });
  14894. }
  14895. this.model.style = this.map.tableStyleInfo.model;
  14896. return false;
  14897. default:
  14898. // could be some unrecognised tags
  14899. return true;
  14900. }
  14901. }
  14902. reconcile(model, options) {
  14903. // fetch the dfxs from styles
  14904. model.columns.forEach(column => {
  14905. if (column.dxfId !== undefined) {
  14906. column.style = options.styles.getDxfStyle(column.dxfId);
  14907. }
  14908. });
  14909. }
  14910. }
  14911. TableXform.TABLE_ATTRIBUTES = {
  14912. xmlns: 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
  14913. 'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
  14914. 'mc:Ignorable': 'xr xr3',
  14915. 'xmlns:xr': 'http://schemas.microsoft.com/office/spreadsheetml/2014/revision',
  14916. 'xmlns:xr3': 'http://schemas.microsoft.com/office/spreadsheetml/2016/revision3'
  14917. // 'xr:uid': '{00000000-000C-0000-FFFF-FFFF00000000}',
  14918. };
  14919. module.exports = TableXform;
  14920. },{"../../../utils/xml-stream":28,"../base-xform":32,"../list-xform":71,"./auto-filter-xform":137,"./table-column-xform":141,"./table-style-info-xform":142}],144:[function(require,module,exports){
  14921. (function (process,Buffer){(function (){
  14922. "use strict";
  14923. const fs = require('fs');
  14924. const JSZip = require('jszip');
  14925. const {
  14926. PassThrough
  14927. } = require('readable-stream');
  14928. const ZipStream = require('../utils/zip-stream');
  14929. const StreamBuf = require('../utils/stream-buf');
  14930. const utils = require('../utils/utils');
  14931. const XmlStream = require('../utils/xml-stream');
  14932. const {
  14933. bufferToString
  14934. } = require('../utils/browser-buffer-decode');
  14935. const StylesXform = require('./xform/style/styles-xform');
  14936. const CoreXform = require('./xform/core/core-xform');
  14937. const SharedStringsXform = require('./xform/strings/shared-strings-xform');
  14938. const RelationshipsXform = require('./xform/core/relationships-xform');
  14939. const ContentTypesXform = require('./xform/core/content-types-xform');
  14940. const AppXform = require('./xform/core/app-xform');
  14941. const WorkbookXform = require('./xform/book/workbook-xform');
  14942. const WorksheetXform = require('./xform/sheet/worksheet-xform');
  14943. const DrawingXform = require('./xform/drawing/drawing-xform');
  14944. const TableXform = require('./xform/table/table-xform');
  14945. const CommentsXform = require('./xform/comment/comments-xform');
  14946. const VmlNotesXform = require('./xform/comment/vml-notes-xform');
  14947. const theme1Xml = require('./xml/theme1');
  14948. function fsReadFileAsync(filename, options) {
  14949. return new Promise((resolve, reject) => {
  14950. fs.readFile(filename, options, (error, data) => {
  14951. if (error) {
  14952. reject(error);
  14953. } else {
  14954. resolve(data);
  14955. }
  14956. });
  14957. });
  14958. }
  14959. class XLSX {
  14960. constructor(workbook) {
  14961. this.workbook = workbook;
  14962. }
  14963. // ===============================================================================
  14964. // Workbook
  14965. // =========================================================================
  14966. // Read
  14967. async readFile(filename, options) {
  14968. if (!(await utils.fs.exists(filename))) {
  14969. throw new Error(`File not found: ${filename}`);
  14970. }
  14971. const stream = fs.createReadStream(filename);
  14972. try {
  14973. const workbook = await this.read(stream, options);
  14974. stream.close();
  14975. return workbook;
  14976. } catch (error) {
  14977. stream.close();
  14978. throw error;
  14979. }
  14980. }
  14981. parseRels(stream) {
  14982. const xform = new RelationshipsXform();
  14983. return xform.parseStream(stream);
  14984. }
  14985. parseWorkbook(stream) {
  14986. const xform = new WorkbookXform();
  14987. return xform.parseStream(stream);
  14988. }
  14989. parseSharedStrings(stream) {
  14990. const xform = new SharedStringsXform();
  14991. return xform.parseStream(stream);
  14992. }
  14993. reconcile(model, options) {
  14994. const workbookXform = new WorkbookXform();
  14995. const worksheetXform = new WorksheetXform(options);
  14996. const drawingXform = new DrawingXform();
  14997. const tableXform = new TableXform();
  14998. workbookXform.reconcile(model);
  14999. // reconcile drawings with their rels
  15000. const drawingOptions = {
  15001. media: model.media,
  15002. mediaIndex: model.mediaIndex
  15003. };
  15004. Object.keys(model.drawings).forEach(name => {
  15005. const drawing = model.drawings[name];
  15006. const drawingRel = model.drawingRels[name];
  15007. if (drawingRel) {
  15008. drawingOptions.rels = drawingRel.reduce((o, rel) => {
  15009. o[rel.Id] = rel;
  15010. return o;
  15011. }, {});
  15012. (drawing.anchors || []).forEach(anchor => {
  15013. const hyperlinks = anchor.picture && anchor.picture.hyperlinks;
  15014. if (hyperlinks && drawingOptions.rels[hyperlinks.rId]) {
  15015. hyperlinks.hyperlink = drawingOptions.rels[hyperlinks.rId].Target;
  15016. delete hyperlinks.rId;
  15017. }
  15018. });
  15019. drawingXform.reconcile(drawing, drawingOptions);
  15020. }
  15021. });
  15022. // reconcile tables with the default styles
  15023. const tableOptions = {
  15024. styles: model.styles
  15025. };
  15026. Object.values(model.tables).forEach(table => {
  15027. tableXform.reconcile(table, tableOptions);
  15028. });
  15029. const sheetOptions = {
  15030. styles: model.styles,
  15031. sharedStrings: model.sharedStrings,
  15032. media: model.media,
  15033. mediaIndex: model.mediaIndex,
  15034. date1904: model.properties && model.properties.date1904,
  15035. drawings: model.drawings,
  15036. comments: model.comments,
  15037. tables: model.tables,
  15038. vmlDrawings: model.vmlDrawings
  15039. };
  15040. model.worksheets.forEach(worksheet => {
  15041. worksheet.relationships = model.worksheetRels[worksheet.sheetNo];
  15042. worksheetXform.reconcile(worksheet, sheetOptions);
  15043. });
  15044. // delete unnecessary parts
  15045. delete model.worksheetHash;
  15046. delete model.worksheetRels;
  15047. delete model.globalRels;
  15048. delete model.sharedStrings;
  15049. delete model.workbookRels;
  15050. delete model.sheetDefs;
  15051. delete model.styles;
  15052. delete model.mediaIndex;
  15053. delete model.drawings;
  15054. delete model.drawingRels;
  15055. delete model.vmlDrawings;
  15056. }
  15057. async _processWorksheetEntry(stream, model, sheetNo, options, path) {
  15058. const xform = new WorksheetXform(options);
  15059. const worksheet = await xform.parseStream(stream);
  15060. worksheet.sheetNo = sheetNo;
  15061. model.worksheetHash[path] = worksheet;
  15062. model.worksheets.push(worksheet);
  15063. }
  15064. async _processCommentEntry(stream, model, name) {
  15065. const xform = new CommentsXform();
  15066. const comments = await xform.parseStream(stream);
  15067. model.comments[`../${name}.xml`] = comments;
  15068. }
  15069. async _processTableEntry(stream, model, name) {
  15070. const xform = new TableXform();
  15071. const table = await xform.parseStream(stream);
  15072. model.tables[`../tables/${name}.xml`] = table;
  15073. }
  15074. async _processWorksheetRelsEntry(stream, model, sheetNo) {
  15075. const xform = new RelationshipsXform();
  15076. const relationships = await xform.parseStream(stream);
  15077. model.worksheetRels[sheetNo] = relationships;
  15078. }
  15079. async _processMediaEntry(entry, model, filename) {
  15080. const lastDot = filename.lastIndexOf('.');
  15081. // if we can't determine extension, ignore it
  15082. if (lastDot >= 1) {
  15083. const extension = filename.substr(lastDot + 1);
  15084. const name = filename.substr(0, lastDot);
  15085. await new Promise((resolve, reject) => {
  15086. const streamBuf = new StreamBuf();
  15087. streamBuf.on('finish', () => {
  15088. model.mediaIndex[filename] = model.media.length;
  15089. model.mediaIndex[name] = model.media.length;
  15090. const medium = {
  15091. type: 'image',
  15092. name,
  15093. extension,
  15094. buffer: streamBuf.toBuffer()
  15095. };
  15096. model.media.push(medium);
  15097. resolve();
  15098. });
  15099. entry.on('error', error => {
  15100. reject(error);
  15101. });
  15102. entry.pipe(streamBuf);
  15103. });
  15104. }
  15105. }
  15106. async _processDrawingEntry(entry, model, name) {
  15107. const xform = new DrawingXform();
  15108. const drawing = await xform.parseStream(entry);
  15109. model.drawings[name] = drawing;
  15110. }
  15111. async _processDrawingRelsEntry(entry, model, name) {
  15112. const xform = new RelationshipsXform();
  15113. const relationships = await xform.parseStream(entry);
  15114. model.drawingRels[name] = relationships;
  15115. }
  15116. async _processVmlDrawingEntry(entry, model, name) {
  15117. const xform = new VmlNotesXform();
  15118. const vmlDrawing = await xform.parseStream(entry);
  15119. model.vmlDrawings[`../drawings/${name}.vml`] = vmlDrawing;
  15120. }
  15121. async _processThemeEntry(entry, model, name) {
  15122. await new Promise((resolve, reject) => {
  15123. // TODO: stream entry into buffer and store the xml in the model.themes[]
  15124. const stream = new StreamBuf();
  15125. entry.on('error', reject);
  15126. stream.on('error', reject);
  15127. stream.on('finish', () => {
  15128. model.themes[name] = stream.read().toString();
  15129. resolve();
  15130. });
  15131. entry.pipe(stream);
  15132. });
  15133. }
  15134. /**
  15135. * @deprecated since version 4.0. You should use `#read` instead. Please follow upgrade instruction: https://github.com/exceljs/exceljs/blob/master/UPGRADE-4.0.md
  15136. */
  15137. createInputStream() {
  15138. throw new Error('`XLSX#createInputStream` is deprecated. You should use `XLSX#read` instead. This method will be removed in version 5.0. Please follow upgrade instruction: https://github.com/exceljs/exceljs/blob/master/UPGRADE-4.0.md');
  15139. }
  15140. async read(stream, options) {
  15141. // TODO: Remove once node v8 is deprecated
  15142. // Detect and upgrade old streams
  15143. if (!stream[Symbol.asyncIterator] && stream.pipe) {
  15144. stream = stream.pipe(new PassThrough());
  15145. }
  15146. const chunks = [];
  15147. for await (const chunk of stream) {
  15148. chunks.push(chunk);
  15149. }
  15150. return this.load(Buffer.concat(chunks), options);
  15151. }
  15152. async load(data, options) {
  15153. let buffer;
  15154. if (options && options.base64) {
  15155. buffer = Buffer.from(data.toString(), 'base64');
  15156. } else {
  15157. buffer = data;
  15158. }
  15159. const model = {
  15160. worksheets: [],
  15161. worksheetHash: {},
  15162. worksheetRels: [],
  15163. themes: {},
  15164. media: [],
  15165. mediaIndex: {},
  15166. drawings: {},
  15167. drawingRels: {},
  15168. comments: {},
  15169. tables: {},
  15170. vmlDrawings: {}
  15171. };
  15172. const zip = await JSZip.loadAsync(buffer);
  15173. for (const entry of Object.values(zip.files)) {
  15174. /* eslint-disable no-await-in-loop */
  15175. if (!entry.dir) {
  15176. let entryName = entry.name;
  15177. if (entryName[0] === '/') {
  15178. entryName = entryName.substr(1);
  15179. }
  15180. let stream;
  15181. if (entryName.match(/xl\/media\//) ||
  15182. // themes are not parsed as stream
  15183. entryName.match(/xl\/theme\/([a-zA-Z0-9]+)[.]xml/)) {
  15184. stream = new PassThrough();
  15185. stream.write(await entry.async('nodebuffer'));
  15186. } else {
  15187. // use object mode to avoid buffer-string convention
  15188. stream = new PassThrough({
  15189. writableObjectMode: true,
  15190. readableObjectMode: true
  15191. });
  15192. let content;
  15193. // https://www.npmjs.com/package/process
  15194. if (process.browser) {
  15195. // running in browser, use TextDecoder if possible
  15196. content = bufferToString(await entry.async('nodebuffer'));
  15197. } else {
  15198. // running in node.js
  15199. content = await entry.async('string');
  15200. }
  15201. const chunkSize = 16 * 1024;
  15202. for (let i = 0; i < content.length; i += chunkSize) {
  15203. stream.write(content.substring(i, i + chunkSize));
  15204. }
  15205. }
  15206. stream.end();
  15207. switch (entryName) {
  15208. case '_rels/.rels':
  15209. model.globalRels = await this.parseRels(stream);
  15210. break;
  15211. case 'xl/workbook.xml':
  15212. {
  15213. const workbook = await this.parseWorkbook(stream);
  15214. model.sheets = workbook.sheets;
  15215. model.definedNames = workbook.definedNames;
  15216. model.views = workbook.views;
  15217. model.properties = workbook.properties;
  15218. model.calcProperties = workbook.calcProperties;
  15219. break;
  15220. }
  15221. case 'xl/_rels/workbook.xml.rels':
  15222. model.workbookRels = await this.parseRels(stream);
  15223. break;
  15224. case 'xl/sharedStrings.xml':
  15225. model.sharedStrings = new SharedStringsXform();
  15226. await model.sharedStrings.parseStream(stream);
  15227. break;
  15228. case 'xl/styles.xml':
  15229. model.styles = new StylesXform();
  15230. await model.styles.parseStream(stream);
  15231. break;
  15232. case 'docProps/app.xml':
  15233. {
  15234. const appXform = new AppXform();
  15235. const appProperties = await appXform.parseStream(stream);
  15236. model.company = appProperties.company;
  15237. model.manager = appProperties.manager;
  15238. break;
  15239. }
  15240. case 'docProps/core.xml':
  15241. {
  15242. const coreXform = new CoreXform();
  15243. const coreProperties = await coreXform.parseStream(stream);
  15244. Object.assign(model, coreProperties);
  15245. break;
  15246. }
  15247. default:
  15248. {
  15249. let match = entryName.match(/xl\/worksheets\/sheet(\d+)[.]xml/);
  15250. if (match) {
  15251. await this._processWorksheetEntry(stream, model, match[1], options, entryName);
  15252. break;
  15253. }
  15254. match = entryName.match(/xl\/worksheets\/_rels\/sheet(\d+)[.]xml.rels/);
  15255. if (match) {
  15256. await this._processWorksheetRelsEntry(stream, model, match[1]);
  15257. break;
  15258. }
  15259. match = entryName.match(/xl\/theme\/([a-zA-Z0-9]+)[.]xml/);
  15260. if (match) {
  15261. await this._processThemeEntry(stream, model, match[1]);
  15262. break;
  15263. }
  15264. match = entryName.match(/xl\/media\/([a-zA-Z0-9]+[.][a-zA-Z0-9]{3,4})$/);
  15265. if (match) {
  15266. await this._processMediaEntry(stream, model, match[1]);
  15267. break;
  15268. }
  15269. match = entryName.match(/xl\/drawings\/([a-zA-Z0-9]+)[.]xml/);
  15270. if (match) {
  15271. await this._processDrawingEntry(stream, model, match[1]);
  15272. break;
  15273. }
  15274. match = entryName.match(/xl\/(comments\d+)[.]xml/);
  15275. if (match) {
  15276. await this._processCommentEntry(stream, model, match[1]);
  15277. break;
  15278. }
  15279. match = entryName.match(/xl\/tables\/(table\d+)[.]xml/);
  15280. if (match) {
  15281. await this._processTableEntry(stream, model, match[1]);
  15282. break;
  15283. }
  15284. match = entryName.match(/xl\/drawings\/_rels\/([a-zA-Z0-9]+)[.]xml[.]rels/);
  15285. if (match) {
  15286. await this._processDrawingRelsEntry(stream, model, match[1]);
  15287. break;
  15288. }
  15289. match = entryName.match(/xl\/drawings\/(vmlDrawing\d+)[.]vml/);
  15290. if (match) {
  15291. await this._processVmlDrawingEntry(stream, model, match[1]);
  15292. break;
  15293. }
  15294. }
  15295. }
  15296. }
  15297. }
  15298. this.reconcile(model, options);
  15299. // apply model
  15300. this.workbook.model = model;
  15301. return this.workbook;
  15302. }
  15303. // =========================================================================
  15304. // Write
  15305. async addMedia(zip, model) {
  15306. await Promise.all(model.media.map(async medium => {
  15307. if (medium.type === 'image') {
  15308. const filename = `xl/media/${medium.name}.${medium.extension}`;
  15309. if (medium.filename) {
  15310. const data = await fsReadFileAsync(medium.filename);
  15311. return zip.append(data, {
  15312. name: filename
  15313. });
  15314. }
  15315. if (medium.buffer) {
  15316. return zip.append(medium.buffer, {
  15317. name: filename
  15318. });
  15319. }
  15320. if (medium.base64) {
  15321. const dataimg64 = medium.base64;
  15322. const content = dataimg64.substring(dataimg64.indexOf(',') + 1);
  15323. return zip.append(content, {
  15324. name: filename,
  15325. base64: true
  15326. });
  15327. }
  15328. }
  15329. throw new Error('Unsupported media');
  15330. }));
  15331. }
  15332. addDrawings(zip, model) {
  15333. const drawingXform = new DrawingXform();
  15334. const relsXform = new RelationshipsXform();
  15335. model.worksheets.forEach(worksheet => {
  15336. const {
  15337. drawing
  15338. } = worksheet;
  15339. if (drawing) {
  15340. drawingXform.prepare(drawing, {});
  15341. let xml = drawingXform.toXml(drawing);
  15342. zip.append(xml, {
  15343. name: `xl/drawings/${drawing.name}.xml`
  15344. });
  15345. xml = relsXform.toXml(drawing.rels);
  15346. zip.append(xml, {
  15347. name: `xl/drawings/_rels/${drawing.name}.xml.rels`
  15348. });
  15349. }
  15350. });
  15351. }
  15352. addTables(zip, model) {
  15353. const tableXform = new TableXform();
  15354. model.worksheets.forEach(worksheet => {
  15355. const {
  15356. tables
  15357. } = worksheet;
  15358. tables.forEach(table => {
  15359. tableXform.prepare(table, {});
  15360. const tableXml = tableXform.toXml(table);
  15361. zip.append(tableXml, {
  15362. name: `xl/tables/${table.target}`
  15363. });
  15364. });
  15365. });
  15366. }
  15367. async addContentTypes(zip, model) {
  15368. const xform = new ContentTypesXform();
  15369. const xml = xform.toXml(model);
  15370. zip.append(xml, {
  15371. name: '[Content_Types].xml'
  15372. });
  15373. }
  15374. async addApp(zip, model) {
  15375. const xform = new AppXform();
  15376. const xml = xform.toXml(model);
  15377. zip.append(xml, {
  15378. name: 'docProps/app.xml'
  15379. });
  15380. }
  15381. async addCore(zip, model) {
  15382. const coreXform = new CoreXform();
  15383. zip.append(coreXform.toXml(model), {
  15384. name: 'docProps/core.xml'
  15385. });
  15386. }
  15387. async addThemes(zip, model) {
  15388. const themes = model.themes || {
  15389. theme1: theme1Xml
  15390. };
  15391. Object.keys(themes).forEach(name => {
  15392. const xml = themes[name];
  15393. const path = `xl/theme/${name}.xml`;
  15394. zip.append(xml, {
  15395. name: path
  15396. });
  15397. });
  15398. }
  15399. async addOfficeRels(zip) {
  15400. const xform = new RelationshipsXform();
  15401. const xml = xform.toXml([{
  15402. Id: 'rId1',
  15403. Type: XLSX.RelType.OfficeDocument,
  15404. Target: 'xl/workbook.xml'
  15405. }, {
  15406. Id: 'rId2',
  15407. Type: XLSX.RelType.CoreProperties,
  15408. Target: 'docProps/core.xml'
  15409. }, {
  15410. Id: 'rId3',
  15411. Type: XLSX.RelType.ExtenderProperties,
  15412. Target: 'docProps/app.xml'
  15413. }]);
  15414. zip.append(xml, {
  15415. name: '_rels/.rels'
  15416. });
  15417. }
  15418. async addWorkbookRels(zip, model) {
  15419. let count = 1;
  15420. const relationships = [{
  15421. Id: `rId${count++}`,
  15422. Type: XLSX.RelType.Styles,
  15423. Target: 'styles.xml'
  15424. }, {
  15425. Id: `rId${count++}`,
  15426. Type: XLSX.RelType.Theme,
  15427. Target: 'theme/theme1.xml'
  15428. }];
  15429. if (model.sharedStrings.count) {
  15430. relationships.push({
  15431. Id: `rId${count++}`,
  15432. Type: XLSX.RelType.SharedStrings,
  15433. Target: 'sharedStrings.xml'
  15434. });
  15435. }
  15436. model.worksheets.forEach(worksheet => {
  15437. worksheet.rId = `rId${count++}`;
  15438. relationships.push({
  15439. Id: worksheet.rId,
  15440. Type: XLSX.RelType.Worksheet,
  15441. Target: `worksheets/sheet${worksheet.id}.xml`
  15442. });
  15443. });
  15444. const xform = new RelationshipsXform();
  15445. const xml = xform.toXml(relationships);
  15446. zip.append(xml, {
  15447. name: 'xl/_rels/workbook.xml.rels'
  15448. });
  15449. }
  15450. async addSharedStrings(zip, model) {
  15451. if (model.sharedStrings && model.sharedStrings.count) {
  15452. zip.append(model.sharedStrings.xml, {
  15453. name: 'xl/sharedStrings.xml'
  15454. });
  15455. }
  15456. }
  15457. async addStyles(zip, model) {
  15458. const {
  15459. xml
  15460. } = model.styles;
  15461. if (xml) {
  15462. zip.append(xml, {
  15463. name: 'xl/styles.xml'
  15464. });
  15465. }
  15466. }
  15467. async addWorkbook(zip, model) {
  15468. const xform = new WorkbookXform();
  15469. zip.append(xform.toXml(model), {
  15470. name: 'xl/workbook.xml'
  15471. });
  15472. }
  15473. async addWorksheets(zip, model) {
  15474. // preparation phase
  15475. const worksheetXform = new WorksheetXform();
  15476. const relationshipsXform = new RelationshipsXform();
  15477. const commentsXform = new CommentsXform();
  15478. const vmlNotesXform = new VmlNotesXform();
  15479. // write sheets
  15480. model.worksheets.forEach(worksheet => {
  15481. let xmlStream = new XmlStream();
  15482. worksheetXform.render(xmlStream, worksheet);
  15483. zip.append(xmlStream.xml, {
  15484. name: `xl/worksheets/sheet${worksheet.id}.xml`
  15485. });
  15486. if (worksheet.rels && worksheet.rels.length) {
  15487. xmlStream = new XmlStream();
  15488. relationshipsXform.render(xmlStream, worksheet.rels);
  15489. zip.append(xmlStream.xml, {
  15490. name: `xl/worksheets/_rels/sheet${worksheet.id}.xml.rels`
  15491. });
  15492. }
  15493. if (worksheet.comments.length > 0) {
  15494. xmlStream = new XmlStream();
  15495. commentsXform.render(xmlStream, worksheet);
  15496. zip.append(xmlStream.xml, {
  15497. name: `xl/comments${worksheet.id}.xml`
  15498. });
  15499. xmlStream = new XmlStream();
  15500. vmlNotesXform.render(xmlStream, worksheet);
  15501. zip.append(xmlStream.xml, {
  15502. name: `xl/drawings/vmlDrawing${worksheet.id}.vml`
  15503. });
  15504. }
  15505. });
  15506. }
  15507. _finalize(zip) {
  15508. return new Promise((resolve, reject) => {
  15509. zip.on('finish', () => {
  15510. resolve(this);
  15511. });
  15512. zip.on('error', reject);
  15513. zip.finalize();
  15514. });
  15515. }
  15516. prepareModel(model, options) {
  15517. // ensure following properties have sane values
  15518. model.creator = model.creator || 'ExcelJS';
  15519. model.lastModifiedBy = model.lastModifiedBy || 'ExcelJS';
  15520. model.created = model.created || new Date();
  15521. model.modified = model.modified || new Date();
  15522. model.useSharedStrings = options.useSharedStrings !== undefined ? options.useSharedStrings : true;
  15523. model.useStyles = options.useStyles !== undefined ? options.useStyles : true;
  15524. // Manage the shared strings
  15525. model.sharedStrings = new SharedStringsXform();
  15526. // add a style manager to handle cell formats, fonts, etc.
  15527. model.styles = model.useStyles ? new StylesXform(true) : new StylesXform.Mock();
  15528. // prepare all of the things before the render
  15529. const workbookXform = new WorkbookXform();
  15530. const worksheetXform = new WorksheetXform();
  15531. workbookXform.prepare(model);
  15532. const worksheetOptions = {
  15533. sharedStrings: model.sharedStrings,
  15534. styles: model.styles,
  15535. date1904: model.properties.date1904,
  15536. drawingsCount: 0,
  15537. media: model.media
  15538. };
  15539. worksheetOptions.drawings = model.drawings = [];
  15540. worksheetOptions.commentRefs = model.commentRefs = [];
  15541. let tableCount = 0;
  15542. model.tables = [];
  15543. model.worksheets.forEach(worksheet => {
  15544. // assign unique filenames to tables
  15545. worksheet.tables.forEach(table => {
  15546. tableCount++;
  15547. table.target = `table${tableCount}.xml`;
  15548. table.id = tableCount;
  15549. model.tables.push(table);
  15550. });
  15551. worksheetXform.prepare(worksheet, worksheetOptions);
  15552. });
  15553. // TODO: workbook drawing list
  15554. }
  15555. async write(stream, options) {
  15556. options = options || {};
  15557. const {
  15558. model
  15559. } = this.workbook;
  15560. const zip = new ZipStream.ZipWriter(options.zip);
  15561. zip.pipe(stream);
  15562. this.prepareModel(model, options);
  15563. // render
  15564. await this.addContentTypes(zip, model);
  15565. await this.addOfficeRels(zip, model);
  15566. await this.addWorkbookRels(zip, model);
  15567. await this.addWorksheets(zip, model);
  15568. await this.addSharedStrings(zip, model); // always after worksheets
  15569. await this.addDrawings(zip, model);
  15570. await this.addTables(zip, model);
  15571. await Promise.all([this.addThemes(zip, model), this.addStyles(zip, model)]);
  15572. await this.addMedia(zip, model);
  15573. await Promise.all([this.addApp(zip, model), this.addCore(zip, model)]);
  15574. await this.addWorkbook(zip, model);
  15575. return this._finalize(zip);
  15576. }
  15577. writeFile(filename, options) {
  15578. const stream = fs.createWriteStream(filename);
  15579. return new Promise((resolve, reject) => {
  15580. stream.on('finish', () => {
  15581. resolve();
  15582. });
  15583. stream.on('error', error => {
  15584. reject(error);
  15585. });
  15586. this.write(stream, options).then(() => {
  15587. stream.end();
  15588. }).catch(err => {
  15589. reject(err);
  15590. });
  15591. });
  15592. }
  15593. async writeBuffer(options) {
  15594. const stream = new StreamBuf();
  15595. await this.write(stream, options);
  15596. return stream.read();
  15597. }
  15598. }
  15599. XLSX.RelType = require('./rel-type');
  15600. module.exports = XLSX;
  15601. }).call(this)}).call(this,require('_process'),require("buffer").Buffer)
  15602. },{"../utils/browser-buffer-decode":16,"../utils/stream-buf":24,"../utils/utils":27,"../utils/xml-stream":28,"../utils/zip-stream":29,"./rel-type":31,"./xform/book/workbook-xform":38,"./xform/comment/comments-xform":40,"./xform/comment/vml-notes-xform":45,"./xform/core/app-xform":51,"./xform/core/content-types-xform":52,"./xform/core/core-xform":53,"./xform/core/relationships-xform":55,"./xform/drawing/drawing-xform":62,"./xform/sheet/worksheet-xform":115,"./xform/strings/shared-strings-xform":124,"./xform/style/styles-xform":135,"./xform/table/table-xform":143,"./xml/theme1":145,"_process":467,"buffer":220,"fs":216,"jszip":441,"readable-stream":491}],145:[function(require,module,exports){
  15603. "use strict";
  15604. /* eslint-disable */
  15605. module.exports = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"> <a:themeElements> <a:clrScheme name="Office"> <a:dk1> <a:sysClr val="windowText" lastClr="000000"/> </a:dk1> <a:lt1> <a:sysClr val="window" lastClr="FFFFFF"/> </a:lt1> <a:dk2> <a:srgbClr val="1F497D"/> </a:dk2> <a:lt2> <a:srgbClr val="EEECE1"/> </a:lt2> <a:accent1> <a:srgbClr val="4F81BD"/> </a:accent1> <a:accent2> <a:srgbClr val="C0504D"/> </a:accent2> <a:accent3> <a:srgbClr val="9BBB59"/> </a:accent3> <a:accent4> <a:srgbClr val="8064A2"/> </a:accent4> <a:accent5> <a:srgbClr val="4BACC6"/> </a:accent5> <a:accent6> <a:srgbClr val="F79646"/> </a:accent6> <a:hlink> <a:srgbClr val="0000FF"/> </a:hlink> <a:folHlink> <a:srgbClr val="800080"/> </a:folHlink> </a:clrScheme> <a:fontScheme name="Office"> <a:majorFont> <a:latin typeface="Cambria"/> <a:ea typeface=""/> <a:cs typeface=""/> <a:font script="Jpan" typeface="MS Pゴシック"/> <a:font script="Hang" typeface="맑은 고딕"/> <a:font script="Hans" typeface="宋体"/> <a:font script="Hant" typeface="新細明體"/> <a:font script="Arab" typeface="Times New Roman"/> <a:font script="Hebr" typeface="Times New Roman"/> <a:font script="Thai" typeface="Tahoma"/> <a:font script="Ethi" typeface="Nyala"/> <a:font script="Beng" typeface="Vrinda"/> <a:font script="Gujr" typeface="Shruti"/> <a:font script="Khmr" typeface="MoolBoran"/> <a:font script="Knda" typeface="Tunga"/> <a:font script="Guru" typeface="Raavi"/> <a:font script="Cans" typeface="Euphemia"/> <a:font script="Cher" typeface="Plantagenet Cherokee"/> <a:font script="Yiii" typeface="Microsoft Yi Baiti"/> <a:font script="Tibt" typeface="Microsoft Himalaya"/> <a:font script="Thaa" typeface="MV Boli"/> <a:font script="Deva" typeface="Mangal"/> <a:font script="Telu" typeface="Gautami"/> <a:font script="Taml" typeface="Latha"/> <a:font script="Syrc" typeface="Estrangelo Edessa"/> <a:font script="Orya" typeface="Kalinga"/> <a:font script="Mlym" typeface="Kartika"/> <a:font script="Laoo" typeface="DokChampa"/> <a:font script="Sinh" typeface="Iskoola Pota"/> <a:font script="Mong" typeface="Mongolian Baiti"/> <a:font script="Viet" typeface="Times New Roman"/> <a:font script="Uigh" typeface="Microsoft Uighur"/> <a:font script="Geor" typeface="Sylfaen"/> </a:majorFont> <a:minorFont> <a:latin typeface="Calibri"/> <a:ea typeface=""/> <a:cs typeface=""/> <a:font script="Jpan" typeface="MS Pゴシック"/> <a:font script="Hang" typeface="맑은 고딕"/> <a:font script="Hans" typeface="宋体"/> <a:font script="Hant" typeface="新細明體"/> <a:font script="Arab" typeface="Arial"/> <a:font script="Hebr" typeface="Arial"/> <a:font script="Thai" typeface="Tahoma"/> <a:font script="Ethi" typeface="Nyala"/> <a:font script="Beng" typeface="Vrinda"/> <a:font script="Gujr" typeface="Shruti"/> <a:font script="Khmr" typeface="DaunPenh"/> <a:font script="Knda" typeface="Tunga"/> <a:font script="Guru" typeface="Raavi"/> <a:font script="Cans" typeface="Euphemia"/> <a:font script="Cher" typeface="Plantagenet Cherokee"/> <a:font script="Yiii" typeface="Microsoft Yi Baiti"/> <a:font script="Tibt" typeface="Microsoft Himalaya"/> <a:font script="Thaa" typeface="MV Boli"/> <a:font script="Deva" typeface="Mangal"/> <a:font script="Telu" typeface="Gautami"/> <a:font script="Taml" typeface="Latha"/> <a:font script="Syrc" typeface="Estrangelo Edessa"/> <a:font script="Orya" typeface="Kalinga"/> <a:font script="Mlym" typeface="Kartika"/> <a:font script="Laoo" typeface="DokChampa"/> <a:font script="Sinh" typeface="Iskoola Pota"/> <a:font script="Mong" typeface="Mongolian Baiti"/> <a:font script="Viet" typeface="Arial"/> <a:font script="Uigh" typeface="Microsoft Uighur"/> <a:font script="Geor" typeface="Sylfaen"/> </a:minorFont> </a:fontScheme> <a:fmtScheme name="Office"> <a:fillStyleLst> <a:solidFill> <a:schemeClr val="phClr"/> </a:solidFill> <a:gradFill rotWithShape="1"> <a:gsLst> <a:gs pos="0"> <a:schemeClr val="phClr"> <a:tint val="50000"/> <a:satMod val="300000"/> </a:schemeClr> </a:gs> <a:gs pos="35000"> <a:schemeClr val="phClr"> <a:tint val="37000"/> <a:satMod val="300000"/> </a:schemeClr> </a:gs> <a:gs pos="100000"> <a:schemeClr val="phClr"> <a:tint val="15000"/> <a:satMod val="350000"/> </a:schemeClr> </a:gs> </a:gsLst> <a:lin ang="16200000" scaled="1"/> </a:gradFill> <a:gradFill rotWithShape="1"> <a:gsLst> <a:gs pos="0"> <a:schemeClr val="phClr"> <a:tint val="100000"/> <a:shade val="100000"/> <a:satMod val="130000"/> </a:schemeClr> </a:gs> <a:gs pos="100000"> <a:schemeClr val="phClr"> <a:tint val="50000"/> <a:shade val="100000"/> <a:satMod val="350000"/> </a:schemeClr> </a:gs> </a:gsLst> <a:lin ang="16200000" scaled="0"/> </a:gradFill> </a:fillStyleLst> <a:lnStyleLst> <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"> <a:solidFill> <a:schemeClr val="phClr"> <a:shade val="95000"/> <a:satMod val="105000"/> </a:schemeClr> </a:solidFill> <a:prstDash val="solid"/> </a:ln> <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"> <a:solidFill> <a:schemeClr val="phClr"/> </a:solidFill> <a:prstDash val="solid"/> </a:ln> <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"> <a:solidFill> <a:schemeClr val="phClr"/> </a:solidFill> <a:prstDash val="solid"/> </a:ln> </a:lnStyleLst> <a:effectStyleLst> <a:effectStyle> <a:effectLst> <a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"> <a:srgbClr val="000000"> <a:alpha val="38000"/> </a:srgbClr> </a:outerShdw> </a:effectLst> </a:effectStyle> <a:effectStyle> <a:effectLst> <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"> <a:srgbClr val="000000"> <a:alpha val="35000"/> </a:srgbClr> </a:outerShdw> </a:effectLst> </a:effectStyle> <a:effectStyle> <a:effectLst> <a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"> <a:srgbClr val="000000"> <a:alpha val="35000"/> </a:srgbClr> </a:outerShdw> </a:effectLst> <a:scene3d> <a:camera prst="orthographicFront"> <a:rot lat="0" lon="0" rev="0"/> </a:camera> <a:lightRig rig="threePt" dir="t"> <a:rot lat="0" lon="0" rev="1200000"/> </a:lightRig> </a:scene3d> <a:sp3d> <a:bevelT w="63500" h="25400"/> </a:sp3d> </a:effectStyle> </a:effectStyleLst> <a:bgFillStyleLst> <a:solidFill> <a:schemeClr val="phClr"/> </a:solidFill> <a:gradFill rotWithShape="1"> <a:gsLst> <a:gs pos="0"> <a:schemeClr val="phClr"> <a:tint val="40000"/> <a:satMod val="350000"/> </a:schemeClr> </a:gs> <a:gs pos="40000"> <a:schemeClr val="phClr"> <a:tint val="45000"/> <a:shade val="99000"/> <a:satMod val="350000"/> </a:schemeClr> </a:gs> <a:gs pos="100000"> <a:schemeClr val="phClr"> <a:shade val="20000"/> <a:satMod val="255000"/> </a:schemeClr> </a:gs> </a:gsLst> <a:path path="circle"> <a:fillToRect l="50000" t="-80000" r="50000" b="180000"/> </a:path> </a:gradFill> <a:gradFill rotWithShape="1"> <a:gsLst> <a:gs pos="0"> <a:schemeClr val="phClr"> <a:tint val="80000"/> <a:satMod val="300000"/> </a:schemeClr> </a:gs> <a:gs pos="100000"> <a:schemeClr val="phClr"> <a:shade val="30000"/> <a:satMod val="200000"/> </a:schemeClr> </a:gs> </a:gsLst> <a:path path="circle"> <a:fillToRect l="50000" t="50000" r="50000" b="50000"/> </a:path> </a:gradFill> </a:bgFillStyleLst> </a:fmtScheme> </a:themeElements> <a:objectDefaults> <a:spDef> <a:spPr/> <a:bodyPr/> <a:lstStyle/> <a:style> <a:lnRef idx="1"> <a:schemeClr val="accent1"/> </a:lnRef> <a:fillRef idx="3"> <a:schemeClr val="accent1"/> </a:fillRef> <a:effectRef idx="2"> <a:schemeClr val="accent1"/> </a:effectRef> <a:fontRef idx="minor"> <a:schemeClr val="lt1"/> </a:fontRef> </a:style> </a:spDef> <a:lnDef> <a:spPr/> <a:bodyPr/> <a:lstStyle/> <a:style> <a:lnRef idx="2"> <a:schemeClr val="accent1"/> </a:lnRef> <a:fillRef idx="0"> <a:schemeClr val="accent1"/> </a:fillRef> <a:effectRef idx="1"> <a:schemeClr val="accent1"/> </a:effectRef> <a:fontRef idx="minor"> <a:schemeClr val="tx1"/> </a:fontRef> </a:style> </a:lnDef> </a:objectDefaults> <a:extraClrSchemeLst/> </a:theme>';
  15606. },{}],146:[function(require,module,exports){
  15607. (function (Buffer){(function (){
  15608. "use strict";
  15609. Object.defineProperty(exports, "__esModule", {
  15610. value: true
  15611. });
  15612. exports.CsvFormatterStream = void 0;
  15613. const stream_1 = require("stream");
  15614. const formatter_1 = require("./formatter");
  15615. class CsvFormatterStream extends stream_1.Transform {
  15616. constructor(formatterOptions) {
  15617. super({
  15618. writableObjectMode: formatterOptions.objectMode
  15619. });
  15620. this.hasWrittenBOM = false;
  15621. this.formatterOptions = formatterOptions;
  15622. this.rowFormatter = new formatter_1.RowFormatter(formatterOptions);
  15623. // if writeBOM is false then set to true
  15624. // if writeBOM is true then set to false by default so it is written out
  15625. this.hasWrittenBOM = !formatterOptions.writeBOM;
  15626. }
  15627. transform(transformFunction) {
  15628. this.rowFormatter.rowTransform = transformFunction;
  15629. return this;
  15630. }
  15631. _transform(row, encoding, cb) {
  15632. let cbCalled = false;
  15633. try {
  15634. if (!this.hasWrittenBOM) {
  15635. this.push(this.formatterOptions.BOM);
  15636. this.hasWrittenBOM = true;
  15637. }
  15638. this.rowFormatter.format(row, (err, rows) => {
  15639. if (err) {
  15640. cbCalled = true;
  15641. return cb(err);
  15642. }
  15643. if (rows) {
  15644. rows.forEach(r => {
  15645. this.push(Buffer.from(r, 'utf8'));
  15646. });
  15647. }
  15648. cbCalled = true;
  15649. return cb();
  15650. });
  15651. } catch (e) {
  15652. if (cbCalled) {
  15653. throw e;
  15654. }
  15655. cb(e);
  15656. }
  15657. }
  15658. _flush(cb) {
  15659. this.rowFormatter.finish((err, rows) => {
  15660. if (err) {
  15661. return cb(err);
  15662. }
  15663. if (rows) {
  15664. rows.forEach(r => {
  15665. this.push(Buffer.from(r, 'utf8'));
  15666. });
  15667. }
  15668. return cb();
  15669. });
  15670. }
  15671. }
  15672. exports.CsvFormatterStream = CsvFormatterStream;
  15673. }).call(this)}).call(this,require("buffer").Buffer)
  15674. },{"./formatter":150,"buffer":220,"stream":505}],147:[function(require,module,exports){
  15675. "use strict";
  15676. Object.defineProperty(exports, "__esModule", {
  15677. value: true
  15678. });
  15679. exports.FormatterOptions = void 0;
  15680. class FormatterOptions {
  15681. constructor() {
  15682. let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15683. var _a;
  15684. this.objectMode = true;
  15685. this.delimiter = ',';
  15686. this.rowDelimiter = '\n';
  15687. this.quote = '"';
  15688. this.escape = this.quote;
  15689. this.quoteColumns = false;
  15690. this.quoteHeaders = this.quoteColumns;
  15691. this.headers = null;
  15692. this.includeEndRowDelimiter = false;
  15693. this.writeBOM = false;
  15694. this.BOM = '\ufeff';
  15695. this.alwaysWriteHeaders = false;
  15696. Object.assign(this, opts || {});
  15697. if (typeof (opts === null || opts === void 0 ? void 0 : opts.quoteHeaders) === 'undefined') {
  15698. this.quoteHeaders = this.quoteColumns;
  15699. }
  15700. if ((opts === null || opts === void 0 ? void 0 : opts.quote) === true) {
  15701. this.quote = '"';
  15702. } else if ((opts === null || opts === void 0 ? void 0 : opts.quote) === false) {
  15703. this.quote = '';
  15704. }
  15705. if (typeof (opts === null || opts === void 0 ? void 0 : opts.escape) !== 'string') {
  15706. this.escape = this.quote;
  15707. }
  15708. this.shouldWriteHeaders = !!this.headers && ((_a = opts.writeHeaders) !== null && _a !== void 0 ? _a : true);
  15709. this.headers = Array.isArray(this.headers) ? this.headers : null;
  15710. this.escapedQuote = `${this.escape}${this.quote}`;
  15711. }
  15712. }
  15713. exports.FormatterOptions = FormatterOptions;
  15714. },{}],148:[function(require,module,exports){
  15715. "use strict";
  15716. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  15717. return mod && mod.__esModule ? mod : {
  15718. "default": mod
  15719. };
  15720. };
  15721. Object.defineProperty(exports, "__esModule", {
  15722. value: true
  15723. });
  15724. exports.FieldFormatter = void 0;
  15725. const lodash_isboolean_1 = __importDefault(require("lodash.isboolean"));
  15726. const lodash_isnil_1 = __importDefault(require("lodash.isnil"));
  15727. const lodash_escaperegexp_1 = __importDefault(require("lodash.escaperegexp"));
  15728. class FieldFormatter {
  15729. constructor(formatterOptions) {
  15730. this._headers = null;
  15731. this.formatterOptions = formatterOptions;
  15732. if (formatterOptions.headers !== null) {
  15733. this.headers = formatterOptions.headers;
  15734. }
  15735. this.REPLACE_REGEXP = new RegExp(formatterOptions.quote, 'g');
  15736. const escapePattern = `[${formatterOptions.delimiter}${lodash_escaperegexp_1.default(formatterOptions.rowDelimiter)}|\r|\n]`;
  15737. this.ESCAPE_REGEXP = new RegExp(escapePattern);
  15738. }
  15739. set headers(headers) {
  15740. this._headers = headers;
  15741. }
  15742. shouldQuote(fieldIndex, isHeader) {
  15743. const quoteConfig = isHeader ? this.formatterOptions.quoteHeaders : this.formatterOptions.quoteColumns;
  15744. if (lodash_isboolean_1.default(quoteConfig)) {
  15745. return quoteConfig;
  15746. }
  15747. if (Array.isArray(quoteConfig)) {
  15748. return quoteConfig[fieldIndex];
  15749. }
  15750. if (this._headers !== null) {
  15751. return quoteConfig[this._headers[fieldIndex]];
  15752. }
  15753. return false;
  15754. }
  15755. format(field, fieldIndex, isHeader) {
  15756. const preparedField = `${lodash_isnil_1.default(field) ? '' : field}`.replace(/\0/g, '');
  15757. const {
  15758. formatterOptions
  15759. } = this;
  15760. if (formatterOptions.quote !== '') {
  15761. const shouldEscape = preparedField.indexOf(formatterOptions.quote) !== -1;
  15762. if (shouldEscape) {
  15763. return this.quoteField(preparedField.replace(this.REPLACE_REGEXP, formatterOptions.escapedQuote));
  15764. }
  15765. }
  15766. const hasEscapeCharacters = preparedField.search(this.ESCAPE_REGEXP) !== -1;
  15767. if (hasEscapeCharacters || this.shouldQuote(fieldIndex, isHeader)) {
  15768. return this.quoteField(preparedField);
  15769. }
  15770. return preparedField;
  15771. }
  15772. quoteField(field) {
  15773. const {
  15774. quote
  15775. } = this.formatterOptions;
  15776. return `${quote}${field}${quote}`;
  15777. }
  15778. }
  15779. exports.FieldFormatter = FieldFormatter;
  15780. },{"lodash.escaperegexp":442,"lodash.isboolean":444,"lodash.isnil":447}],149:[function(require,module,exports){
  15781. "use strict";
  15782. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  15783. return mod && mod.__esModule ? mod : {
  15784. "default": mod
  15785. };
  15786. };
  15787. Object.defineProperty(exports, "__esModule", {
  15788. value: true
  15789. });
  15790. exports.RowFormatter = void 0;
  15791. const lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  15792. const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
  15793. const FieldFormatter_1 = require("./FieldFormatter");
  15794. const types_1 = require("../types");
  15795. class RowFormatter {
  15796. constructor(formatterOptions) {
  15797. this.rowCount = 0;
  15798. this.formatterOptions = formatterOptions;
  15799. this.fieldFormatter = new FieldFormatter_1.FieldFormatter(formatterOptions);
  15800. this.headers = formatterOptions.headers;
  15801. this.shouldWriteHeaders = formatterOptions.shouldWriteHeaders;
  15802. this.hasWrittenHeaders = false;
  15803. if (this.headers !== null) {
  15804. this.fieldFormatter.headers = this.headers;
  15805. }
  15806. if (formatterOptions.transform) {
  15807. this.rowTransform = formatterOptions.transform;
  15808. }
  15809. }
  15810. static isRowHashArray(row) {
  15811. if (Array.isArray(row)) {
  15812. return Array.isArray(row[0]) && row[0].length === 2;
  15813. }
  15814. return false;
  15815. }
  15816. static isRowArray(row) {
  15817. return Array.isArray(row) && !this.isRowHashArray(row);
  15818. }
  15819. // get headers from a row item
  15820. static gatherHeaders(row) {
  15821. if (RowFormatter.isRowHashArray(row)) {
  15822. // lets assume a multi-dimesional array with item 0 being the header
  15823. return row.map(it => it[0]);
  15824. }
  15825. if (Array.isArray(row)) {
  15826. return row;
  15827. }
  15828. return Object.keys(row);
  15829. }
  15830. // eslint-disable-next-line @typescript-eslint/no-shadow
  15831. static createTransform(transformFunction) {
  15832. if (types_1.isSyncTransform(transformFunction)) {
  15833. return (row, cb) => {
  15834. let transformedRow = null;
  15835. try {
  15836. transformedRow = transformFunction(row);
  15837. } catch (e) {
  15838. return cb(e);
  15839. }
  15840. return cb(null, transformedRow);
  15841. };
  15842. }
  15843. return (row, cb) => {
  15844. transformFunction(row, cb);
  15845. };
  15846. }
  15847. set rowTransform(transformFunction) {
  15848. if (!lodash_isfunction_1.default(transformFunction)) {
  15849. throw new TypeError('The transform should be a function');
  15850. }
  15851. this._rowTransform = RowFormatter.createTransform(transformFunction);
  15852. }
  15853. format(row, cb) {
  15854. this.callTransformer(row, (err, transformedRow) => {
  15855. if (err) {
  15856. return cb(err);
  15857. }
  15858. if (!row) {
  15859. return cb(null);
  15860. }
  15861. const rows = [];
  15862. if (transformedRow) {
  15863. const {
  15864. shouldFormatColumns,
  15865. headers
  15866. } = this.checkHeaders(transformedRow);
  15867. if (this.shouldWriteHeaders && headers && !this.hasWrittenHeaders) {
  15868. rows.push(this.formatColumns(headers, true));
  15869. this.hasWrittenHeaders = true;
  15870. }
  15871. if (shouldFormatColumns) {
  15872. const columns = this.gatherColumns(transformedRow);
  15873. rows.push(this.formatColumns(columns, false));
  15874. }
  15875. }
  15876. return cb(null, rows);
  15877. });
  15878. }
  15879. finish(cb) {
  15880. const rows = [];
  15881. // check if we should write headers and we didnt get any rows
  15882. if (this.formatterOptions.alwaysWriteHeaders && this.rowCount === 0) {
  15883. if (!this.headers) {
  15884. return cb(new Error('`alwaysWriteHeaders` option is set to true but `headers` option not provided.'));
  15885. }
  15886. rows.push(this.formatColumns(this.headers, true));
  15887. }
  15888. if (this.formatterOptions.includeEndRowDelimiter) {
  15889. rows.push(this.formatterOptions.rowDelimiter);
  15890. }
  15891. return cb(null, rows);
  15892. }
  15893. // check if we need to write header return true if we should also write a row
  15894. // could be false if headers is true and the header row(first item) is passed in
  15895. checkHeaders(row) {
  15896. if (this.headers) {
  15897. // either the headers were provided by the user or we have already gathered them.
  15898. return {
  15899. shouldFormatColumns: true,
  15900. headers: this.headers
  15901. };
  15902. }
  15903. const headers = RowFormatter.gatherHeaders(row);
  15904. this.headers = headers;
  15905. this.fieldFormatter.headers = headers;
  15906. if (!this.shouldWriteHeaders) {
  15907. // if we are not supposed to write the headers then
  15908. // always format the columns
  15909. return {
  15910. shouldFormatColumns: true,
  15911. headers: null
  15912. };
  15913. }
  15914. // if the row is equal to headers dont format
  15915. return {
  15916. shouldFormatColumns: !lodash_isequal_1.default(headers, row),
  15917. headers
  15918. };
  15919. }
  15920. // todo change this method to unknown[]
  15921. gatherColumns(row) {
  15922. if (this.headers === null) {
  15923. throw new Error('Headers is currently null');
  15924. }
  15925. if (!Array.isArray(row)) {
  15926. return this.headers.map(header => row[header]);
  15927. }
  15928. if (RowFormatter.isRowHashArray(row)) {
  15929. return this.headers.map((header, i) => {
  15930. const col = row[i];
  15931. if (col) {
  15932. return col[1];
  15933. }
  15934. return '';
  15935. });
  15936. }
  15937. // if its a one dimensional array and headers were not provided
  15938. // then just return the row
  15939. if (RowFormatter.isRowArray(row) && !this.shouldWriteHeaders) {
  15940. return row;
  15941. }
  15942. return this.headers.map((header, i) => row[i]);
  15943. }
  15944. callTransformer(row, cb) {
  15945. if (!this._rowTransform) {
  15946. return cb(null, row);
  15947. }
  15948. return this._rowTransform(row, cb);
  15949. }
  15950. formatColumns(columns, isHeadersRow) {
  15951. const formattedCols = columns.map((field, i) => this.fieldFormatter.format(field, i, isHeadersRow)).join(this.formatterOptions.delimiter);
  15952. const {
  15953. rowCount
  15954. } = this;
  15955. this.rowCount += 1;
  15956. if (rowCount) {
  15957. return [this.formatterOptions.rowDelimiter, formattedCols].join('');
  15958. }
  15959. return formattedCols;
  15960. }
  15961. }
  15962. exports.RowFormatter = RowFormatter;
  15963. },{"../types":152,"./FieldFormatter":148,"lodash.isequal":445,"lodash.isfunction":446}],150:[function(require,module,exports){
  15964. "use strict";
  15965. Object.defineProperty(exports, "__esModule", {
  15966. value: true
  15967. });
  15968. exports.FieldFormatter = exports.RowFormatter = void 0;
  15969. var RowFormatter_1 = require("./RowFormatter");
  15970. Object.defineProperty(exports, "RowFormatter", {
  15971. enumerable: true,
  15972. get: function () {
  15973. return RowFormatter_1.RowFormatter;
  15974. }
  15975. });
  15976. var FieldFormatter_1 = require("./FieldFormatter");
  15977. Object.defineProperty(exports, "FieldFormatter", {
  15978. enumerable: true,
  15979. get: function () {
  15980. return FieldFormatter_1.FieldFormatter;
  15981. }
  15982. });
  15983. },{"./FieldFormatter":148,"./RowFormatter":149}],151:[function(require,module,exports){
  15984. (function (Buffer){(function (){
  15985. "use strict";
  15986. var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  15987. if (k2 === undefined) k2 = k;
  15988. Object.defineProperty(o, k2, {
  15989. enumerable: true,
  15990. get: function () {
  15991. return m[k];
  15992. }
  15993. });
  15994. } : function (o, m, k, k2) {
  15995. if (k2 === undefined) k2 = k;
  15996. o[k2] = m[k];
  15997. });
  15998. var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  15999. Object.defineProperty(o, "default", {
  16000. enumerable: true,
  16001. value: v
  16002. });
  16003. } : function (o, v) {
  16004. o["default"] = v;
  16005. });
  16006. var __importStar = void 0 && (void 0).__importStar || function (mod) {
  16007. if (mod && mod.__esModule) return mod;
  16008. var result = {};
  16009. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  16010. __setModuleDefault(result, mod);
  16011. return result;
  16012. };
  16013. var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
  16014. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  16015. };
  16016. Object.defineProperty(exports, "__esModule", {
  16017. value: true
  16018. });
  16019. exports.writeToPath = exports.writeToString = exports.writeToBuffer = exports.writeToStream = exports.write = exports.format = exports.FormatterOptions = exports.CsvFormatterStream = void 0;
  16020. const util_1 = require("util");
  16021. const stream_1 = require("stream");
  16022. const fs = __importStar(require("fs"));
  16023. const FormatterOptions_1 = require("./FormatterOptions");
  16024. const CsvFormatterStream_1 = require("./CsvFormatterStream");
  16025. __exportStar(require("./types"), exports);
  16026. var CsvFormatterStream_2 = require("./CsvFormatterStream");
  16027. Object.defineProperty(exports, "CsvFormatterStream", {
  16028. enumerable: true,
  16029. get: function () {
  16030. return CsvFormatterStream_2.CsvFormatterStream;
  16031. }
  16032. });
  16033. var FormatterOptions_2 = require("./FormatterOptions");
  16034. Object.defineProperty(exports, "FormatterOptions", {
  16035. enumerable: true,
  16036. get: function () {
  16037. return FormatterOptions_2.FormatterOptions;
  16038. }
  16039. });
  16040. exports.format = options => new CsvFormatterStream_1.CsvFormatterStream(new FormatterOptions_1.FormatterOptions(options));
  16041. exports.write = (rows, options) => {
  16042. const csvStream = exports.format(options);
  16043. const promiseWrite = util_1.promisify((row, cb) => {
  16044. csvStream.write(row, undefined, cb);
  16045. });
  16046. rows.reduce((prev, row) => prev.then(() => promiseWrite(row)), Promise.resolve()).then(() => csvStream.end()).catch(err => {
  16047. csvStream.emit('error', err);
  16048. });
  16049. return csvStream;
  16050. };
  16051. exports.writeToStream = (ws, rows, options) => exports.write(rows, options).pipe(ws);
  16052. exports.writeToBuffer = function (rows) {
  16053. let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16054. const buffers = [];
  16055. const ws = new stream_1.Writable({
  16056. write(data, enc, writeCb) {
  16057. buffers.push(data);
  16058. writeCb();
  16059. }
  16060. });
  16061. return new Promise((res, rej) => {
  16062. ws.on('error', rej).on('finish', () => res(Buffer.concat(buffers)));
  16063. exports.write(rows, opts).pipe(ws);
  16064. });
  16065. };
  16066. exports.writeToString = (rows, options) => exports.writeToBuffer(rows, options).then(buffer => buffer.toString());
  16067. exports.writeToPath = (path, rows, options) => {
  16068. const stream = fs.createWriteStream(path, {
  16069. encoding: 'utf8'
  16070. });
  16071. return exports.write(rows, options).pipe(stream);
  16072. };
  16073. }).call(this)}).call(this,require("buffer").Buffer)
  16074. },{"./CsvFormatterStream":146,"./FormatterOptions":147,"./types":152,"buffer":220,"fs":216,"stream":505,"util":527}],152:[function(require,module,exports){
  16075. "use strict";
  16076. /* eslint-disable @typescript-eslint/no-explicit-any */
  16077. Object.defineProperty(exports, "__esModule", {
  16078. value: true
  16079. });
  16080. exports.isSyncTransform = void 0;
  16081. exports.isSyncTransform = transform => transform.length === 1;
  16082. },{}],153:[function(require,module,exports){
  16083. (function (setImmediate){(function (){
  16084. "use strict";
  16085. Object.defineProperty(exports, "__esModule", {
  16086. value: true
  16087. });
  16088. exports.CsvParserStream = void 0;
  16089. const string_decoder_1 = require("string_decoder");
  16090. const stream_1 = require("stream");
  16091. const transforms_1 = require("./transforms");
  16092. const parser_1 = require("./parser");
  16093. class CsvParserStream extends stream_1.Transform {
  16094. constructor(parserOptions) {
  16095. super({
  16096. objectMode: parserOptions.objectMode
  16097. });
  16098. this.lines = '';
  16099. this.rowCount = 0;
  16100. this.parsedRowCount = 0;
  16101. this.parsedLineCount = 0;
  16102. this.endEmitted = false;
  16103. this.headersEmitted = false;
  16104. this.parserOptions = parserOptions;
  16105. this.parser = new parser_1.Parser(parserOptions);
  16106. this.headerTransformer = new transforms_1.HeaderTransformer(parserOptions);
  16107. this.decoder = new string_decoder_1.StringDecoder(parserOptions.encoding);
  16108. this.rowTransformerValidator = new transforms_1.RowTransformerValidator();
  16109. }
  16110. get hasHitRowLimit() {
  16111. return this.parserOptions.limitRows && this.rowCount >= this.parserOptions.maxRows;
  16112. }
  16113. get shouldEmitRows() {
  16114. return this.parsedRowCount > this.parserOptions.skipRows;
  16115. }
  16116. get shouldSkipLine() {
  16117. return this.parsedLineCount <= this.parserOptions.skipLines;
  16118. }
  16119. transform(transformFunction) {
  16120. this.rowTransformerValidator.rowTransform = transformFunction;
  16121. return this;
  16122. }
  16123. validate(validateFunction) {
  16124. this.rowTransformerValidator.rowValidator = validateFunction;
  16125. return this;
  16126. }
  16127. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  16128. emit(event) {
  16129. if (event === 'end') {
  16130. if (!this.endEmitted) {
  16131. this.endEmitted = true;
  16132. super.emit('end', this.rowCount);
  16133. }
  16134. return false;
  16135. }
  16136. for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  16137. rest[_key - 1] = arguments[_key];
  16138. }
  16139. return super.emit(event, ...rest);
  16140. }
  16141. _transform(data, encoding, done) {
  16142. // if we have hit our maxRows parsing limit then skip parsing
  16143. if (this.hasHitRowLimit) {
  16144. return done();
  16145. }
  16146. const wrappedCallback = CsvParserStream.wrapDoneCallback(done);
  16147. try {
  16148. const {
  16149. lines
  16150. } = this;
  16151. const newLine = lines + this.decoder.write(data);
  16152. const rows = this.parse(newLine, true);
  16153. return this.processRows(rows, wrappedCallback);
  16154. } catch (e) {
  16155. return wrappedCallback(e);
  16156. }
  16157. }
  16158. _flush(done) {
  16159. const wrappedCallback = CsvParserStream.wrapDoneCallback(done);
  16160. // if we have hit our maxRows parsing limit then skip parsing
  16161. if (this.hasHitRowLimit) {
  16162. return wrappedCallback();
  16163. }
  16164. try {
  16165. const newLine = this.lines + this.decoder.end();
  16166. const rows = this.parse(newLine, false);
  16167. return this.processRows(rows, wrappedCallback);
  16168. } catch (e) {
  16169. return wrappedCallback(e);
  16170. }
  16171. }
  16172. parse(data, hasMoreData) {
  16173. if (!data) {
  16174. return [];
  16175. }
  16176. const {
  16177. line,
  16178. rows
  16179. } = this.parser.parse(data, hasMoreData);
  16180. this.lines = line;
  16181. return rows;
  16182. }
  16183. processRows(rows, cb) {
  16184. const rowsLength = rows.length;
  16185. const iterate = i => {
  16186. const callNext = err => {
  16187. if (err) {
  16188. return cb(err);
  16189. }
  16190. if (i % 100 === 0) {
  16191. // incase the transform are sync insert a next tick to prevent stack overflow
  16192. setImmediate(() => iterate(i + 1));
  16193. return undefined;
  16194. }
  16195. return iterate(i + 1);
  16196. };
  16197. this.checkAndEmitHeaders();
  16198. // if we have emitted all rows or we have hit the maxRows limit option
  16199. // then end
  16200. if (i >= rowsLength || this.hasHitRowLimit) {
  16201. return cb();
  16202. }
  16203. this.parsedLineCount += 1;
  16204. if (this.shouldSkipLine) {
  16205. return callNext();
  16206. }
  16207. const row = rows[i];
  16208. this.rowCount += 1;
  16209. this.parsedRowCount += 1;
  16210. const nextRowCount = this.rowCount;
  16211. return this.transformRow(row, (err, transformResult) => {
  16212. if (err) {
  16213. this.rowCount -= 1;
  16214. return callNext(err);
  16215. }
  16216. if (!transformResult) {
  16217. return callNext(new Error('expected transform result'));
  16218. }
  16219. if (!transformResult.isValid) {
  16220. this.emit('data-invalid', transformResult.row, nextRowCount, transformResult.reason);
  16221. } else if (transformResult.row) {
  16222. return this.pushRow(transformResult.row, callNext);
  16223. }
  16224. return callNext();
  16225. });
  16226. };
  16227. iterate(0);
  16228. }
  16229. transformRow(parsedRow, cb) {
  16230. try {
  16231. this.headerTransformer.transform(parsedRow, (err, withHeaders) => {
  16232. if (err) {
  16233. return cb(err);
  16234. }
  16235. if (!withHeaders) {
  16236. return cb(new Error('Expected result from header transform'));
  16237. }
  16238. if (!withHeaders.isValid) {
  16239. if (this.shouldEmitRows) {
  16240. return cb(null, {
  16241. isValid: false,
  16242. row: parsedRow
  16243. });
  16244. }
  16245. // skipped because of skipRows option remove from total row count
  16246. return this.skipRow(cb);
  16247. }
  16248. if (withHeaders.row) {
  16249. if (this.shouldEmitRows) {
  16250. return this.rowTransformerValidator.transformAndValidate(withHeaders.row, cb);
  16251. }
  16252. // skipped because of skipRows option remove from total row count
  16253. return this.skipRow(cb);
  16254. }
  16255. // this is a header row dont include in the rowCount or parsedRowCount
  16256. this.rowCount -= 1;
  16257. this.parsedRowCount -= 1;
  16258. return cb(null, {
  16259. row: null,
  16260. isValid: true
  16261. });
  16262. });
  16263. } catch (e) {
  16264. cb(e);
  16265. }
  16266. }
  16267. checkAndEmitHeaders() {
  16268. if (!this.headersEmitted && this.headerTransformer.headers) {
  16269. this.headersEmitted = true;
  16270. this.emit('headers', this.headerTransformer.headers);
  16271. }
  16272. }
  16273. skipRow(cb) {
  16274. // skipped because of skipRows option remove from total row count
  16275. this.rowCount -= 1;
  16276. return cb(null, {
  16277. row: null,
  16278. isValid: true
  16279. });
  16280. }
  16281. pushRow(row, cb) {
  16282. try {
  16283. if (!this.parserOptions.objectMode) {
  16284. this.push(JSON.stringify(row));
  16285. } else {
  16286. this.push(row);
  16287. }
  16288. cb();
  16289. } catch (e) {
  16290. cb(e);
  16291. }
  16292. }
  16293. static wrapDoneCallback(done) {
  16294. let errorCalled = false;
  16295. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  16296. return function (err) {
  16297. if (err) {
  16298. if (errorCalled) {
  16299. throw err;
  16300. }
  16301. errorCalled = true;
  16302. done(err);
  16303. return;
  16304. }
  16305. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  16306. args[_key2 - 1] = arguments[_key2];
  16307. }
  16308. done(...args);
  16309. };
  16310. }
  16311. }
  16312. exports.CsvParserStream = CsvParserStream;
  16313. }).call(this)}).call(this,require("timers").setImmediate)
  16314. },{"./parser":165,"./transforms":168,"stream":505,"string_decoder":218,"timers":523}],154:[function(require,module,exports){
  16315. "use strict";
  16316. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  16317. return mod && mod.__esModule ? mod : {
  16318. "default": mod
  16319. };
  16320. };
  16321. Object.defineProperty(exports, "__esModule", {
  16322. value: true
  16323. });
  16324. exports.ParserOptions = void 0;
  16325. const lodash_escaperegexp_1 = __importDefault(require("lodash.escaperegexp"));
  16326. const lodash_isnil_1 = __importDefault(require("lodash.isnil"));
  16327. class ParserOptions {
  16328. constructor(opts) {
  16329. var _a;
  16330. this.objectMode = true;
  16331. this.delimiter = ',';
  16332. this.ignoreEmpty = false;
  16333. this.quote = '"';
  16334. this.escape = null;
  16335. this.escapeChar = this.quote;
  16336. this.comment = null;
  16337. this.supportsComments = false;
  16338. this.ltrim = false;
  16339. this.rtrim = false;
  16340. this.trim = false;
  16341. this.headers = null;
  16342. this.renameHeaders = false;
  16343. this.strictColumnHandling = false;
  16344. this.discardUnmappedColumns = false;
  16345. this.carriageReturn = '\r';
  16346. this.encoding = 'utf8';
  16347. this.limitRows = false;
  16348. this.maxRows = 0;
  16349. this.skipLines = 0;
  16350. this.skipRows = 0;
  16351. Object.assign(this, opts || {});
  16352. if (this.delimiter.length > 1) {
  16353. throw new Error('delimiter option must be one character long');
  16354. }
  16355. this.escapedDelimiter = lodash_escaperegexp_1.default(this.delimiter);
  16356. this.escapeChar = (_a = this.escape) !== null && _a !== void 0 ? _a : this.quote;
  16357. this.supportsComments = !lodash_isnil_1.default(this.comment);
  16358. this.NEXT_TOKEN_REGEXP = new RegExp(`([^\\s]|\\r\\n|\\n|\\r|${this.escapedDelimiter})`);
  16359. if (this.maxRows > 0) {
  16360. this.limitRows = true;
  16361. }
  16362. }
  16363. }
  16364. exports.ParserOptions = ParserOptions;
  16365. },{"lodash.escaperegexp":442,"lodash.isnil":447}],155:[function(require,module,exports){
  16366. "use strict";
  16367. var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
  16368. if (k2 === undefined) k2 = k;
  16369. Object.defineProperty(o, k2, {
  16370. enumerable: true,
  16371. get: function () {
  16372. return m[k];
  16373. }
  16374. });
  16375. } : function (o, m, k, k2) {
  16376. if (k2 === undefined) k2 = k;
  16377. o[k2] = m[k];
  16378. });
  16379. var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
  16380. Object.defineProperty(o, "default", {
  16381. enumerable: true,
  16382. value: v
  16383. });
  16384. } : function (o, v) {
  16385. o["default"] = v;
  16386. });
  16387. var __importStar = void 0 && (void 0).__importStar || function (mod) {
  16388. if (mod && mod.__esModule) return mod;
  16389. var result = {};
  16390. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  16391. __setModuleDefault(result, mod);
  16392. return result;
  16393. };
  16394. var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
  16395. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  16396. };
  16397. Object.defineProperty(exports, "__esModule", {
  16398. value: true
  16399. });
  16400. exports.parseString = exports.parseFile = exports.parseStream = exports.parse = exports.ParserOptions = exports.CsvParserStream = void 0;
  16401. const fs = __importStar(require("fs"));
  16402. const stream_1 = require("stream");
  16403. const ParserOptions_1 = require("./ParserOptions");
  16404. const CsvParserStream_1 = require("./CsvParserStream");
  16405. __exportStar(require("./types"), exports);
  16406. var CsvParserStream_2 = require("./CsvParserStream");
  16407. Object.defineProperty(exports, "CsvParserStream", {
  16408. enumerable: true,
  16409. get: function () {
  16410. return CsvParserStream_2.CsvParserStream;
  16411. }
  16412. });
  16413. var ParserOptions_2 = require("./ParserOptions");
  16414. Object.defineProperty(exports, "ParserOptions", {
  16415. enumerable: true,
  16416. get: function () {
  16417. return ParserOptions_2.ParserOptions;
  16418. }
  16419. });
  16420. exports.parse = args => new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(args));
  16421. exports.parseStream = (stream, options) => stream.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  16422. exports.parseFile = function (location) {
  16423. let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16424. return fs.createReadStream(location).pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  16425. };
  16426. exports.parseString = (string, options) => {
  16427. const rs = new stream_1.Readable();
  16428. rs.push(string);
  16429. rs.push(null);
  16430. return rs.pipe(new CsvParserStream_1.CsvParserStream(new ParserOptions_1.ParserOptions(options)));
  16431. };
  16432. },{"./CsvParserStream":153,"./ParserOptions":154,"./types":169,"fs":216,"stream":505}],156:[function(require,module,exports){
  16433. "use strict";
  16434. Object.defineProperty(exports, "__esModule", {
  16435. value: true
  16436. });
  16437. exports.Parser = void 0;
  16438. const Scanner_1 = require("./Scanner");
  16439. const RowParser_1 = require("./RowParser");
  16440. const Token_1 = require("./Token");
  16441. class Parser {
  16442. constructor(parserOptions) {
  16443. this.parserOptions = parserOptions;
  16444. this.rowParser = new RowParser_1.RowParser(this.parserOptions);
  16445. }
  16446. static removeBOM(line) {
  16447. // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
  16448. // conversion translates it to FEFF (UTF-16 BOM)
  16449. if (line && line.charCodeAt(0) === 0xfeff) {
  16450. return line.slice(1);
  16451. }
  16452. return line;
  16453. }
  16454. parse(line, hasMoreData) {
  16455. const scanner = new Scanner_1.Scanner({
  16456. line: Parser.removeBOM(line),
  16457. parserOptions: this.parserOptions,
  16458. hasMoreData
  16459. });
  16460. if (this.parserOptions.supportsComments) {
  16461. return this.parseWithComments(scanner);
  16462. }
  16463. return this.parseWithoutComments(scanner);
  16464. }
  16465. parseWithoutComments(scanner) {
  16466. const rows = [];
  16467. let shouldContinue = true;
  16468. while (shouldContinue) {
  16469. shouldContinue = this.parseRow(scanner, rows);
  16470. }
  16471. return {
  16472. line: scanner.line,
  16473. rows
  16474. };
  16475. }
  16476. parseWithComments(scanner) {
  16477. const {
  16478. parserOptions
  16479. } = this;
  16480. const rows = [];
  16481. for (let nextToken = scanner.nextCharacterToken; nextToken !== null; nextToken = scanner.nextCharacterToken) {
  16482. if (Token_1.Token.isTokenComment(nextToken, parserOptions)) {
  16483. const cursor = scanner.advancePastLine();
  16484. if (cursor === null) {
  16485. return {
  16486. line: scanner.lineFromCursor,
  16487. rows
  16488. };
  16489. }
  16490. if (!scanner.hasMoreCharacters) {
  16491. return {
  16492. line: scanner.lineFromCursor,
  16493. rows
  16494. };
  16495. }
  16496. scanner.truncateToCursor();
  16497. } else if (!this.parseRow(scanner, rows)) {
  16498. break;
  16499. }
  16500. }
  16501. return {
  16502. line: scanner.line,
  16503. rows
  16504. };
  16505. }
  16506. parseRow(scanner, rows) {
  16507. const nextToken = scanner.nextNonSpaceToken;
  16508. if (!nextToken) {
  16509. return false;
  16510. }
  16511. const row = this.rowParser.parse(scanner);
  16512. if (row === null) {
  16513. return false;
  16514. }
  16515. if (this.parserOptions.ignoreEmpty && RowParser_1.RowParser.isEmptyRow(row)) {
  16516. return true;
  16517. }
  16518. rows.push(row);
  16519. return true;
  16520. }
  16521. }
  16522. exports.Parser = Parser;
  16523. },{"./RowParser":157,"./Scanner":158,"./Token":159}],157:[function(require,module,exports){
  16524. "use strict";
  16525. Object.defineProperty(exports, "__esModule", {
  16526. value: true
  16527. });
  16528. exports.RowParser = void 0;
  16529. const column_1 = require("./column");
  16530. const Token_1 = require("./Token");
  16531. const EMPTY_STRING = '';
  16532. class RowParser {
  16533. constructor(parserOptions) {
  16534. this.parserOptions = parserOptions;
  16535. this.columnParser = new column_1.ColumnParser(parserOptions);
  16536. }
  16537. static isEmptyRow(row) {
  16538. return row.join(EMPTY_STRING).replace(/\s+/g, EMPTY_STRING) === EMPTY_STRING;
  16539. }
  16540. parse(scanner) {
  16541. const {
  16542. parserOptions
  16543. } = this;
  16544. const {
  16545. hasMoreData
  16546. } = scanner;
  16547. const currentScanner = scanner;
  16548. const columns = [];
  16549. let currentToken = this.getStartToken(currentScanner, columns);
  16550. while (currentToken) {
  16551. if (Token_1.Token.isTokenRowDelimiter(currentToken)) {
  16552. currentScanner.advancePastToken(currentToken);
  16553. // if ends with CR and there is more data, keep unparsed due to possible
  16554. // coming LF in CRLF
  16555. if (!currentScanner.hasMoreCharacters && Token_1.Token.isTokenCarriageReturn(currentToken, parserOptions) && hasMoreData) {
  16556. return null;
  16557. }
  16558. currentScanner.truncateToCursor();
  16559. return columns;
  16560. }
  16561. if (!this.shouldSkipColumnParse(currentScanner, currentToken, columns)) {
  16562. const item = this.columnParser.parse(currentScanner);
  16563. if (item === null) {
  16564. return null;
  16565. }
  16566. columns.push(item);
  16567. }
  16568. currentToken = currentScanner.nextNonSpaceToken;
  16569. }
  16570. if (!hasMoreData) {
  16571. currentScanner.truncateToCursor();
  16572. return columns;
  16573. }
  16574. return null;
  16575. }
  16576. getStartToken(scanner, columns) {
  16577. const currentToken = scanner.nextNonSpaceToken;
  16578. if (currentToken !== null && Token_1.Token.isTokenDelimiter(currentToken, this.parserOptions)) {
  16579. columns.push('');
  16580. return scanner.nextNonSpaceToken;
  16581. }
  16582. return currentToken;
  16583. }
  16584. shouldSkipColumnParse(scanner, currentToken, columns) {
  16585. const {
  16586. parserOptions
  16587. } = this;
  16588. if (Token_1.Token.isTokenDelimiter(currentToken, parserOptions)) {
  16589. scanner.advancePastToken(currentToken);
  16590. // if the delimiter is at the end of a line
  16591. const nextToken = scanner.nextCharacterToken;
  16592. if (!scanner.hasMoreCharacters || nextToken !== null && Token_1.Token.isTokenRowDelimiter(nextToken)) {
  16593. columns.push('');
  16594. return true;
  16595. }
  16596. if (nextToken !== null && Token_1.Token.isTokenDelimiter(nextToken, parserOptions)) {
  16597. columns.push('');
  16598. return true;
  16599. }
  16600. }
  16601. return false;
  16602. }
  16603. }
  16604. exports.RowParser = RowParser;
  16605. },{"./Token":159,"./column":164}],158:[function(require,module,exports){
  16606. "use strict";
  16607. Object.defineProperty(exports, "__esModule", {
  16608. value: true
  16609. });
  16610. exports.Scanner = void 0;
  16611. const Token_1 = require("./Token");
  16612. const ROW_DELIMITER = /((?:\r\n)|\n|\r)/;
  16613. class Scanner {
  16614. constructor(args) {
  16615. this.cursor = 0;
  16616. this.line = args.line;
  16617. this.lineLength = this.line.length;
  16618. this.parserOptions = args.parserOptions;
  16619. this.hasMoreData = args.hasMoreData;
  16620. this.cursor = args.cursor || 0;
  16621. }
  16622. get hasMoreCharacters() {
  16623. return this.lineLength > this.cursor;
  16624. }
  16625. get nextNonSpaceToken() {
  16626. const {
  16627. lineFromCursor
  16628. } = this;
  16629. const regex = this.parserOptions.NEXT_TOKEN_REGEXP;
  16630. if (lineFromCursor.search(regex) === -1) {
  16631. return null;
  16632. }
  16633. const match = regex.exec(lineFromCursor);
  16634. if (match == null) {
  16635. return null;
  16636. }
  16637. const token = match[1];
  16638. const startCursor = this.cursor + (match.index || 0);
  16639. return new Token_1.Token({
  16640. token,
  16641. startCursor,
  16642. endCursor: startCursor + token.length - 1
  16643. });
  16644. }
  16645. get nextCharacterToken() {
  16646. const {
  16647. cursor,
  16648. lineLength
  16649. } = this;
  16650. if (lineLength <= cursor) {
  16651. return null;
  16652. }
  16653. return new Token_1.Token({
  16654. token: this.line[cursor],
  16655. startCursor: cursor,
  16656. endCursor: cursor
  16657. });
  16658. }
  16659. get lineFromCursor() {
  16660. return this.line.substr(this.cursor);
  16661. }
  16662. advancePastLine() {
  16663. const match = ROW_DELIMITER.exec(this.lineFromCursor);
  16664. if (!match) {
  16665. if (this.hasMoreData) {
  16666. return null;
  16667. }
  16668. this.cursor = this.lineLength;
  16669. return this;
  16670. }
  16671. this.cursor += (match.index || 0) + match[0].length;
  16672. return this;
  16673. }
  16674. advanceTo(cursor) {
  16675. this.cursor = cursor;
  16676. return this;
  16677. }
  16678. advanceToToken(token) {
  16679. this.cursor = token.startCursor;
  16680. return this;
  16681. }
  16682. advancePastToken(token) {
  16683. this.cursor = token.endCursor + 1;
  16684. return this;
  16685. }
  16686. truncateToCursor() {
  16687. this.line = this.lineFromCursor;
  16688. this.lineLength = this.line.length;
  16689. this.cursor = 0;
  16690. return this;
  16691. }
  16692. }
  16693. exports.Scanner = Scanner;
  16694. },{"./Token":159}],159:[function(require,module,exports){
  16695. "use strict";
  16696. Object.defineProperty(exports, "__esModule", {
  16697. value: true
  16698. });
  16699. exports.Token = void 0;
  16700. class Token {
  16701. constructor(tokenArgs) {
  16702. this.token = tokenArgs.token;
  16703. this.startCursor = tokenArgs.startCursor;
  16704. this.endCursor = tokenArgs.endCursor;
  16705. }
  16706. static isTokenRowDelimiter(token) {
  16707. const content = token.token;
  16708. return content === '\r' || content === '\n' || content === '\r\n';
  16709. }
  16710. static isTokenCarriageReturn(token, parserOptions) {
  16711. return token.token === parserOptions.carriageReturn;
  16712. }
  16713. static isTokenComment(token, parserOptions) {
  16714. return parserOptions.supportsComments && !!token && token.token === parserOptions.comment;
  16715. }
  16716. static isTokenEscapeCharacter(token, parserOptions) {
  16717. return token.token === parserOptions.escapeChar;
  16718. }
  16719. static isTokenQuote(token, parserOptions) {
  16720. return token.token === parserOptions.quote;
  16721. }
  16722. static isTokenDelimiter(token, parserOptions) {
  16723. return token.token === parserOptions.delimiter;
  16724. }
  16725. }
  16726. exports.Token = Token;
  16727. },{}],160:[function(require,module,exports){
  16728. "use strict";
  16729. Object.defineProperty(exports, "__esModule", {
  16730. value: true
  16731. });
  16732. exports.ColumnFormatter = void 0;
  16733. class ColumnFormatter {
  16734. constructor(parserOptions) {
  16735. if (parserOptions.trim) {
  16736. this.format = col => col.trim();
  16737. } else if (parserOptions.ltrim) {
  16738. this.format = col => col.trimLeft();
  16739. } else if (parserOptions.rtrim) {
  16740. this.format = col => col.trimRight();
  16741. } else {
  16742. this.format = col => col;
  16743. }
  16744. }
  16745. }
  16746. exports.ColumnFormatter = ColumnFormatter;
  16747. },{}],161:[function(require,module,exports){
  16748. "use strict";
  16749. Object.defineProperty(exports, "__esModule", {
  16750. value: true
  16751. });
  16752. exports.ColumnParser = void 0;
  16753. const NonQuotedColumnParser_1 = require("./NonQuotedColumnParser");
  16754. const QuotedColumnParser_1 = require("./QuotedColumnParser");
  16755. const Token_1 = require("../Token");
  16756. class ColumnParser {
  16757. constructor(parserOptions) {
  16758. this.parserOptions = parserOptions;
  16759. this.quotedColumnParser = new QuotedColumnParser_1.QuotedColumnParser(parserOptions);
  16760. this.nonQuotedColumnParser = new NonQuotedColumnParser_1.NonQuotedColumnParser(parserOptions);
  16761. }
  16762. parse(scanner) {
  16763. const {
  16764. nextNonSpaceToken
  16765. } = scanner;
  16766. if (nextNonSpaceToken !== null && Token_1.Token.isTokenQuote(nextNonSpaceToken, this.parserOptions)) {
  16767. scanner.advanceToToken(nextNonSpaceToken);
  16768. return this.quotedColumnParser.parse(scanner);
  16769. }
  16770. return this.nonQuotedColumnParser.parse(scanner);
  16771. }
  16772. }
  16773. exports.ColumnParser = ColumnParser;
  16774. },{"../Token":159,"./NonQuotedColumnParser":162,"./QuotedColumnParser":163}],162:[function(require,module,exports){
  16775. "use strict";
  16776. Object.defineProperty(exports, "__esModule", {
  16777. value: true
  16778. });
  16779. exports.NonQuotedColumnParser = void 0;
  16780. const ColumnFormatter_1 = require("./ColumnFormatter");
  16781. const Token_1 = require("../Token");
  16782. class NonQuotedColumnParser {
  16783. constructor(parserOptions) {
  16784. this.parserOptions = parserOptions;
  16785. this.columnFormatter = new ColumnFormatter_1.ColumnFormatter(parserOptions);
  16786. }
  16787. parse(scanner) {
  16788. if (!scanner.hasMoreCharacters) {
  16789. return null;
  16790. }
  16791. const {
  16792. parserOptions
  16793. } = this;
  16794. const characters = [];
  16795. let nextToken = scanner.nextCharacterToken;
  16796. for (; nextToken; nextToken = scanner.nextCharacterToken) {
  16797. if (Token_1.Token.isTokenDelimiter(nextToken, parserOptions) || Token_1.Token.isTokenRowDelimiter(nextToken)) {
  16798. break;
  16799. }
  16800. characters.push(nextToken.token);
  16801. scanner.advancePastToken(nextToken);
  16802. }
  16803. return this.columnFormatter.format(characters.join(''));
  16804. }
  16805. }
  16806. exports.NonQuotedColumnParser = NonQuotedColumnParser;
  16807. },{"../Token":159,"./ColumnFormatter":160}],163:[function(require,module,exports){
  16808. "use strict";
  16809. Object.defineProperty(exports, "__esModule", {
  16810. value: true
  16811. });
  16812. exports.QuotedColumnParser = void 0;
  16813. const ColumnFormatter_1 = require("./ColumnFormatter");
  16814. const Token_1 = require("../Token");
  16815. class QuotedColumnParser {
  16816. constructor(parserOptions) {
  16817. this.parserOptions = parserOptions;
  16818. this.columnFormatter = new ColumnFormatter_1.ColumnFormatter(parserOptions);
  16819. }
  16820. parse(scanner) {
  16821. if (!scanner.hasMoreCharacters) {
  16822. return null;
  16823. }
  16824. const originalCursor = scanner.cursor;
  16825. const {
  16826. foundClosingQuote,
  16827. col
  16828. } = this.gatherDataBetweenQuotes(scanner);
  16829. if (!foundClosingQuote) {
  16830. // reset the cursor to the original
  16831. scanner.advanceTo(originalCursor);
  16832. // if we didnt find a closing quote but we potentially have more data then skip the parsing
  16833. // and return the original scanner.
  16834. if (!scanner.hasMoreData) {
  16835. throw new Error(`Parse Error: missing closing: '${this.parserOptions.quote || ''}' in line: at '${scanner.lineFromCursor.replace(/[\r\n]/g, "\\n'")}'`);
  16836. }
  16837. return null;
  16838. }
  16839. this.checkForMalformedColumn(scanner);
  16840. return col;
  16841. }
  16842. gatherDataBetweenQuotes(scanner) {
  16843. const {
  16844. parserOptions
  16845. } = this;
  16846. let foundStartingQuote = false;
  16847. let foundClosingQuote = false;
  16848. const characters = [];
  16849. let nextToken = scanner.nextCharacterToken;
  16850. for (; !foundClosingQuote && nextToken !== null; nextToken = scanner.nextCharacterToken) {
  16851. const isQuote = Token_1.Token.isTokenQuote(nextToken, parserOptions);
  16852. // ignore first quote
  16853. if (!foundStartingQuote && isQuote) {
  16854. foundStartingQuote = true;
  16855. } else if (foundStartingQuote) {
  16856. if (Token_1.Token.isTokenEscapeCharacter(nextToken, parserOptions)) {
  16857. // advance past the escape character so we can get the next one in line
  16858. scanner.advancePastToken(nextToken);
  16859. const tokenFollowingEscape = scanner.nextCharacterToken;
  16860. // if the character following the escape is a quote character then just add
  16861. // the quote and advance to that character
  16862. if (tokenFollowingEscape !== null && (Token_1.Token.isTokenQuote(tokenFollowingEscape, parserOptions) || Token_1.Token.isTokenEscapeCharacter(tokenFollowingEscape, parserOptions))) {
  16863. characters.push(tokenFollowingEscape.token);
  16864. nextToken = tokenFollowingEscape;
  16865. } else if (isQuote) {
  16866. // if the escape is also a quote then we found our closing quote and finish early
  16867. foundClosingQuote = true;
  16868. } else {
  16869. // other wise add the escape token to the characters since it wast escaping anything
  16870. characters.push(nextToken.token);
  16871. }
  16872. } else if (isQuote) {
  16873. // we found our closing quote!
  16874. foundClosingQuote = true;
  16875. } else {
  16876. // add the token to the characters
  16877. characters.push(nextToken.token);
  16878. }
  16879. }
  16880. scanner.advancePastToken(nextToken);
  16881. }
  16882. return {
  16883. col: this.columnFormatter.format(characters.join('')),
  16884. foundClosingQuote
  16885. };
  16886. }
  16887. checkForMalformedColumn(scanner) {
  16888. const {
  16889. parserOptions
  16890. } = this;
  16891. const {
  16892. nextNonSpaceToken
  16893. } = scanner;
  16894. if (nextNonSpaceToken) {
  16895. const isNextTokenADelimiter = Token_1.Token.isTokenDelimiter(nextNonSpaceToken, parserOptions);
  16896. const isNextTokenARowDelimiter = Token_1.Token.isTokenRowDelimiter(nextNonSpaceToken);
  16897. if (!(isNextTokenADelimiter || isNextTokenARowDelimiter)) {
  16898. // if the final quote was NOT followed by a column (,) or row(\n) delimiter then its a bad column
  16899. // tldr: only part of the column was quoted
  16900. const linePreview = scanner.lineFromCursor.substr(0, 10).replace(/[\r\n]/g, "\\n'");
  16901. throw new Error(`Parse Error: expected: '${parserOptions.escapedDelimiter}' OR new line got: '${nextNonSpaceToken.token}'. at '${linePreview}`);
  16902. }
  16903. scanner.advanceToToken(nextNonSpaceToken);
  16904. } else if (!scanner.hasMoreData) {
  16905. scanner.advancePastLine();
  16906. }
  16907. }
  16908. }
  16909. exports.QuotedColumnParser = QuotedColumnParser;
  16910. },{"../Token":159,"./ColumnFormatter":160}],164:[function(require,module,exports){
  16911. "use strict";
  16912. Object.defineProperty(exports, "__esModule", {
  16913. value: true
  16914. });
  16915. exports.ColumnFormatter = exports.QuotedColumnParser = exports.NonQuotedColumnParser = exports.ColumnParser = void 0;
  16916. var ColumnParser_1 = require("./ColumnParser");
  16917. Object.defineProperty(exports, "ColumnParser", {
  16918. enumerable: true,
  16919. get: function () {
  16920. return ColumnParser_1.ColumnParser;
  16921. }
  16922. });
  16923. var NonQuotedColumnParser_1 = require("./NonQuotedColumnParser");
  16924. Object.defineProperty(exports, "NonQuotedColumnParser", {
  16925. enumerable: true,
  16926. get: function () {
  16927. return NonQuotedColumnParser_1.NonQuotedColumnParser;
  16928. }
  16929. });
  16930. var QuotedColumnParser_1 = require("./QuotedColumnParser");
  16931. Object.defineProperty(exports, "QuotedColumnParser", {
  16932. enumerable: true,
  16933. get: function () {
  16934. return QuotedColumnParser_1.QuotedColumnParser;
  16935. }
  16936. });
  16937. var ColumnFormatter_1 = require("./ColumnFormatter");
  16938. Object.defineProperty(exports, "ColumnFormatter", {
  16939. enumerable: true,
  16940. get: function () {
  16941. return ColumnFormatter_1.ColumnFormatter;
  16942. }
  16943. });
  16944. },{"./ColumnFormatter":160,"./ColumnParser":161,"./NonQuotedColumnParser":162,"./QuotedColumnParser":163}],165:[function(require,module,exports){
  16945. "use strict";
  16946. Object.defineProperty(exports, "__esModule", {
  16947. value: true
  16948. });
  16949. exports.QuotedColumnParser = exports.NonQuotedColumnParser = exports.ColumnParser = exports.Token = exports.Scanner = exports.RowParser = exports.Parser = void 0;
  16950. var Parser_1 = require("./Parser");
  16951. Object.defineProperty(exports, "Parser", {
  16952. enumerable: true,
  16953. get: function () {
  16954. return Parser_1.Parser;
  16955. }
  16956. });
  16957. var RowParser_1 = require("./RowParser");
  16958. Object.defineProperty(exports, "RowParser", {
  16959. enumerable: true,
  16960. get: function () {
  16961. return RowParser_1.RowParser;
  16962. }
  16963. });
  16964. var Scanner_1 = require("./Scanner");
  16965. Object.defineProperty(exports, "Scanner", {
  16966. enumerable: true,
  16967. get: function () {
  16968. return Scanner_1.Scanner;
  16969. }
  16970. });
  16971. var Token_1 = require("./Token");
  16972. Object.defineProperty(exports, "Token", {
  16973. enumerable: true,
  16974. get: function () {
  16975. return Token_1.Token;
  16976. }
  16977. });
  16978. var column_1 = require("./column");
  16979. Object.defineProperty(exports, "ColumnParser", {
  16980. enumerable: true,
  16981. get: function () {
  16982. return column_1.ColumnParser;
  16983. }
  16984. });
  16985. Object.defineProperty(exports, "NonQuotedColumnParser", {
  16986. enumerable: true,
  16987. get: function () {
  16988. return column_1.NonQuotedColumnParser;
  16989. }
  16990. });
  16991. Object.defineProperty(exports, "QuotedColumnParser", {
  16992. enumerable: true,
  16993. get: function () {
  16994. return column_1.QuotedColumnParser;
  16995. }
  16996. });
  16997. },{"./Parser":156,"./RowParser":157,"./Scanner":158,"./Token":159,"./column":164}],166:[function(require,module,exports){
  16998. "use strict";
  16999. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  17000. return mod && mod.__esModule ? mod : {
  17001. "default": mod
  17002. };
  17003. };
  17004. Object.defineProperty(exports, "__esModule", {
  17005. value: true
  17006. });
  17007. exports.HeaderTransformer = void 0;
  17008. const lodash_isundefined_1 = __importDefault(require("lodash.isundefined"));
  17009. const lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  17010. const lodash_uniq_1 = __importDefault(require("lodash.uniq"));
  17011. const lodash_groupby_1 = __importDefault(require("lodash.groupby"));
  17012. class HeaderTransformer {
  17013. constructor(parserOptions) {
  17014. this.headers = null;
  17015. this.receivedHeaders = false;
  17016. this.shouldUseFirstRow = false;
  17017. this.processedFirstRow = false;
  17018. this.headersLength = 0;
  17019. this.parserOptions = parserOptions;
  17020. if (parserOptions.headers === true) {
  17021. this.shouldUseFirstRow = true;
  17022. } else if (Array.isArray(parserOptions.headers)) {
  17023. this.setHeaders(parserOptions.headers);
  17024. } else if (lodash_isfunction_1.default(parserOptions.headers)) {
  17025. this.headersTransform = parserOptions.headers;
  17026. }
  17027. }
  17028. transform(row, cb) {
  17029. if (!this.shouldMapRow(row)) {
  17030. return cb(null, {
  17031. row: null,
  17032. isValid: true
  17033. });
  17034. }
  17035. return cb(null, this.processRow(row));
  17036. }
  17037. shouldMapRow(row) {
  17038. const {
  17039. parserOptions
  17040. } = this;
  17041. if (!this.headersTransform && parserOptions.renameHeaders && !this.processedFirstRow) {
  17042. if (!this.receivedHeaders) {
  17043. throw new Error('Error renaming headers: new headers must be provided in an array');
  17044. }
  17045. this.processedFirstRow = true;
  17046. return false;
  17047. }
  17048. if (!this.receivedHeaders && Array.isArray(row)) {
  17049. if (this.headersTransform) {
  17050. this.setHeaders(this.headersTransform(row));
  17051. } else if (this.shouldUseFirstRow) {
  17052. this.setHeaders(row);
  17053. } else {
  17054. // dont do anything with the headers if we didnt receive a transform or shouldnt use the first row.
  17055. return true;
  17056. }
  17057. return false;
  17058. }
  17059. return true;
  17060. }
  17061. processRow(row) {
  17062. if (!this.headers) {
  17063. return {
  17064. row: row,
  17065. isValid: true
  17066. };
  17067. }
  17068. const {
  17069. parserOptions
  17070. } = this;
  17071. if (!parserOptions.discardUnmappedColumns && row.length > this.headersLength) {
  17072. if (!parserOptions.strictColumnHandling) {
  17073. throw new Error(`Unexpected Error: column header mismatch expected: ${this.headersLength} columns got: ${row.length}`);
  17074. }
  17075. return {
  17076. row: row,
  17077. isValid: false,
  17078. reason: `Column header mismatch expected: ${this.headersLength} columns got: ${row.length}`
  17079. };
  17080. }
  17081. if (parserOptions.strictColumnHandling && row.length < this.headersLength) {
  17082. return {
  17083. row: row,
  17084. isValid: false,
  17085. reason: `Column header mismatch expected: ${this.headersLength} columns got: ${row.length}`
  17086. };
  17087. }
  17088. return {
  17089. row: this.mapHeaders(row),
  17090. isValid: true
  17091. };
  17092. }
  17093. mapHeaders(row) {
  17094. const rowMap = {};
  17095. const {
  17096. headers,
  17097. headersLength
  17098. } = this;
  17099. for (let i = 0; i < headersLength; i += 1) {
  17100. const header = headers[i];
  17101. if (!lodash_isundefined_1.default(header)) {
  17102. const val = row[i];
  17103. // eslint-disable-next-line no-param-reassign
  17104. if (lodash_isundefined_1.default(val)) {
  17105. rowMap[header] = '';
  17106. } else {
  17107. rowMap[header] = val;
  17108. }
  17109. }
  17110. }
  17111. return rowMap;
  17112. }
  17113. setHeaders(headers) {
  17114. var _a;
  17115. const filteredHeaders = headers.filter(h => !!h);
  17116. if (lodash_uniq_1.default(filteredHeaders).length !== filteredHeaders.length) {
  17117. const grouped = lodash_groupby_1.default(filteredHeaders);
  17118. const duplicates = Object.keys(grouped).filter(dup => grouped[dup].length > 1);
  17119. throw new Error(`Duplicate headers found ${JSON.stringify(duplicates)}`);
  17120. }
  17121. this.headers = headers;
  17122. this.receivedHeaders = true;
  17123. this.headersLength = ((_a = this.headers) === null || _a === void 0 ? void 0 : _a.length) || 0;
  17124. }
  17125. }
  17126. exports.HeaderTransformer = HeaderTransformer;
  17127. },{"lodash.groupby":443,"lodash.isfunction":446,"lodash.isundefined":448,"lodash.uniq":449}],167:[function(require,module,exports){
  17128. "use strict";
  17129. var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  17130. return mod && mod.__esModule ? mod : {
  17131. "default": mod
  17132. };
  17133. };
  17134. Object.defineProperty(exports, "__esModule", {
  17135. value: true
  17136. });
  17137. exports.RowTransformerValidator = void 0;
  17138. const lodash_isfunction_1 = __importDefault(require("lodash.isfunction"));
  17139. const types_1 = require("../types");
  17140. class RowTransformerValidator {
  17141. constructor() {
  17142. this._rowTransform = null;
  17143. this._rowValidator = null;
  17144. }
  17145. // eslint-disable-next-line @typescript-eslint/no-shadow
  17146. static createTransform(transformFunction) {
  17147. if (types_1.isSyncTransform(transformFunction)) {
  17148. return (row, cb) => {
  17149. let transformed = null;
  17150. try {
  17151. transformed = transformFunction(row);
  17152. } catch (e) {
  17153. return cb(e);
  17154. }
  17155. return cb(null, transformed);
  17156. };
  17157. }
  17158. return transformFunction;
  17159. }
  17160. static createValidator(validateFunction) {
  17161. if (types_1.isSyncValidate(validateFunction)) {
  17162. return (row, cb) => {
  17163. cb(null, {
  17164. row,
  17165. isValid: validateFunction(row)
  17166. });
  17167. };
  17168. }
  17169. return (row, cb) => {
  17170. validateFunction(row, (err, isValid, reason) => {
  17171. if (err) {
  17172. return cb(err);
  17173. }
  17174. if (isValid) {
  17175. return cb(null, {
  17176. row,
  17177. isValid,
  17178. reason
  17179. });
  17180. }
  17181. return cb(null, {
  17182. row,
  17183. isValid: false,
  17184. reason
  17185. });
  17186. });
  17187. };
  17188. }
  17189. set rowTransform(transformFunction) {
  17190. if (!lodash_isfunction_1.default(transformFunction)) {
  17191. throw new TypeError('The transform should be a function');
  17192. }
  17193. this._rowTransform = RowTransformerValidator.createTransform(transformFunction);
  17194. }
  17195. set rowValidator(validateFunction) {
  17196. if (!lodash_isfunction_1.default(validateFunction)) {
  17197. throw new TypeError('The validate should be a function');
  17198. }
  17199. this._rowValidator = RowTransformerValidator.createValidator(validateFunction);
  17200. }
  17201. transformAndValidate(row, cb) {
  17202. return this.callTransformer(row, (transformErr, transformedRow) => {
  17203. if (transformErr) {
  17204. return cb(transformErr);
  17205. }
  17206. if (!transformedRow) {
  17207. return cb(null, {
  17208. row: null,
  17209. isValid: true
  17210. });
  17211. }
  17212. return this.callValidator(transformedRow, (validateErr, validationResult) => {
  17213. if (validateErr) {
  17214. return cb(validateErr);
  17215. }
  17216. if (validationResult && !validationResult.isValid) {
  17217. return cb(null, {
  17218. row: transformedRow,
  17219. isValid: false,
  17220. reason: validationResult.reason
  17221. });
  17222. }
  17223. return cb(null, {
  17224. row: transformedRow,
  17225. isValid: true
  17226. });
  17227. });
  17228. });
  17229. }
  17230. callTransformer(row, cb) {
  17231. if (!this._rowTransform) {
  17232. return cb(null, row);
  17233. }
  17234. return this._rowTransform(row, cb);
  17235. }
  17236. callValidator(row, cb) {
  17237. if (!this._rowValidator) {
  17238. return cb(null, {
  17239. row,
  17240. isValid: true
  17241. });
  17242. }
  17243. return this._rowValidator(row, cb);
  17244. }
  17245. }
  17246. exports.RowTransformerValidator = RowTransformerValidator;
  17247. },{"../types":169,"lodash.isfunction":446}],168:[function(require,module,exports){
  17248. "use strict";
  17249. Object.defineProperty(exports, "__esModule", {
  17250. value: true
  17251. });
  17252. exports.HeaderTransformer = exports.RowTransformerValidator = void 0;
  17253. var RowTransformerValidator_1 = require("./RowTransformerValidator");
  17254. Object.defineProperty(exports, "RowTransformerValidator", {
  17255. enumerable: true,
  17256. get: function () {
  17257. return RowTransformerValidator_1.RowTransformerValidator;
  17258. }
  17259. });
  17260. var HeaderTransformer_1 = require("./HeaderTransformer");
  17261. Object.defineProperty(exports, "HeaderTransformer", {
  17262. enumerable: true,
  17263. get: function () {
  17264. return HeaderTransformer_1.HeaderTransformer;
  17265. }
  17266. });
  17267. },{"./HeaderTransformer":166,"./RowTransformerValidator":167}],169:[function(require,module,exports){
  17268. "use strict";
  17269. Object.defineProperty(exports, "__esModule", {
  17270. value: true
  17271. });
  17272. exports.isSyncValidate = exports.isSyncTransform = void 0;
  17273. exports.isSyncTransform = transform => transform.length === 1;
  17274. exports.isSyncValidate = validate => validate.length === 1;
  17275. },{}],170:[function(require,module,exports){
  17276. 'use strict';
  17277. const asn1 = exports;
  17278. asn1.bignum = require('bn.js');
  17279. asn1.define = require('./asn1/api').define;
  17280. asn1.base = require('./asn1/base');
  17281. asn1.constants = require('./asn1/constants');
  17282. asn1.decoders = require('./asn1/decoders');
  17283. asn1.encoders = require('./asn1/encoders');
  17284. },{"./asn1/api":171,"./asn1/base":173,"./asn1/constants":177,"./asn1/decoders":179,"./asn1/encoders":182,"bn.js":184}],171:[function(require,module,exports){
  17285. 'use strict';
  17286. const encoders = require('./encoders');
  17287. const decoders = require('./decoders');
  17288. const inherits = require('inherits');
  17289. const api = exports;
  17290. api.define = function define(name, body) {
  17291. return new Entity(name, body);
  17292. };
  17293. function Entity(name, body) {
  17294. this.name = name;
  17295. this.body = body;
  17296. this.decoders = {};
  17297. this.encoders = {};
  17298. }
  17299. Entity.prototype._createNamed = function createNamed(Base) {
  17300. const name = this.name;
  17301. function Generated(entity) {
  17302. this._initNamed(entity, name);
  17303. }
  17304. inherits(Generated, Base);
  17305. Generated.prototype._initNamed = function _initNamed(entity, name) {
  17306. Base.call(this, entity, name);
  17307. };
  17308. return new Generated(this);
  17309. };
  17310. Entity.prototype._getDecoder = function _getDecoder(enc) {
  17311. enc = enc || 'der';
  17312. // Lazily create decoder
  17313. if (!this.decoders.hasOwnProperty(enc)) this.decoders[enc] = this._createNamed(decoders[enc]);
  17314. return this.decoders[enc];
  17315. };
  17316. Entity.prototype.decode = function decode(data, enc, options) {
  17317. return this._getDecoder(enc).decode(data, options);
  17318. };
  17319. Entity.prototype._getEncoder = function _getEncoder(enc) {
  17320. enc = enc || 'der';
  17321. // Lazily create encoder
  17322. if (!this.encoders.hasOwnProperty(enc)) this.encoders[enc] = this._createNamed(encoders[enc]);
  17323. return this.encoders[enc];
  17324. };
  17325. Entity.prototype.encode = function encode(data, enc, /* internal */reporter) {
  17326. return this._getEncoder(enc).encode(data, reporter);
  17327. };
  17328. },{"./decoders":179,"./encoders":182,"inherits":440}],172:[function(require,module,exports){
  17329. 'use strict';
  17330. const inherits = require('inherits');
  17331. const Reporter = require('../base/reporter').Reporter;
  17332. const Buffer = require('safer-buffer').Buffer;
  17333. function DecoderBuffer(base, options) {
  17334. Reporter.call(this, options);
  17335. if (!Buffer.isBuffer(base)) {
  17336. this.error('Input not Buffer');
  17337. return;
  17338. }
  17339. this.base = base;
  17340. this.offset = 0;
  17341. this.length = base.length;
  17342. }
  17343. inherits(DecoderBuffer, Reporter);
  17344. exports.DecoderBuffer = DecoderBuffer;
  17345. DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) {
  17346. if (data instanceof DecoderBuffer) {
  17347. return true;
  17348. }
  17349. // Or accept compatible API
  17350. const isCompatible = typeof data === 'object' && Buffer.isBuffer(data.base) && data.constructor.name === 'DecoderBuffer' && typeof data.offset === 'number' && typeof data.length === 'number' && typeof data.save === 'function' && typeof data.restore === 'function' && typeof data.isEmpty === 'function' && typeof data.readUInt8 === 'function' && typeof data.skip === 'function' && typeof data.raw === 'function';
  17351. return isCompatible;
  17352. };
  17353. DecoderBuffer.prototype.save = function save() {
  17354. return {
  17355. offset: this.offset,
  17356. reporter: Reporter.prototype.save.call(this)
  17357. };
  17358. };
  17359. DecoderBuffer.prototype.restore = function restore(save) {
  17360. // Return skipped data
  17361. const res = new DecoderBuffer(this.base);
  17362. res.offset = save.offset;
  17363. res.length = this.offset;
  17364. this.offset = save.offset;
  17365. Reporter.prototype.restore.call(this, save.reporter);
  17366. return res;
  17367. };
  17368. DecoderBuffer.prototype.isEmpty = function isEmpty() {
  17369. return this.offset === this.length;
  17370. };
  17371. DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
  17372. if (this.offset + 1 <= this.length) return this.base.readUInt8(this.offset++, true);else return this.error(fail || 'DecoderBuffer overrun');
  17373. };
  17374. DecoderBuffer.prototype.skip = function skip(bytes, fail) {
  17375. if (!(this.offset + bytes <= this.length)) return this.error(fail || 'DecoderBuffer overrun');
  17376. const res = new DecoderBuffer(this.base);
  17377. // Share reporter state
  17378. res._reporterState = this._reporterState;
  17379. res.offset = this.offset;
  17380. res.length = this.offset + bytes;
  17381. this.offset += bytes;
  17382. return res;
  17383. };
  17384. DecoderBuffer.prototype.raw = function raw(save) {
  17385. return this.base.slice(save ? save.offset : this.offset, this.length);
  17386. };
  17387. function EncoderBuffer(value, reporter) {
  17388. if (Array.isArray(value)) {
  17389. this.length = 0;
  17390. this.value = value.map(function (item) {
  17391. if (!EncoderBuffer.isEncoderBuffer(item)) item = new EncoderBuffer(item, reporter);
  17392. this.length += item.length;
  17393. return item;
  17394. }, this);
  17395. } else if (typeof value === 'number') {
  17396. if (!(0 <= value && value <= 0xff)) return reporter.error('non-byte EncoderBuffer value');
  17397. this.value = value;
  17398. this.length = 1;
  17399. } else if (typeof value === 'string') {
  17400. this.value = value;
  17401. this.length = Buffer.byteLength(value);
  17402. } else if (Buffer.isBuffer(value)) {
  17403. this.value = value;
  17404. this.length = value.length;
  17405. } else {
  17406. return reporter.error('Unsupported type: ' + typeof value);
  17407. }
  17408. }
  17409. exports.EncoderBuffer = EncoderBuffer;
  17410. EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) {
  17411. if (data instanceof EncoderBuffer) {
  17412. return true;
  17413. }
  17414. // Or accept compatible API
  17415. const isCompatible = typeof data === 'object' && data.constructor.name === 'EncoderBuffer' && typeof data.length === 'number' && typeof data.join === 'function';
  17416. return isCompatible;
  17417. };
  17418. EncoderBuffer.prototype.join = function join(out, offset) {
  17419. if (!out) out = Buffer.alloc(this.length);
  17420. if (!offset) offset = 0;
  17421. if (this.length === 0) return out;
  17422. if (Array.isArray(this.value)) {
  17423. this.value.forEach(function (item) {
  17424. item.join(out, offset);
  17425. offset += item.length;
  17426. });
  17427. } else {
  17428. if (typeof this.value === 'number') out[offset] = this.value;else if (typeof this.value === 'string') out.write(this.value, offset);else if (Buffer.isBuffer(this.value)) this.value.copy(out, offset);
  17429. offset += this.length;
  17430. }
  17431. return out;
  17432. };
  17433. },{"../base/reporter":175,"inherits":440,"safer-buffer":495}],173:[function(require,module,exports){
  17434. 'use strict';
  17435. const base = exports;
  17436. base.Reporter = require('./reporter').Reporter;
  17437. base.DecoderBuffer = require('./buffer').DecoderBuffer;
  17438. base.EncoderBuffer = require('./buffer').EncoderBuffer;
  17439. base.Node = require('./node');
  17440. },{"./buffer":172,"./node":174,"./reporter":175}],174:[function(require,module,exports){
  17441. 'use strict';
  17442. const Reporter = require('../base/reporter').Reporter;
  17443. const EncoderBuffer = require('../base/buffer').EncoderBuffer;
  17444. const DecoderBuffer = require('../base/buffer').DecoderBuffer;
  17445. const assert = require('minimalistic-assert');
  17446. // Supported tags
  17447. const tags = ['seq', 'seqof', 'set', 'setof', 'objid', 'bool', 'gentime', 'utctime', 'null_', 'enum', 'int', 'objDesc', 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str', 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr'];
  17448. // Public methods list
  17449. const methods = ['key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', 'any', 'contains'].concat(tags);
  17450. // Overrided methods list
  17451. const overrided = ['_peekTag', '_decodeTag', '_use', '_decodeStr', '_decodeObjid', '_decodeTime', '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList', '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime', '_encodeNull', '_encodeInt', '_encodeBool'];
  17452. function Node(enc, parent, name) {
  17453. const state = {};
  17454. this._baseState = state;
  17455. state.name = name;
  17456. state.enc = enc;
  17457. state.parent = parent || null;
  17458. state.children = null;
  17459. // State
  17460. state.tag = null;
  17461. state.args = null;
  17462. state.reverseArgs = null;
  17463. state.choice = null;
  17464. state.optional = false;
  17465. state.any = false;
  17466. state.obj = false;
  17467. state.use = null;
  17468. state.useDecoder = null;
  17469. state.key = null;
  17470. state['default'] = null;
  17471. state.explicit = null;
  17472. state.implicit = null;
  17473. state.contains = null;
  17474. // Should create new instance on each method
  17475. if (!state.parent) {
  17476. state.children = [];
  17477. this._wrap();
  17478. }
  17479. }
  17480. module.exports = Node;
  17481. const stateProps = ['enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice', 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit', 'implicit', 'contains'];
  17482. Node.prototype.clone = function clone() {
  17483. const state = this._baseState;
  17484. const cstate = {};
  17485. stateProps.forEach(function (prop) {
  17486. cstate[prop] = state[prop];
  17487. });
  17488. const res = new this.constructor(cstate.parent);
  17489. res._baseState = cstate;
  17490. return res;
  17491. };
  17492. Node.prototype._wrap = function wrap() {
  17493. const state = this._baseState;
  17494. methods.forEach(function (method) {
  17495. this[method] = function _wrappedMethod() {
  17496. const clone = new this.constructor(this);
  17497. state.children.push(clone);
  17498. return clone[method].apply(clone, arguments);
  17499. };
  17500. }, this);
  17501. };
  17502. Node.prototype._init = function init(body) {
  17503. const state = this._baseState;
  17504. assert(state.parent === null);
  17505. body.call(this);
  17506. // Filter children
  17507. state.children = state.children.filter(function (child) {
  17508. return child._baseState.parent === this;
  17509. }, this);
  17510. assert.equal(state.children.length, 1, 'Root node can have only one child');
  17511. };
  17512. Node.prototype._useArgs = function useArgs(args) {
  17513. const state = this._baseState;
  17514. // Filter children and args
  17515. const children = args.filter(function (arg) {
  17516. return arg instanceof this.constructor;
  17517. }, this);
  17518. args = args.filter(function (arg) {
  17519. return !(arg instanceof this.constructor);
  17520. }, this);
  17521. if (children.length !== 0) {
  17522. assert(state.children === null);
  17523. state.children = children;
  17524. // Replace parent to maintain backward link
  17525. children.forEach(function (child) {
  17526. child._baseState.parent = this;
  17527. }, this);
  17528. }
  17529. if (args.length !== 0) {
  17530. assert(state.args === null);
  17531. state.args = args;
  17532. state.reverseArgs = args.map(function (arg) {
  17533. if (typeof arg !== 'object' || arg.constructor !== Object) return arg;
  17534. const res = {};
  17535. Object.keys(arg).forEach(function (key) {
  17536. if (key == (key | 0)) key |= 0;
  17537. const value = arg[key];
  17538. res[value] = key;
  17539. });
  17540. return res;
  17541. });
  17542. }
  17543. };
  17544. //
  17545. // Overrided methods
  17546. //
  17547. overrided.forEach(function (method) {
  17548. Node.prototype[method] = function _overrided() {
  17549. const state = this._baseState;
  17550. throw new Error(method + ' not implemented for encoding: ' + state.enc);
  17551. };
  17552. });
  17553. //
  17554. // Public methods
  17555. //
  17556. tags.forEach(function (tag) {
  17557. Node.prototype[tag] = function _tagMethod() {
  17558. const state = this._baseState;
  17559. const args = Array.prototype.slice.call(arguments);
  17560. assert(state.tag === null);
  17561. state.tag = tag;
  17562. this._useArgs(args);
  17563. return this;
  17564. };
  17565. });
  17566. Node.prototype.use = function use(item) {
  17567. assert(item);
  17568. const state = this._baseState;
  17569. assert(state.use === null);
  17570. state.use = item;
  17571. return this;
  17572. };
  17573. Node.prototype.optional = function optional() {
  17574. const state = this._baseState;
  17575. state.optional = true;
  17576. return this;
  17577. };
  17578. Node.prototype.def = function def(val) {
  17579. const state = this._baseState;
  17580. assert(state['default'] === null);
  17581. state['default'] = val;
  17582. state.optional = true;
  17583. return this;
  17584. };
  17585. Node.prototype.explicit = function explicit(num) {
  17586. const state = this._baseState;
  17587. assert(state.explicit === null && state.implicit === null);
  17588. state.explicit = num;
  17589. return this;
  17590. };
  17591. Node.prototype.implicit = function implicit(num) {
  17592. const state = this._baseState;
  17593. assert(state.explicit === null && state.implicit === null);
  17594. state.implicit = num;
  17595. return this;
  17596. };
  17597. Node.prototype.obj = function obj() {
  17598. const state = this._baseState;
  17599. const args = Array.prototype.slice.call(arguments);
  17600. state.obj = true;
  17601. if (args.length !== 0) this._useArgs(args);
  17602. return this;
  17603. };
  17604. Node.prototype.key = function key(newKey) {
  17605. const state = this._baseState;
  17606. assert(state.key === null);
  17607. state.key = newKey;
  17608. return this;
  17609. };
  17610. Node.prototype.any = function any() {
  17611. const state = this._baseState;
  17612. state.any = true;
  17613. return this;
  17614. };
  17615. Node.prototype.choice = function choice(obj) {
  17616. const state = this._baseState;
  17617. assert(state.choice === null);
  17618. state.choice = obj;
  17619. this._useArgs(Object.keys(obj).map(function (key) {
  17620. return obj[key];
  17621. }));
  17622. return this;
  17623. };
  17624. Node.prototype.contains = function contains(item) {
  17625. const state = this._baseState;
  17626. assert(state.use === null);
  17627. state.contains = item;
  17628. return this;
  17629. };
  17630. //
  17631. // Decoding
  17632. //
  17633. Node.prototype._decode = function decode(input, options) {
  17634. const state = this._baseState;
  17635. // Decode root node
  17636. if (state.parent === null) return input.wrapResult(state.children[0]._decode(input, options));
  17637. let result = state['default'];
  17638. let present = true;
  17639. let prevKey = null;
  17640. if (state.key !== null) prevKey = input.enterKey(state.key);
  17641. // Check if tag is there
  17642. if (state.optional) {
  17643. let tag = null;
  17644. if (state.explicit !== null) tag = state.explicit;else if (state.implicit !== null) tag = state.implicit;else if (state.tag !== null) tag = state.tag;
  17645. if (tag === null && !state.any) {
  17646. // Trial and Error
  17647. const save = input.save();
  17648. try {
  17649. if (state.choice === null) this._decodeGeneric(state.tag, input, options);else this._decodeChoice(input, options);
  17650. present = true;
  17651. } catch (e) {
  17652. present = false;
  17653. }
  17654. input.restore(save);
  17655. } else {
  17656. present = this._peekTag(input, tag, state.any);
  17657. if (input.isError(present)) return present;
  17658. }
  17659. }
  17660. // Push object on stack
  17661. let prevObj;
  17662. if (state.obj && present) prevObj = input.enterObject();
  17663. if (present) {
  17664. // Unwrap explicit values
  17665. if (state.explicit !== null) {
  17666. const explicit = this._decodeTag(input, state.explicit);
  17667. if (input.isError(explicit)) return explicit;
  17668. input = explicit;
  17669. }
  17670. const start = input.offset;
  17671. // Unwrap implicit and normal values
  17672. if (state.use === null && state.choice === null) {
  17673. let save;
  17674. if (state.any) save = input.save();
  17675. const body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any);
  17676. if (input.isError(body)) return body;
  17677. if (state.any) result = input.raw(save);else input = body;
  17678. }
  17679. if (options && options.track && state.tag !== null) options.track(input.path(), start, input.length, 'tagged');
  17680. if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, 'content');
  17681. // Select proper method for tag
  17682. if (state.any) {
  17683. // no-op
  17684. } else if (state.choice === null) {
  17685. result = this._decodeGeneric(state.tag, input, options);
  17686. } else {
  17687. result = this._decodeChoice(input, options);
  17688. }
  17689. if (input.isError(result)) return result;
  17690. // Decode children
  17691. if (!state.any && state.choice === null && state.children !== null) {
  17692. state.children.forEach(function decodeChildren(child) {
  17693. // NOTE: We are ignoring errors here, to let parser continue with other
  17694. // parts of encoded data
  17695. child._decode(input, options);
  17696. });
  17697. }
  17698. // Decode contained/encoded by schema, only in bit or octet strings
  17699. if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
  17700. const data = new DecoderBuffer(result);
  17701. result = this._getUse(state.contains, input._reporterState.obj)._decode(data, options);
  17702. }
  17703. }
  17704. // Pop object
  17705. if (state.obj && present) result = input.leaveObject(prevObj);
  17706. // Set key
  17707. if (state.key !== null && (result !== null || present === true)) input.leaveKey(prevKey, state.key, result);else if (prevKey !== null) input.exitKey(prevKey);
  17708. return result;
  17709. };
  17710. Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) {
  17711. const state = this._baseState;
  17712. if (tag === 'seq' || tag === 'set') return null;
  17713. if (tag === 'seqof' || tag === 'setof') return this._decodeList(input, tag, state.args[0], options);else if (/str$/.test(tag)) return this._decodeStr(input, tag, options);else if (tag === 'objid' && state.args) return this._decodeObjid(input, state.args[0], state.args[1], options);else if (tag === 'objid') return this._decodeObjid(input, null, null, options);else if (tag === 'gentime' || tag === 'utctime') return this._decodeTime(input, tag, options);else if (tag === 'null_') return this._decodeNull(input, options);else if (tag === 'bool') return this._decodeBool(input, options);else if (tag === 'objDesc') return this._decodeStr(input, tag, options);else if (tag === 'int' || tag === 'enum') return this._decodeInt(input, state.args && state.args[0], options);
  17714. if (state.use !== null) {
  17715. return this._getUse(state.use, input._reporterState.obj)._decode(input, options);
  17716. } else {
  17717. return input.error('unknown tag: ' + tag);
  17718. }
  17719. };
  17720. Node.prototype._getUse = function _getUse(entity, obj) {
  17721. const state = this._baseState;
  17722. // Create altered use decoder if implicit is set
  17723. state.useDecoder = this._use(entity, obj);
  17724. assert(state.useDecoder._baseState.parent === null);
  17725. state.useDecoder = state.useDecoder._baseState.children[0];
  17726. if (state.implicit !== state.useDecoder._baseState.implicit) {
  17727. state.useDecoder = state.useDecoder.clone();
  17728. state.useDecoder._baseState.implicit = state.implicit;
  17729. }
  17730. return state.useDecoder;
  17731. };
  17732. Node.prototype._decodeChoice = function decodeChoice(input, options) {
  17733. const state = this._baseState;
  17734. let result = null;
  17735. let match = false;
  17736. Object.keys(state.choice).some(function (key) {
  17737. const save = input.save();
  17738. const node = state.choice[key];
  17739. try {
  17740. const value = node._decode(input, options);
  17741. if (input.isError(value)) return false;
  17742. result = {
  17743. type: key,
  17744. value: value
  17745. };
  17746. match = true;
  17747. } catch (e) {
  17748. input.restore(save);
  17749. return false;
  17750. }
  17751. return true;
  17752. }, this);
  17753. if (!match) return input.error('Choice not matched');
  17754. return result;
  17755. };
  17756. //
  17757. // Encoding
  17758. //
  17759. Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
  17760. return new EncoderBuffer(data, this.reporter);
  17761. };
  17762. Node.prototype._encode = function encode(data, reporter, parent) {
  17763. const state = this._baseState;
  17764. if (state['default'] !== null && state['default'] === data) return;
  17765. const result = this._encodeValue(data, reporter, parent);
  17766. if (result === undefined) return;
  17767. if (this._skipDefault(result, reporter, parent)) return;
  17768. return result;
  17769. };
  17770. Node.prototype._encodeValue = function encode(data, reporter, parent) {
  17771. const state = this._baseState;
  17772. // Decode root node
  17773. if (state.parent === null) return state.children[0]._encode(data, reporter || new Reporter());
  17774. let result = null;
  17775. // Set reporter to share it with a child class
  17776. this.reporter = reporter;
  17777. // Check if data is there
  17778. if (state.optional && data === undefined) {
  17779. if (state['default'] !== null) data = state['default'];else return;
  17780. }
  17781. // Encode children first
  17782. let content = null;
  17783. let primitive = false;
  17784. if (state.any) {
  17785. // Anything that was given is translated to buffer
  17786. result = this._createEncoderBuffer(data);
  17787. } else if (state.choice) {
  17788. result = this._encodeChoice(data, reporter);
  17789. } else if (state.contains) {
  17790. content = this._getUse(state.contains, parent)._encode(data, reporter);
  17791. primitive = true;
  17792. } else if (state.children) {
  17793. content = state.children.map(function (child) {
  17794. if (child._baseState.tag === 'null_') return child._encode(null, reporter, data);
  17795. if (child._baseState.key === null) return reporter.error('Child should have a key');
  17796. const prevKey = reporter.enterKey(child._baseState.key);
  17797. if (typeof data !== 'object') return reporter.error('Child expected, but input is not object');
  17798. const res = child._encode(data[child._baseState.key], reporter, data);
  17799. reporter.leaveKey(prevKey);
  17800. return res;
  17801. }, this).filter(function (child) {
  17802. return child;
  17803. });
  17804. content = this._createEncoderBuffer(content);
  17805. } else {
  17806. if (state.tag === 'seqof' || state.tag === 'setof') {
  17807. // TODO(indutny): this should be thrown on DSL level
  17808. if (!(state.args && state.args.length === 1)) return reporter.error('Too many args for : ' + state.tag);
  17809. if (!Array.isArray(data)) return reporter.error('seqof/setof, but data is not Array');
  17810. const child = this.clone();
  17811. child._baseState.implicit = null;
  17812. content = this._createEncoderBuffer(data.map(function (item) {
  17813. const state = this._baseState;
  17814. return this._getUse(state.args[0], data)._encode(item, reporter);
  17815. }, child));
  17816. } else if (state.use !== null) {
  17817. result = this._getUse(state.use, parent)._encode(data, reporter);
  17818. } else {
  17819. content = this._encodePrimitive(state.tag, data);
  17820. primitive = true;
  17821. }
  17822. }
  17823. // Encode data itself
  17824. if (!state.any && state.choice === null) {
  17825. const tag = state.implicit !== null ? state.implicit : state.tag;
  17826. const cls = state.implicit === null ? 'universal' : 'context';
  17827. if (tag === null) {
  17828. if (state.use === null) reporter.error('Tag could be omitted only for .use()');
  17829. } else {
  17830. if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content);
  17831. }
  17832. }
  17833. // Wrap in explicit
  17834. if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, 'context', result);
  17835. return result;
  17836. };
  17837. Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
  17838. const state = this._baseState;
  17839. const node = state.choice[data.type];
  17840. if (!node) {
  17841. assert(false, data.type + ' not found in ' + JSON.stringify(Object.keys(state.choice)));
  17842. }
  17843. return node._encode(data.value, reporter);
  17844. };
  17845. Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
  17846. const state = this._baseState;
  17847. if (/str$/.test(tag)) return this._encodeStr(data, tag);else if (tag === 'objid' && state.args) return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);else if (tag === 'objid') return this._encodeObjid(data, null, null);else if (tag === 'gentime' || tag === 'utctime') return this._encodeTime(data, tag);else if (tag === 'null_') return this._encodeNull();else if (tag === 'int' || tag === 'enum') return this._encodeInt(data, state.args && state.reverseArgs[0]);else if (tag === 'bool') return this._encodeBool(data);else if (tag === 'objDesc') return this._encodeStr(data, tag);else throw new Error('Unsupported tag: ' + tag);
  17848. };
  17849. Node.prototype._isNumstr = function isNumstr(str) {
  17850. return /^[0-9 ]*$/.test(str);
  17851. };
  17852. Node.prototype._isPrintstr = function isPrintstr(str) {
  17853. return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str);
  17854. };
  17855. },{"../base/buffer":172,"../base/reporter":175,"minimalistic-assert":453}],175:[function(require,module,exports){
  17856. 'use strict';
  17857. const inherits = require('inherits');
  17858. function Reporter(options) {
  17859. this._reporterState = {
  17860. obj: null,
  17861. path: [],
  17862. options: options || {},
  17863. errors: []
  17864. };
  17865. }
  17866. exports.Reporter = Reporter;
  17867. Reporter.prototype.isError = function isError(obj) {
  17868. return obj instanceof ReporterError;
  17869. };
  17870. Reporter.prototype.save = function save() {
  17871. const state = this._reporterState;
  17872. return {
  17873. obj: state.obj,
  17874. pathLen: state.path.length
  17875. };
  17876. };
  17877. Reporter.prototype.restore = function restore(data) {
  17878. const state = this._reporterState;
  17879. state.obj = data.obj;
  17880. state.path = state.path.slice(0, data.pathLen);
  17881. };
  17882. Reporter.prototype.enterKey = function enterKey(key) {
  17883. return this._reporterState.path.push(key);
  17884. };
  17885. Reporter.prototype.exitKey = function exitKey(index) {
  17886. const state = this._reporterState;
  17887. state.path = state.path.slice(0, index - 1);
  17888. };
  17889. Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
  17890. const state = this._reporterState;
  17891. this.exitKey(index);
  17892. if (state.obj !== null) state.obj[key] = value;
  17893. };
  17894. Reporter.prototype.path = function path() {
  17895. return this._reporterState.path.join('/');
  17896. };
  17897. Reporter.prototype.enterObject = function enterObject() {
  17898. const state = this._reporterState;
  17899. const prev = state.obj;
  17900. state.obj = {};
  17901. return prev;
  17902. };
  17903. Reporter.prototype.leaveObject = function leaveObject(prev) {
  17904. const state = this._reporterState;
  17905. const now = state.obj;
  17906. state.obj = prev;
  17907. return now;
  17908. };
  17909. Reporter.prototype.error = function error(msg) {
  17910. let err;
  17911. const state = this._reporterState;
  17912. const inherited = msg instanceof ReporterError;
  17913. if (inherited) {
  17914. err = msg;
  17915. } else {
  17916. err = new ReporterError(state.path.map(function (elem) {
  17917. return '[' + JSON.stringify(elem) + ']';
  17918. }).join(''), msg.message || msg, msg.stack);
  17919. }
  17920. if (!state.options.partial) throw err;
  17921. if (!inherited) state.errors.push(err);
  17922. return err;
  17923. };
  17924. Reporter.prototype.wrapResult = function wrapResult(result) {
  17925. const state = this._reporterState;
  17926. if (!state.options.partial) return result;
  17927. return {
  17928. result: this.isError(result) ? null : result,
  17929. errors: state.errors
  17930. };
  17931. };
  17932. function ReporterError(path, msg) {
  17933. this.path = path;
  17934. this.rethrow(msg);
  17935. }
  17936. inherits(ReporterError, Error);
  17937. ReporterError.prototype.rethrow = function rethrow(msg) {
  17938. this.message = msg + ' at: ' + (this.path || '(shallow)');
  17939. if (Error.captureStackTrace) Error.captureStackTrace(this, ReporterError);
  17940. if (!this.stack) {
  17941. try {
  17942. // IE only adds stack when thrown
  17943. throw new Error(this.message);
  17944. } catch (e) {
  17945. this.stack = e.stack;
  17946. }
  17947. }
  17948. return this;
  17949. };
  17950. },{"inherits":440}],176:[function(require,module,exports){
  17951. 'use strict';
  17952. // Helper
  17953. function reverse(map) {
  17954. const res = {};
  17955. Object.keys(map).forEach(function (key) {
  17956. // Convert key to integer if it is stringified
  17957. if ((key | 0) == key) key = key | 0;
  17958. const value = map[key];
  17959. res[value] = key;
  17960. });
  17961. return res;
  17962. }
  17963. exports.tagClass = {
  17964. 0: 'universal',
  17965. 1: 'application',
  17966. 2: 'context',
  17967. 3: 'private'
  17968. };
  17969. exports.tagClassByName = reverse(exports.tagClass);
  17970. exports.tag = {
  17971. 0x00: 'end',
  17972. 0x01: 'bool',
  17973. 0x02: 'int',
  17974. 0x03: 'bitstr',
  17975. 0x04: 'octstr',
  17976. 0x05: 'null_',
  17977. 0x06: 'objid',
  17978. 0x07: 'objDesc',
  17979. 0x08: 'external',
  17980. 0x09: 'real',
  17981. 0x0a: 'enum',
  17982. 0x0b: 'embed',
  17983. 0x0c: 'utf8str',
  17984. 0x0d: 'relativeOid',
  17985. 0x10: 'seq',
  17986. 0x11: 'set',
  17987. 0x12: 'numstr',
  17988. 0x13: 'printstr',
  17989. 0x14: 't61str',
  17990. 0x15: 'videostr',
  17991. 0x16: 'ia5str',
  17992. 0x17: 'utctime',
  17993. 0x18: 'gentime',
  17994. 0x19: 'graphstr',
  17995. 0x1a: 'iso646str',
  17996. 0x1b: 'genstr',
  17997. 0x1c: 'unistr',
  17998. 0x1d: 'charstr',
  17999. 0x1e: 'bmpstr'
  18000. };
  18001. exports.tagByName = reverse(exports.tag);
  18002. },{}],177:[function(require,module,exports){
  18003. 'use strict';
  18004. const constants = exports;
  18005. // Helper
  18006. constants._reverse = function reverse(map) {
  18007. const res = {};
  18008. Object.keys(map).forEach(function (key) {
  18009. // Convert key to integer if it is stringified
  18010. if ((key | 0) == key) key = key | 0;
  18011. const value = map[key];
  18012. res[value] = key;
  18013. });
  18014. return res;
  18015. };
  18016. constants.der = require('./der');
  18017. },{"./der":176}],178:[function(require,module,exports){
  18018. 'use strict';
  18019. const inherits = require('inherits');
  18020. const bignum = require('bn.js');
  18021. const DecoderBuffer = require('../base/buffer').DecoderBuffer;
  18022. const Node = require('../base/node');
  18023. // Import DER constants
  18024. const der = require('../constants/der');
  18025. function DERDecoder(entity) {
  18026. this.enc = 'der';
  18027. this.name = entity.name;
  18028. this.entity = entity;
  18029. // Construct base tree
  18030. this.tree = new DERNode();
  18031. this.tree._init(entity.body);
  18032. }
  18033. module.exports = DERDecoder;
  18034. DERDecoder.prototype.decode = function decode(data, options) {
  18035. if (!DecoderBuffer.isDecoderBuffer(data)) {
  18036. data = new DecoderBuffer(data, options);
  18037. }
  18038. return this.tree._decode(data, options);
  18039. };
  18040. // Tree methods
  18041. function DERNode(parent) {
  18042. Node.call(this, 'der', parent);
  18043. }
  18044. inherits(DERNode, Node);
  18045. DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
  18046. if (buffer.isEmpty()) return false;
  18047. const state = buffer.save();
  18048. const decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
  18049. if (buffer.isError(decodedTag)) return decodedTag;
  18050. buffer.restore(state);
  18051. return decodedTag.tag === tag || decodedTag.tagStr === tag || decodedTag.tagStr + 'of' === tag || any;
  18052. };
  18053. DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
  18054. const decodedTag = derDecodeTag(buffer, 'Failed to decode tag of "' + tag + '"');
  18055. if (buffer.isError(decodedTag)) return decodedTag;
  18056. let len = derDecodeLen(buffer, decodedTag.primitive, 'Failed to get length of "' + tag + '"');
  18057. // Failure
  18058. if (buffer.isError(len)) return len;
  18059. if (!any && decodedTag.tag !== tag && decodedTag.tagStr !== tag && decodedTag.tagStr + 'of' !== tag) {
  18060. return buffer.error('Failed to match tag: "' + tag + '"');
  18061. }
  18062. if (decodedTag.primitive || len !== null) return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  18063. // Indefinite length... find END tag
  18064. const state = buffer.save();
  18065. const res = this._skipUntilEnd(buffer, 'Failed to skip indefinite length body: "' + this.tag + '"');
  18066. if (buffer.isError(res)) return res;
  18067. len = buffer.offset - state.offset;
  18068. buffer.restore(state);
  18069. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  18070. };
  18071. DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
  18072. for (;;) {
  18073. const tag = derDecodeTag(buffer, fail);
  18074. if (buffer.isError(tag)) return tag;
  18075. const len = derDecodeLen(buffer, tag.primitive, fail);
  18076. if (buffer.isError(len)) return len;
  18077. let res;
  18078. if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail);
  18079. // Failure
  18080. if (buffer.isError(res)) return res;
  18081. if (tag.tagStr === 'end') break;
  18082. }
  18083. };
  18084. DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, options) {
  18085. const result = [];
  18086. while (!buffer.isEmpty()) {
  18087. const possibleEnd = this._peekTag(buffer, 'end');
  18088. if (buffer.isError(possibleEnd)) return possibleEnd;
  18089. const res = decoder.decode(buffer, 'der', options);
  18090. if (buffer.isError(res) && possibleEnd) break;
  18091. result.push(res);
  18092. }
  18093. return result;
  18094. };
  18095. DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
  18096. if (tag === 'bitstr') {
  18097. const unused = buffer.readUInt8();
  18098. if (buffer.isError(unused)) return unused;
  18099. return {
  18100. unused: unused,
  18101. data: buffer.raw()
  18102. };
  18103. } else if (tag === 'bmpstr') {
  18104. const raw = buffer.raw();
  18105. if (raw.length % 2 === 1) return buffer.error('Decoding of string type: bmpstr length mismatch');
  18106. let str = '';
  18107. for (let i = 0; i < raw.length / 2; i++) {
  18108. str += String.fromCharCode(raw.readUInt16BE(i * 2));
  18109. }
  18110. return str;
  18111. } else if (tag === 'numstr') {
  18112. const numstr = buffer.raw().toString('ascii');
  18113. if (!this._isNumstr(numstr)) {
  18114. return buffer.error('Decoding of string type: ' + 'numstr unsupported characters');
  18115. }
  18116. return numstr;
  18117. } else if (tag === 'octstr') {
  18118. return buffer.raw();
  18119. } else if (tag === 'objDesc') {
  18120. return buffer.raw();
  18121. } else if (tag === 'printstr') {
  18122. const printstr = buffer.raw().toString('ascii');
  18123. if (!this._isPrintstr(printstr)) {
  18124. return buffer.error('Decoding of string type: ' + 'printstr unsupported characters');
  18125. }
  18126. return printstr;
  18127. } else if (/str$/.test(tag)) {
  18128. return buffer.raw().toString();
  18129. } else {
  18130. return buffer.error('Decoding of string type: ' + tag + ' unsupported');
  18131. }
  18132. };
  18133. DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
  18134. let result;
  18135. const identifiers = [];
  18136. let ident = 0;
  18137. let subident = 0;
  18138. while (!buffer.isEmpty()) {
  18139. subident = buffer.readUInt8();
  18140. ident <<= 7;
  18141. ident |= subident & 0x7f;
  18142. if ((subident & 0x80) === 0) {
  18143. identifiers.push(ident);
  18144. ident = 0;
  18145. }
  18146. }
  18147. if (subident & 0x80) identifiers.push(ident);
  18148. const first = identifiers[0] / 40 | 0;
  18149. const second = identifiers[0] % 40;
  18150. if (relative) result = identifiers;else result = [first, second].concat(identifiers.slice(1));
  18151. if (values) {
  18152. let tmp = values[result.join(' ')];
  18153. if (tmp === undefined) tmp = values[result.join('.')];
  18154. if (tmp !== undefined) result = tmp;
  18155. }
  18156. return result;
  18157. };
  18158. DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
  18159. const str = buffer.raw().toString();
  18160. let year;
  18161. let mon;
  18162. let day;
  18163. let hour;
  18164. let min;
  18165. let sec;
  18166. if (tag === 'gentime') {
  18167. year = str.slice(0, 4) | 0;
  18168. mon = str.slice(4, 6) | 0;
  18169. day = str.slice(6, 8) | 0;
  18170. hour = str.slice(8, 10) | 0;
  18171. min = str.slice(10, 12) | 0;
  18172. sec = str.slice(12, 14) | 0;
  18173. } else if (tag === 'utctime') {
  18174. year = str.slice(0, 2) | 0;
  18175. mon = str.slice(2, 4) | 0;
  18176. day = str.slice(4, 6) | 0;
  18177. hour = str.slice(6, 8) | 0;
  18178. min = str.slice(8, 10) | 0;
  18179. sec = str.slice(10, 12) | 0;
  18180. if (year < 70) year = 2000 + year;else year = 1900 + year;
  18181. } else {
  18182. return buffer.error('Decoding ' + tag + ' time is not supported yet');
  18183. }
  18184. return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
  18185. };
  18186. DERNode.prototype._decodeNull = function decodeNull() {
  18187. return null;
  18188. };
  18189. DERNode.prototype._decodeBool = function decodeBool(buffer) {
  18190. const res = buffer.readUInt8();
  18191. if (buffer.isError(res)) return res;else return res !== 0;
  18192. };
  18193. DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
  18194. // Bigint, return as it is (assume big endian)
  18195. const raw = buffer.raw();
  18196. let res = new bignum(raw);
  18197. if (values) res = values[res.toString(10)] || res;
  18198. return res;
  18199. };
  18200. DERNode.prototype._use = function use(entity, obj) {
  18201. if (typeof entity === 'function') entity = entity(obj);
  18202. return entity._getDecoder('der').tree;
  18203. };
  18204. // Utility methods
  18205. function derDecodeTag(buf, fail) {
  18206. let tag = buf.readUInt8(fail);
  18207. if (buf.isError(tag)) return tag;
  18208. const cls = der.tagClass[tag >> 6];
  18209. const primitive = (tag & 0x20) === 0;
  18210. // Multi-octet tag - load
  18211. if ((tag & 0x1f) === 0x1f) {
  18212. let oct = tag;
  18213. tag = 0;
  18214. while ((oct & 0x80) === 0x80) {
  18215. oct = buf.readUInt8(fail);
  18216. if (buf.isError(oct)) return oct;
  18217. tag <<= 7;
  18218. tag |= oct & 0x7f;
  18219. }
  18220. } else {
  18221. tag &= 0x1f;
  18222. }
  18223. const tagStr = der.tag[tag];
  18224. return {
  18225. cls: cls,
  18226. primitive: primitive,
  18227. tag: tag,
  18228. tagStr: tagStr
  18229. };
  18230. }
  18231. function derDecodeLen(buf, primitive, fail) {
  18232. let len = buf.readUInt8(fail);
  18233. if (buf.isError(len)) return len;
  18234. // Indefinite form
  18235. if (!primitive && len === 0x80) return null;
  18236. // Definite form
  18237. if ((len & 0x80) === 0) {
  18238. // Short form
  18239. return len;
  18240. }
  18241. // Long form
  18242. const num = len & 0x7f;
  18243. if (num > 4) return buf.error('length octect is too long');
  18244. len = 0;
  18245. for (let i = 0; i < num; i++) {
  18246. len <<= 8;
  18247. const j = buf.readUInt8(fail);
  18248. if (buf.isError(j)) return j;
  18249. len |= j;
  18250. }
  18251. return len;
  18252. }
  18253. },{"../base/buffer":172,"../base/node":174,"../constants/der":176,"bn.js":184,"inherits":440}],179:[function(require,module,exports){
  18254. 'use strict';
  18255. const decoders = exports;
  18256. decoders.der = require('./der');
  18257. decoders.pem = require('./pem');
  18258. },{"./der":178,"./pem":180}],180:[function(require,module,exports){
  18259. 'use strict';
  18260. const inherits = require('inherits');
  18261. const Buffer = require('safer-buffer').Buffer;
  18262. const DERDecoder = require('./der');
  18263. function PEMDecoder(entity) {
  18264. DERDecoder.call(this, entity);
  18265. this.enc = 'pem';
  18266. }
  18267. inherits(PEMDecoder, DERDecoder);
  18268. module.exports = PEMDecoder;
  18269. PEMDecoder.prototype.decode = function decode(data, options) {
  18270. const lines = data.toString().split(/[\r\n]+/g);
  18271. const label = options.label.toUpperCase();
  18272. const re = /^-----(BEGIN|END) ([^-]+)-----$/;
  18273. let start = -1;
  18274. let end = -1;
  18275. for (let i = 0; i < lines.length; i++) {
  18276. const match = lines[i].match(re);
  18277. if (match === null) continue;
  18278. if (match[2] !== label) continue;
  18279. if (start === -1) {
  18280. if (match[1] !== 'BEGIN') break;
  18281. start = i;
  18282. } else {
  18283. if (match[1] !== 'END') break;
  18284. end = i;
  18285. break;
  18286. }
  18287. }
  18288. if (start === -1 || end === -1) throw new Error('PEM section not found for: ' + label);
  18289. const base64 = lines.slice(start + 1, end).join('');
  18290. // Remove excessive symbols
  18291. base64.replace(/[^a-z0-9+/=]+/gi, '');
  18292. const input = Buffer.from(base64, 'base64');
  18293. return DERDecoder.prototype.decode.call(this, input, options);
  18294. };
  18295. },{"./der":178,"inherits":440,"safer-buffer":495}],181:[function(require,module,exports){
  18296. 'use strict';
  18297. const inherits = require('inherits');
  18298. const Buffer = require('safer-buffer').Buffer;
  18299. const Node = require('../base/node');
  18300. // Import DER constants
  18301. const der = require('../constants/der');
  18302. function DEREncoder(entity) {
  18303. this.enc = 'der';
  18304. this.name = entity.name;
  18305. this.entity = entity;
  18306. // Construct base tree
  18307. this.tree = new DERNode();
  18308. this.tree._init(entity.body);
  18309. }
  18310. module.exports = DEREncoder;
  18311. DEREncoder.prototype.encode = function encode(data, reporter) {
  18312. return this.tree._encode(data, reporter).join();
  18313. };
  18314. // Tree methods
  18315. function DERNode(parent) {
  18316. Node.call(this, 'der', parent);
  18317. }
  18318. inherits(DERNode, Node);
  18319. DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) {
  18320. const encodedTag = encodeTag(tag, primitive, cls, this.reporter);
  18321. // Short form
  18322. if (content.length < 0x80) {
  18323. const header = Buffer.alloc(2);
  18324. header[0] = encodedTag;
  18325. header[1] = content.length;
  18326. return this._createEncoderBuffer([header, content]);
  18327. }
  18328. // Long form
  18329. // Count octets required to store length
  18330. let lenOctets = 1;
  18331. for (let i = content.length; i >= 0x100; i >>= 8) lenOctets++;
  18332. const header = Buffer.alloc(1 + 1 + lenOctets);
  18333. header[0] = encodedTag;
  18334. header[1] = 0x80 | lenOctets;
  18335. for (let i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8) header[i] = j & 0xff;
  18336. return this._createEncoderBuffer([header, content]);
  18337. };
  18338. DERNode.prototype._encodeStr = function encodeStr(str, tag) {
  18339. if (tag === 'bitstr') {
  18340. return this._createEncoderBuffer([str.unused | 0, str.data]);
  18341. } else if (tag === 'bmpstr') {
  18342. const buf = Buffer.alloc(str.length * 2);
  18343. for (let i = 0; i < str.length; i++) {
  18344. buf.writeUInt16BE(str.charCodeAt(i), i * 2);
  18345. }
  18346. return this._createEncoderBuffer(buf);
  18347. } else if (tag === 'numstr') {
  18348. if (!this._isNumstr(str)) {
  18349. return this.reporter.error('Encoding of string type: numstr supports ' + 'only digits and space');
  18350. }
  18351. return this._createEncoderBuffer(str);
  18352. } else if (tag === 'printstr') {
  18353. if (!this._isPrintstr(str)) {
  18354. return this.reporter.error('Encoding of string type: printstr supports ' + 'only latin upper and lower case letters, ' + 'digits, space, apostrophe, left and rigth ' + 'parenthesis, plus sign, comma, hyphen, ' + 'dot, slash, colon, equal sign, ' + 'question mark');
  18355. }
  18356. return this._createEncoderBuffer(str);
  18357. } else if (/str$/.test(tag)) {
  18358. return this._createEncoderBuffer(str);
  18359. } else if (tag === 'objDesc') {
  18360. return this._createEncoderBuffer(str);
  18361. } else {
  18362. return this.reporter.error('Encoding of string type: ' + tag + ' unsupported');
  18363. }
  18364. };
  18365. DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
  18366. if (typeof id === 'string') {
  18367. if (!values) return this.reporter.error('string objid given, but no values map found');
  18368. if (!values.hasOwnProperty(id)) return this.reporter.error('objid not found in values map');
  18369. id = values[id].split(/[\s.]+/g);
  18370. for (let i = 0; i < id.length; i++) id[i] |= 0;
  18371. } else if (Array.isArray(id)) {
  18372. id = id.slice();
  18373. for (let i = 0; i < id.length; i++) id[i] |= 0;
  18374. }
  18375. if (!Array.isArray(id)) {
  18376. return this.reporter.error('objid() should be either array or string, ' + 'got: ' + JSON.stringify(id));
  18377. }
  18378. if (!relative) {
  18379. if (id[1] >= 40) return this.reporter.error('Second objid identifier OOB');
  18380. id.splice(0, 2, id[0] * 40 + id[1]);
  18381. }
  18382. // Count number of octets
  18383. let size = 0;
  18384. for (let i = 0; i < id.length; i++) {
  18385. let ident = id[i];
  18386. for (size++; ident >= 0x80; ident >>= 7) size++;
  18387. }
  18388. const objid = Buffer.alloc(size);
  18389. let offset = objid.length - 1;
  18390. for (let i = id.length - 1; i >= 0; i--) {
  18391. let ident = id[i];
  18392. objid[offset--] = ident & 0x7f;
  18393. while ((ident >>= 7) > 0) objid[offset--] = 0x80 | ident & 0x7f;
  18394. }
  18395. return this._createEncoderBuffer(objid);
  18396. };
  18397. function two(num) {
  18398. if (num < 10) return '0' + num;else return num;
  18399. }
  18400. DERNode.prototype._encodeTime = function encodeTime(time, tag) {
  18401. let str;
  18402. const date = new Date(time);
  18403. if (tag === 'gentime') {
  18404. str = [two(date.getUTCFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  18405. } else if (tag === 'utctime') {
  18406. str = [two(date.getUTCFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  18407. } else {
  18408. this.reporter.error('Encoding ' + tag + ' time is not supported yet');
  18409. }
  18410. return this._encodeStr(str, 'octstr');
  18411. };
  18412. DERNode.prototype._encodeNull = function encodeNull() {
  18413. return this._createEncoderBuffer('');
  18414. };
  18415. DERNode.prototype._encodeInt = function encodeInt(num, values) {
  18416. if (typeof num === 'string') {
  18417. if (!values) return this.reporter.error('String int or enum given, but no values map');
  18418. if (!values.hasOwnProperty(num)) {
  18419. return this.reporter.error('Values map doesn\'t contain: ' + JSON.stringify(num));
  18420. }
  18421. num = values[num];
  18422. }
  18423. // Bignum, assume big endian
  18424. if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
  18425. const numArray = num.toArray();
  18426. if (!num.sign && numArray[0] & 0x80) {
  18427. numArray.unshift(0);
  18428. }
  18429. num = Buffer.from(numArray);
  18430. }
  18431. if (Buffer.isBuffer(num)) {
  18432. let size = num.length;
  18433. if (num.length === 0) size++;
  18434. const out = Buffer.alloc(size);
  18435. num.copy(out);
  18436. if (num.length === 0) out[0] = 0;
  18437. return this._createEncoderBuffer(out);
  18438. }
  18439. if (num < 0x80) return this._createEncoderBuffer(num);
  18440. if (num < 0x100) return this._createEncoderBuffer([0, num]);
  18441. let size = 1;
  18442. for (let i = num; i >= 0x100; i >>= 8) size++;
  18443. const out = new Array(size);
  18444. for (let i = out.length - 1; i >= 0; i--) {
  18445. out[i] = num & 0xff;
  18446. num >>= 8;
  18447. }
  18448. if (out[0] & 0x80) {
  18449. out.unshift(0);
  18450. }
  18451. return this._createEncoderBuffer(Buffer.from(out));
  18452. };
  18453. DERNode.prototype._encodeBool = function encodeBool(value) {
  18454. return this._createEncoderBuffer(value ? 0xff : 0);
  18455. };
  18456. DERNode.prototype._use = function use(entity, obj) {
  18457. if (typeof entity === 'function') entity = entity(obj);
  18458. return entity._getEncoder('der').tree;
  18459. };
  18460. DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
  18461. const state = this._baseState;
  18462. let i;
  18463. if (state['default'] === null) return false;
  18464. const data = dataBuffer.join();
  18465. if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
  18466. if (data.length !== state.defaultBuffer.length) return false;
  18467. for (i = 0; i < data.length; i++) if (data[i] !== state.defaultBuffer[i]) return false;
  18468. return true;
  18469. };
  18470. // Utility methods
  18471. function encodeTag(tag, primitive, cls, reporter) {
  18472. let res;
  18473. if (tag === 'seqof') tag = 'seq';else if (tag === 'setof') tag = 'set';
  18474. if (der.tagByName.hasOwnProperty(tag)) res = der.tagByName[tag];else if (typeof tag === 'number' && (tag | 0) === tag) res = tag;else return reporter.error('Unknown tag: ' + tag);
  18475. if (res >= 0x1f) return reporter.error('Multi-octet tag encoding unsupported');
  18476. if (!primitive) res |= 0x20;
  18477. res |= der.tagClassByName[cls || 'universal'] << 6;
  18478. return res;
  18479. }
  18480. },{"../base/node":174,"../constants/der":176,"inherits":440,"safer-buffer":495}],182:[function(require,module,exports){
  18481. 'use strict';
  18482. const encoders = exports;
  18483. encoders.der = require('./der');
  18484. encoders.pem = require('./pem');
  18485. },{"./der":181,"./pem":183}],183:[function(require,module,exports){
  18486. 'use strict';
  18487. const inherits = require('inherits');
  18488. const DEREncoder = require('./der');
  18489. function PEMEncoder(entity) {
  18490. DEREncoder.call(this, entity);
  18491. this.enc = 'pem';
  18492. }
  18493. inherits(PEMEncoder, DEREncoder);
  18494. module.exports = PEMEncoder;
  18495. PEMEncoder.prototype.encode = function encode(data, options) {
  18496. const buf = DEREncoder.prototype.encode.call(this, data);
  18497. const p = buf.toString('base64');
  18498. const out = ['-----BEGIN ' + options.label + '-----'];
  18499. for (let i = 0; i < p.length; i += 64) out.push(p.slice(i, i + 64));
  18500. out.push('-----END ' + options.label + '-----');
  18501. return out.join('\n');
  18502. };
  18503. },{"./der":181,"inherits":440}],184:[function(require,module,exports){
  18504. "use strict";
  18505. (function (module, exports) {
  18506. 'use strict';
  18507. // Utils
  18508. function assert(val, msg) {
  18509. if (!val) throw new Error(msg || 'Assertion failed');
  18510. }
  18511. // Could use `inherits` module, but don't want to move from single file
  18512. // architecture yet.
  18513. function inherits(ctor, superCtor) {
  18514. ctor.super_ = superCtor;
  18515. var TempCtor = function () {};
  18516. TempCtor.prototype = superCtor.prototype;
  18517. ctor.prototype = new TempCtor();
  18518. ctor.prototype.constructor = ctor;
  18519. }
  18520. // BN
  18521. function BN(number, base, endian) {
  18522. if (BN.isBN(number)) {
  18523. return number;
  18524. }
  18525. this.negative = 0;
  18526. this.words = null;
  18527. this.length = 0;
  18528. // Reduction context
  18529. this.red = null;
  18530. if (number !== null) {
  18531. if (base === 'le' || base === 'be') {
  18532. endian = base;
  18533. base = 10;
  18534. }
  18535. this._init(number || 0, base || 10, endian || 'be');
  18536. }
  18537. }
  18538. if (typeof module === 'object') {
  18539. module.exports = BN;
  18540. } else {
  18541. exports.BN = BN;
  18542. }
  18543. BN.BN = BN;
  18544. BN.wordSize = 26;
  18545. var Buffer;
  18546. try {
  18547. if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
  18548. Buffer = window.Buffer;
  18549. } else {
  18550. Buffer = require('buffer').Buffer;
  18551. }
  18552. } catch (e) {}
  18553. BN.isBN = function isBN(num) {
  18554. if (num instanceof BN) {
  18555. return true;
  18556. }
  18557. return num !== null && typeof num === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  18558. };
  18559. BN.max = function max(left, right) {
  18560. if (left.cmp(right) > 0) return left;
  18561. return right;
  18562. };
  18563. BN.min = function min(left, right) {
  18564. if (left.cmp(right) < 0) return left;
  18565. return right;
  18566. };
  18567. BN.prototype._init = function init(number, base, endian) {
  18568. if (typeof number === 'number') {
  18569. return this._initNumber(number, base, endian);
  18570. }
  18571. if (typeof number === 'object') {
  18572. return this._initArray(number, base, endian);
  18573. }
  18574. if (base === 'hex') {
  18575. base = 16;
  18576. }
  18577. assert(base === (base | 0) && base >= 2 && base <= 36);
  18578. number = number.toString().replace(/\s+/g, '');
  18579. var start = 0;
  18580. if (number[0] === '-') {
  18581. start++;
  18582. this.negative = 1;
  18583. }
  18584. if (start < number.length) {
  18585. if (base === 16) {
  18586. this._parseHex(number, start, endian);
  18587. } else {
  18588. this._parseBase(number, base, start);
  18589. if (endian === 'le') {
  18590. this._initArray(this.toArray(), base, endian);
  18591. }
  18592. }
  18593. }
  18594. };
  18595. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  18596. if (number < 0) {
  18597. this.negative = 1;
  18598. number = -number;
  18599. }
  18600. if (number < 0x4000000) {
  18601. this.words = [number & 0x3ffffff];
  18602. this.length = 1;
  18603. } else if (number < 0x10000000000000) {
  18604. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  18605. this.length = 2;
  18606. } else {
  18607. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  18608. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  18609. this.length = 3;
  18610. }
  18611. if (endian !== 'le') return;
  18612. // Reverse the bytes
  18613. this._initArray(this.toArray(), base, endian);
  18614. };
  18615. BN.prototype._initArray = function _initArray(number, base, endian) {
  18616. // Perhaps a Uint8Array
  18617. assert(typeof number.length === 'number');
  18618. if (number.length <= 0) {
  18619. this.words = [0];
  18620. this.length = 1;
  18621. return this;
  18622. }
  18623. this.length = Math.ceil(number.length / 3);
  18624. this.words = new Array(this.length);
  18625. for (var i = 0; i < this.length; i++) {
  18626. this.words[i] = 0;
  18627. }
  18628. var j, w;
  18629. var off = 0;
  18630. if (endian === 'be') {
  18631. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  18632. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  18633. this.words[j] |= w << off & 0x3ffffff;
  18634. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  18635. off += 24;
  18636. if (off >= 26) {
  18637. off -= 26;
  18638. j++;
  18639. }
  18640. }
  18641. } else if (endian === 'le') {
  18642. for (i = 0, j = 0; i < number.length; i += 3) {
  18643. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  18644. this.words[j] |= w << off & 0x3ffffff;
  18645. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  18646. off += 24;
  18647. if (off >= 26) {
  18648. off -= 26;
  18649. j++;
  18650. }
  18651. }
  18652. }
  18653. return this.strip();
  18654. };
  18655. function parseHex4Bits(string, index) {
  18656. var c = string.charCodeAt(index);
  18657. // 'A' - 'F'
  18658. if (c >= 65 && c <= 70) {
  18659. return c - 55;
  18660. // 'a' - 'f'
  18661. } else if (c >= 97 && c <= 102) {
  18662. return c - 87;
  18663. // '0' - '9'
  18664. } else {
  18665. return c - 48 & 0xf;
  18666. }
  18667. }
  18668. function parseHexByte(string, lowerBound, index) {
  18669. var r = parseHex4Bits(string, index);
  18670. if (index - 1 >= lowerBound) {
  18671. r |= parseHex4Bits(string, index - 1) << 4;
  18672. }
  18673. return r;
  18674. }
  18675. BN.prototype._parseHex = function _parseHex(number, start, endian) {
  18676. // Create possibly bigger array to ensure that it fits the number
  18677. this.length = Math.ceil((number.length - start) / 6);
  18678. this.words = new Array(this.length);
  18679. for (var i = 0; i < this.length; i++) {
  18680. this.words[i] = 0;
  18681. }
  18682. // 24-bits chunks
  18683. var off = 0;
  18684. var j = 0;
  18685. var w;
  18686. if (endian === 'be') {
  18687. for (i = number.length - 1; i >= start; i -= 2) {
  18688. w = parseHexByte(number, start, i) << off;
  18689. this.words[j] |= w & 0x3ffffff;
  18690. if (off >= 18) {
  18691. off -= 18;
  18692. j += 1;
  18693. this.words[j] |= w >>> 26;
  18694. } else {
  18695. off += 8;
  18696. }
  18697. }
  18698. } else {
  18699. var parseLength = number.length - start;
  18700. for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
  18701. w = parseHexByte(number, start, i) << off;
  18702. this.words[j] |= w & 0x3ffffff;
  18703. if (off >= 18) {
  18704. off -= 18;
  18705. j += 1;
  18706. this.words[j] |= w >>> 26;
  18707. } else {
  18708. off += 8;
  18709. }
  18710. }
  18711. }
  18712. this.strip();
  18713. };
  18714. function parseBase(str, start, end, mul) {
  18715. var r = 0;
  18716. var len = Math.min(str.length, end);
  18717. for (var i = start; i < len; i++) {
  18718. var c = str.charCodeAt(i) - 48;
  18719. r *= mul;
  18720. // 'a'
  18721. if (c >= 49) {
  18722. r += c - 49 + 0xa;
  18723. // 'A'
  18724. } else if (c >= 17) {
  18725. r += c - 17 + 0xa;
  18726. // '0' - '9'
  18727. } else {
  18728. r += c;
  18729. }
  18730. }
  18731. return r;
  18732. }
  18733. BN.prototype._parseBase = function _parseBase(number, base, start) {
  18734. // Initialize as zero
  18735. this.words = [0];
  18736. this.length = 1;
  18737. // Find length of limb in base
  18738. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  18739. limbLen++;
  18740. }
  18741. limbLen--;
  18742. limbPow = limbPow / base | 0;
  18743. var total = number.length - start;
  18744. var mod = total % limbLen;
  18745. var end = Math.min(total, total - mod) + start;
  18746. var word = 0;
  18747. for (var i = start; i < end; i += limbLen) {
  18748. word = parseBase(number, i, i + limbLen, base);
  18749. this.imuln(limbPow);
  18750. if (this.words[0] + word < 0x4000000) {
  18751. this.words[0] += word;
  18752. } else {
  18753. this._iaddn(word);
  18754. }
  18755. }
  18756. if (mod !== 0) {
  18757. var pow = 1;
  18758. word = parseBase(number, i, number.length, base);
  18759. for (i = 0; i < mod; i++) {
  18760. pow *= base;
  18761. }
  18762. this.imuln(pow);
  18763. if (this.words[0] + word < 0x4000000) {
  18764. this.words[0] += word;
  18765. } else {
  18766. this._iaddn(word);
  18767. }
  18768. }
  18769. this.strip();
  18770. };
  18771. BN.prototype.copy = function copy(dest) {
  18772. dest.words = new Array(this.length);
  18773. for (var i = 0; i < this.length; i++) {
  18774. dest.words[i] = this.words[i];
  18775. }
  18776. dest.length = this.length;
  18777. dest.negative = this.negative;
  18778. dest.red = this.red;
  18779. };
  18780. BN.prototype.clone = function clone() {
  18781. var r = new BN(null);
  18782. this.copy(r);
  18783. return r;
  18784. };
  18785. BN.prototype._expand = function _expand(size) {
  18786. while (this.length < size) {
  18787. this.words[this.length++] = 0;
  18788. }
  18789. return this;
  18790. };
  18791. // Remove leading `0` from `this`
  18792. BN.prototype.strip = function strip() {
  18793. while (this.length > 1 && this.words[this.length - 1] === 0) {
  18794. this.length--;
  18795. }
  18796. return this._normSign();
  18797. };
  18798. BN.prototype._normSign = function _normSign() {
  18799. // -0 = 0
  18800. if (this.length === 1 && this.words[0] === 0) {
  18801. this.negative = 0;
  18802. }
  18803. return this;
  18804. };
  18805. BN.prototype.inspect = function inspect() {
  18806. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  18807. };
  18808. /*
  18809. var zeros = [];
  18810. var groupSizes = [];
  18811. var groupBases = [];
  18812. var s = '';
  18813. var i = -1;
  18814. while (++i < BN.wordSize) {
  18815. zeros[i] = s;
  18816. s += '0';
  18817. }
  18818. groupSizes[0] = 0;
  18819. groupSizes[1] = 0;
  18820. groupBases[0] = 0;
  18821. groupBases[1] = 0;
  18822. var base = 2 - 1;
  18823. while (++base < 36 + 1) {
  18824. var groupSize = 0;
  18825. var groupBase = 1;
  18826. while (groupBase < (1 << BN.wordSize) / base) {
  18827. groupBase *= base;
  18828. groupSize += 1;
  18829. }
  18830. groupSizes[base] = groupSize;
  18831. groupBases[base] = groupBase;
  18832. }
  18833. */
  18834. var zeros = ['', '0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '000000000', '0000000000', '00000000000', '000000000000', '0000000000000', '00000000000000', '000000000000000', '0000000000000000', '00000000000000000', '000000000000000000', '0000000000000000000', '00000000000000000000', '000000000000000000000', '0000000000000000000000', '00000000000000000000000', '000000000000000000000000', '0000000000000000000000000'];
  18835. var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];
  18836. var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176];
  18837. BN.prototype.toString = function toString(base, padding) {
  18838. base = base || 10;
  18839. padding = padding | 0 || 1;
  18840. var out;
  18841. if (base === 16 || base === 'hex') {
  18842. out = '';
  18843. var off = 0;
  18844. var carry = 0;
  18845. for (var i = 0; i < this.length; i++) {
  18846. var w = this.words[i];
  18847. var word = ((w << off | carry) & 0xffffff).toString(16);
  18848. carry = w >>> 24 - off & 0xffffff;
  18849. if (carry !== 0 || i !== this.length - 1) {
  18850. out = zeros[6 - word.length] + word + out;
  18851. } else {
  18852. out = word + out;
  18853. }
  18854. off += 2;
  18855. if (off >= 26) {
  18856. off -= 26;
  18857. i--;
  18858. }
  18859. }
  18860. if (carry !== 0) {
  18861. out = carry.toString(16) + out;
  18862. }
  18863. while (out.length % padding !== 0) {
  18864. out = '0' + out;
  18865. }
  18866. if (this.negative !== 0) {
  18867. out = '-' + out;
  18868. }
  18869. return out;
  18870. }
  18871. if (base === (base | 0) && base >= 2 && base <= 36) {
  18872. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  18873. var groupSize = groupSizes[base];
  18874. // var groupBase = Math.pow(base, groupSize);
  18875. var groupBase = groupBases[base];
  18876. out = '';
  18877. var c = this.clone();
  18878. c.negative = 0;
  18879. while (!c.isZero()) {
  18880. var r = c.modn(groupBase).toString(base);
  18881. c = c.idivn(groupBase);
  18882. if (!c.isZero()) {
  18883. out = zeros[groupSize - r.length] + r + out;
  18884. } else {
  18885. out = r + out;
  18886. }
  18887. }
  18888. if (this.isZero()) {
  18889. out = '0' + out;
  18890. }
  18891. while (out.length % padding !== 0) {
  18892. out = '0' + out;
  18893. }
  18894. if (this.negative !== 0) {
  18895. out = '-' + out;
  18896. }
  18897. return out;
  18898. }
  18899. assert(false, 'Base should be between 2 and 36');
  18900. };
  18901. BN.prototype.toNumber = function toNumber() {
  18902. var ret = this.words[0];
  18903. if (this.length === 2) {
  18904. ret += this.words[1] * 0x4000000;
  18905. } else if (this.length === 3 && this.words[2] === 0x01) {
  18906. // NOTE: at this stage it is known that the top bit is set
  18907. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  18908. } else if (this.length > 2) {
  18909. assert(false, 'Number can only safely store up to 53 bits');
  18910. }
  18911. return this.negative !== 0 ? -ret : ret;
  18912. };
  18913. BN.prototype.toJSON = function toJSON() {
  18914. return this.toString(16);
  18915. };
  18916. BN.prototype.toBuffer = function toBuffer(endian, length) {
  18917. assert(typeof Buffer !== 'undefined');
  18918. return this.toArrayLike(Buffer, endian, length);
  18919. };
  18920. BN.prototype.toArray = function toArray(endian, length) {
  18921. return this.toArrayLike(Array, endian, length);
  18922. };
  18923. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  18924. var byteLength = this.byteLength();
  18925. var reqLength = length || Math.max(1, byteLength);
  18926. assert(byteLength <= reqLength, 'byte array longer than desired length');
  18927. assert(reqLength > 0, 'Requested array length <= 0');
  18928. this.strip();
  18929. var littleEndian = endian === 'le';
  18930. var res = new ArrayType(reqLength);
  18931. var b, i;
  18932. var q = this.clone();
  18933. if (!littleEndian) {
  18934. // Assume big-endian
  18935. for (i = 0; i < reqLength - byteLength; i++) {
  18936. res[i] = 0;
  18937. }
  18938. for (i = 0; !q.isZero(); i++) {
  18939. b = q.andln(0xff);
  18940. q.iushrn(8);
  18941. res[reqLength - i - 1] = b;
  18942. }
  18943. } else {
  18944. for (i = 0; !q.isZero(); i++) {
  18945. b = q.andln(0xff);
  18946. q.iushrn(8);
  18947. res[i] = b;
  18948. }
  18949. for (; i < reqLength; i++) {
  18950. res[i] = 0;
  18951. }
  18952. }
  18953. return res;
  18954. };
  18955. if (Math.clz32) {
  18956. BN.prototype._countBits = function _countBits(w) {
  18957. return 32 - Math.clz32(w);
  18958. };
  18959. } else {
  18960. BN.prototype._countBits = function _countBits(w) {
  18961. var t = w;
  18962. var r = 0;
  18963. if (t >= 0x1000) {
  18964. r += 13;
  18965. t >>>= 13;
  18966. }
  18967. if (t >= 0x40) {
  18968. r += 7;
  18969. t >>>= 7;
  18970. }
  18971. if (t >= 0x8) {
  18972. r += 4;
  18973. t >>>= 4;
  18974. }
  18975. if (t >= 0x02) {
  18976. r += 2;
  18977. t >>>= 2;
  18978. }
  18979. return r + t;
  18980. };
  18981. }
  18982. BN.prototype._zeroBits = function _zeroBits(w) {
  18983. // Short-cut
  18984. if (w === 0) return 26;
  18985. var t = w;
  18986. var r = 0;
  18987. if ((t & 0x1fff) === 0) {
  18988. r += 13;
  18989. t >>>= 13;
  18990. }
  18991. if ((t & 0x7f) === 0) {
  18992. r += 7;
  18993. t >>>= 7;
  18994. }
  18995. if ((t & 0xf) === 0) {
  18996. r += 4;
  18997. t >>>= 4;
  18998. }
  18999. if ((t & 0x3) === 0) {
  19000. r += 2;
  19001. t >>>= 2;
  19002. }
  19003. if ((t & 0x1) === 0) {
  19004. r++;
  19005. }
  19006. return r;
  19007. };
  19008. // Return number of used bits in a BN
  19009. BN.prototype.bitLength = function bitLength() {
  19010. var w = this.words[this.length - 1];
  19011. var hi = this._countBits(w);
  19012. return (this.length - 1) * 26 + hi;
  19013. };
  19014. function toBitArray(num) {
  19015. var w = new Array(num.bitLength());
  19016. for (var bit = 0; bit < w.length; bit++) {
  19017. var off = bit / 26 | 0;
  19018. var wbit = bit % 26;
  19019. w[bit] = (num.words[off] & 1 << wbit) >>> wbit;
  19020. }
  19021. return w;
  19022. }
  19023. // Number of trailing zero bits
  19024. BN.prototype.zeroBits = function zeroBits() {
  19025. if (this.isZero()) return 0;
  19026. var r = 0;
  19027. for (var i = 0; i < this.length; i++) {
  19028. var b = this._zeroBits(this.words[i]);
  19029. r += b;
  19030. if (b !== 26) break;
  19031. }
  19032. return r;
  19033. };
  19034. BN.prototype.byteLength = function byteLength() {
  19035. return Math.ceil(this.bitLength() / 8);
  19036. };
  19037. BN.prototype.toTwos = function toTwos(width) {
  19038. if (this.negative !== 0) {
  19039. return this.abs().inotn(width).iaddn(1);
  19040. }
  19041. return this.clone();
  19042. };
  19043. BN.prototype.fromTwos = function fromTwos(width) {
  19044. if (this.testn(width - 1)) {
  19045. return this.notn(width).iaddn(1).ineg();
  19046. }
  19047. return this.clone();
  19048. };
  19049. BN.prototype.isNeg = function isNeg() {
  19050. return this.negative !== 0;
  19051. };
  19052. // Return negative clone of `this`
  19053. BN.prototype.neg = function neg() {
  19054. return this.clone().ineg();
  19055. };
  19056. BN.prototype.ineg = function ineg() {
  19057. if (!this.isZero()) {
  19058. this.negative ^= 1;
  19059. }
  19060. return this;
  19061. };
  19062. // Or `num` with `this` in-place
  19063. BN.prototype.iuor = function iuor(num) {
  19064. while (this.length < num.length) {
  19065. this.words[this.length++] = 0;
  19066. }
  19067. for (var i = 0; i < num.length; i++) {
  19068. this.words[i] = this.words[i] | num.words[i];
  19069. }
  19070. return this.strip();
  19071. };
  19072. BN.prototype.ior = function ior(num) {
  19073. assert((this.negative | num.negative) === 0);
  19074. return this.iuor(num);
  19075. };
  19076. // Or `num` with `this`
  19077. BN.prototype.or = function or(num) {
  19078. if (this.length > num.length) return this.clone().ior(num);
  19079. return num.clone().ior(this);
  19080. };
  19081. BN.prototype.uor = function uor(num) {
  19082. if (this.length > num.length) return this.clone().iuor(num);
  19083. return num.clone().iuor(this);
  19084. };
  19085. // And `num` with `this` in-place
  19086. BN.prototype.iuand = function iuand(num) {
  19087. // b = min-length(num, this)
  19088. var b;
  19089. if (this.length > num.length) {
  19090. b = num;
  19091. } else {
  19092. b = this;
  19093. }
  19094. for (var i = 0; i < b.length; i++) {
  19095. this.words[i] = this.words[i] & num.words[i];
  19096. }
  19097. this.length = b.length;
  19098. return this.strip();
  19099. };
  19100. BN.prototype.iand = function iand(num) {
  19101. assert((this.negative | num.negative) === 0);
  19102. return this.iuand(num);
  19103. };
  19104. // And `num` with `this`
  19105. BN.prototype.and = function and(num) {
  19106. if (this.length > num.length) return this.clone().iand(num);
  19107. return num.clone().iand(this);
  19108. };
  19109. BN.prototype.uand = function uand(num) {
  19110. if (this.length > num.length) return this.clone().iuand(num);
  19111. return num.clone().iuand(this);
  19112. };
  19113. // Xor `num` with `this` in-place
  19114. BN.prototype.iuxor = function iuxor(num) {
  19115. // a.length > b.length
  19116. var a;
  19117. var b;
  19118. if (this.length > num.length) {
  19119. a = this;
  19120. b = num;
  19121. } else {
  19122. a = num;
  19123. b = this;
  19124. }
  19125. for (var i = 0; i < b.length; i++) {
  19126. this.words[i] = a.words[i] ^ b.words[i];
  19127. }
  19128. if (this !== a) {
  19129. for (; i < a.length; i++) {
  19130. this.words[i] = a.words[i];
  19131. }
  19132. }
  19133. this.length = a.length;
  19134. return this.strip();
  19135. };
  19136. BN.prototype.ixor = function ixor(num) {
  19137. assert((this.negative | num.negative) === 0);
  19138. return this.iuxor(num);
  19139. };
  19140. // Xor `num` with `this`
  19141. BN.prototype.xor = function xor(num) {
  19142. if (this.length > num.length) return this.clone().ixor(num);
  19143. return num.clone().ixor(this);
  19144. };
  19145. BN.prototype.uxor = function uxor(num) {
  19146. if (this.length > num.length) return this.clone().iuxor(num);
  19147. return num.clone().iuxor(this);
  19148. };
  19149. // Not ``this`` with ``width`` bitwidth
  19150. BN.prototype.inotn = function inotn(width) {
  19151. assert(typeof width === 'number' && width >= 0);
  19152. var bytesNeeded = Math.ceil(width / 26) | 0;
  19153. var bitsLeft = width % 26;
  19154. // Extend the buffer with leading zeroes
  19155. this._expand(bytesNeeded);
  19156. if (bitsLeft > 0) {
  19157. bytesNeeded--;
  19158. }
  19159. // Handle complete words
  19160. for (var i = 0; i < bytesNeeded; i++) {
  19161. this.words[i] = ~this.words[i] & 0x3ffffff;
  19162. }
  19163. // Handle the residue
  19164. if (bitsLeft > 0) {
  19165. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  19166. }
  19167. // And remove leading zeroes
  19168. return this.strip();
  19169. };
  19170. BN.prototype.notn = function notn(width) {
  19171. return this.clone().inotn(width);
  19172. };
  19173. // Set `bit` of `this`
  19174. BN.prototype.setn = function setn(bit, val) {
  19175. assert(typeof bit === 'number' && bit >= 0);
  19176. var off = bit / 26 | 0;
  19177. var wbit = bit % 26;
  19178. this._expand(off + 1);
  19179. if (val) {
  19180. this.words[off] = this.words[off] | 1 << wbit;
  19181. } else {
  19182. this.words[off] = this.words[off] & ~(1 << wbit);
  19183. }
  19184. return this.strip();
  19185. };
  19186. // Add `num` to `this` in-place
  19187. BN.prototype.iadd = function iadd(num) {
  19188. var r;
  19189. // negative + positive
  19190. if (this.negative !== 0 && num.negative === 0) {
  19191. this.negative = 0;
  19192. r = this.isub(num);
  19193. this.negative ^= 1;
  19194. return this._normSign();
  19195. // positive + negative
  19196. } else if (this.negative === 0 && num.negative !== 0) {
  19197. num.negative = 0;
  19198. r = this.isub(num);
  19199. num.negative = 1;
  19200. return r._normSign();
  19201. }
  19202. // a.length > b.length
  19203. var a, b;
  19204. if (this.length > num.length) {
  19205. a = this;
  19206. b = num;
  19207. } else {
  19208. a = num;
  19209. b = this;
  19210. }
  19211. var carry = 0;
  19212. for (var i = 0; i < b.length; i++) {
  19213. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  19214. this.words[i] = r & 0x3ffffff;
  19215. carry = r >>> 26;
  19216. }
  19217. for (; carry !== 0 && i < a.length; i++) {
  19218. r = (a.words[i] | 0) + carry;
  19219. this.words[i] = r & 0x3ffffff;
  19220. carry = r >>> 26;
  19221. }
  19222. this.length = a.length;
  19223. if (carry !== 0) {
  19224. this.words[this.length] = carry;
  19225. this.length++;
  19226. // Copy the rest of the words
  19227. } else if (a !== this) {
  19228. for (; i < a.length; i++) {
  19229. this.words[i] = a.words[i];
  19230. }
  19231. }
  19232. return this;
  19233. };
  19234. // Add `num` to `this`
  19235. BN.prototype.add = function add(num) {
  19236. var res;
  19237. if (num.negative !== 0 && this.negative === 0) {
  19238. num.negative = 0;
  19239. res = this.sub(num);
  19240. num.negative ^= 1;
  19241. return res;
  19242. } else if (num.negative === 0 && this.negative !== 0) {
  19243. this.negative = 0;
  19244. res = num.sub(this);
  19245. this.negative = 1;
  19246. return res;
  19247. }
  19248. if (this.length > num.length) return this.clone().iadd(num);
  19249. return num.clone().iadd(this);
  19250. };
  19251. // Subtract `num` from `this` in-place
  19252. BN.prototype.isub = function isub(num) {
  19253. // this - (-num) = this + num
  19254. if (num.negative !== 0) {
  19255. num.negative = 0;
  19256. var r = this.iadd(num);
  19257. num.negative = 1;
  19258. return r._normSign();
  19259. // -this - num = -(this + num)
  19260. } else if (this.negative !== 0) {
  19261. this.negative = 0;
  19262. this.iadd(num);
  19263. this.negative = 1;
  19264. return this._normSign();
  19265. }
  19266. // At this point both numbers are positive
  19267. var cmp = this.cmp(num);
  19268. // Optimization - zeroify
  19269. if (cmp === 0) {
  19270. this.negative = 0;
  19271. this.length = 1;
  19272. this.words[0] = 0;
  19273. return this;
  19274. }
  19275. // a > b
  19276. var a, b;
  19277. if (cmp > 0) {
  19278. a = this;
  19279. b = num;
  19280. } else {
  19281. a = num;
  19282. b = this;
  19283. }
  19284. var carry = 0;
  19285. for (var i = 0; i < b.length; i++) {
  19286. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  19287. carry = r >> 26;
  19288. this.words[i] = r & 0x3ffffff;
  19289. }
  19290. for (; carry !== 0 && i < a.length; i++) {
  19291. r = (a.words[i] | 0) + carry;
  19292. carry = r >> 26;
  19293. this.words[i] = r & 0x3ffffff;
  19294. }
  19295. // Copy rest of the words
  19296. if (carry === 0 && i < a.length && a !== this) {
  19297. for (; i < a.length; i++) {
  19298. this.words[i] = a.words[i];
  19299. }
  19300. }
  19301. this.length = Math.max(this.length, i);
  19302. if (a !== this) {
  19303. this.negative = 1;
  19304. }
  19305. return this.strip();
  19306. };
  19307. // Subtract `num` from `this`
  19308. BN.prototype.sub = function sub(num) {
  19309. return this.clone().isub(num);
  19310. };
  19311. function smallMulTo(self, num, out) {
  19312. out.negative = num.negative ^ self.negative;
  19313. var len = self.length + num.length | 0;
  19314. out.length = len;
  19315. len = len - 1 | 0;
  19316. // Peel one iteration (compiler can't do it, because of code complexity)
  19317. var a = self.words[0] | 0;
  19318. var b = num.words[0] | 0;
  19319. var r = a * b;
  19320. var lo = r & 0x3ffffff;
  19321. var carry = r / 0x4000000 | 0;
  19322. out.words[0] = lo;
  19323. for (var k = 1; k < len; k++) {
  19324. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  19325. // note that ncarry could be >= 0x3ffffff
  19326. var ncarry = carry >>> 26;
  19327. var rword = carry & 0x3ffffff;
  19328. var maxJ = Math.min(k, num.length - 1);
  19329. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  19330. var i = k - j | 0;
  19331. a = self.words[i] | 0;
  19332. b = num.words[j] | 0;
  19333. r = a * b + rword;
  19334. ncarry += r / 0x4000000 | 0;
  19335. rword = r & 0x3ffffff;
  19336. }
  19337. out.words[k] = rword | 0;
  19338. carry = ncarry | 0;
  19339. }
  19340. if (carry !== 0) {
  19341. out.words[k] = carry | 0;
  19342. } else {
  19343. out.length--;
  19344. }
  19345. return out.strip();
  19346. }
  19347. // TODO(indutny): it may be reasonable to omit it for users who don't need
  19348. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  19349. // multiplication (like elliptic secp256k1).
  19350. var comb10MulTo = function comb10MulTo(self, num, out) {
  19351. var a = self.words;
  19352. var b = num.words;
  19353. var o = out.words;
  19354. var c = 0;
  19355. var lo;
  19356. var mid;
  19357. var hi;
  19358. var a0 = a[0] | 0;
  19359. var al0 = a0 & 0x1fff;
  19360. var ah0 = a0 >>> 13;
  19361. var a1 = a[1] | 0;
  19362. var al1 = a1 & 0x1fff;
  19363. var ah1 = a1 >>> 13;
  19364. var a2 = a[2] | 0;
  19365. var al2 = a2 & 0x1fff;
  19366. var ah2 = a2 >>> 13;
  19367. var a3 = a[3] | 0;
  19368. var al3 = a3 & 0x1fff;
  19369. var ah3 = a3 >>> 13;
  19370. var a4 = a[4] | 0;
  19371. var al4 = a4 & 0x1fff;
  19372. var ah4 = a4 >>> 13;
  19373. var a5 = a[5] | 0;
  19374. var al5 = a5 & 0x1fff;
  19375. var ah5 = a5 >>> 13;
  19376. var a6 = a[6] | 0;
  19377. var al6 = a6 & 0x1fff;
  19378. var ah6 = a6 >>> 13;
  19379. var a7 = a[7] | 0;
  19380. var al7 = a7 & 0x1fff;
  19381. var ah7 = a7 >>> 13;
  19382. var a8 = a[8] | 0;
  19383. var al8 = a8 & 0x1fff;
  19384. var ah8 = a8 >>> 13;
  19385. var a9 = a[9] | 0;
  19386. var al9 = a9 & 0x1fff;
  19387. var ah9 = a9 >>> 13;
  19388. var b0 = b[0] | 0;
  19389. var bl0 = b0 & 0x1fff;
  19390. var bh0 = b0 >>> 13;
  19391. var b1 = b[1] | 0;
  19392. var bl1 = b1 & 0x1fff;
  19393. var bh1 = b1 >>> 13;
  19394. var b2 = b[2] | 0;
  19395. var bl2 = b2 & 0x1fff;
  19396. var bh2 = b2 >>> 13;
  19397. var b3 = b[3] | 0;
  19398. var bl3 = b3 & 0x1fff;
  19399. var bh3 = b3 >>> 13;
  19400. var b4 = b[4] | 0;
  19401. var bl4 = b4 & 0x1fff;
  19402. var bh4 = b4 >>> 13;
  19403. var b5 = b[5] | 0;
  19404. var bl5 = b5 & 0x1fff;
  19405. var bh5 = b5 >>> 13;
  19406. var b6 = b[6] | 0;
  19407. var bl6 = b6 & 0x1fff;
  19408. var bh6 = b6 >>> 13;
  19409. var b7 = b[7] | 0;
  19410. var bl7 = b7 & 0x1fff;
  19411. var bh7 = b7 >>> 13;
  19412. var b8 = b[8] | 0;
  19413. var bl8 = b8 & 0x1fff;
  19414. var bh8 = b8 >>> 13;
  19415. var b9 = b[9] | 0;
  19416. var bl9 = b9 & 0x1fff;
  19417. var bh9 = b9 >>> 13;
  19418. out.negative = self.negative ^ num.negative;
  19419. out.length = 19;
  19420. /* k = 0 */
  19421. lo = Math.imul(al0, bl0);
  19422. mid = Math.imul(al0, bh0);
  19423. mid = mid + Math.imul(ah0, bl0) | 0;
  19424. hi = Math.imul(ah0, bh0);
  19425. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19426. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  19427. w0 &= 0x3ffffff;
  19428. /* k = 1 */
  19429. lo = Math.imul(al1, bl0);
  19430. mid = Math.imul(al1, bh0);
  19431. mid = mid + Math.imul(ah1, bl0) | 0;
  19432. hi = Math.imul(ah1, bh0);
  19433. lo = lo + Math.imul(al0, bl1) | 0;
  19434. mid = mid + Math.imul(al0, bh1) | 0;
  19435. mid = mid + Math.imul(ah0, bl1) | 0;
  19436. hi = hi + Math.imul(ah0, bh1) | 0;
  19437. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19438. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  19439. w1 &= 0x3ffffff;
  19440. /* k = 2 */
  19441. lo = Math.imul(al2, bl0);
  19442. mid = Math.imul(al2, bh0);
  19443. mid = mid + Math.imul(ah2, bl0) | 0;
  19444. hi = Math.imul(ah2, bh0);
  19445. lo = lo + Math.imul(al1, bl1) | 0;
  19446. mid = mid + Math.imul(al1, bh1) | 0;
  19447. mid = mid + Math.imul(ah1, bl1) | 0;
  19448. hi = hi + Math.imul(ah1, bh1) | 0;
  19449. lo = lo + Math.imul(al0, bl2) | 0;
  19450. mid = mid + Math.imul(al0, bh2) | 0;
  19451. mid = mid + Math.imul(ah0, bl2) | 0;
  19452. hi = hi + Math.imul(ah0, bh2) | 0;
  19453. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19454. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  19455. w2 &= 0x3ffffff;
  19456. /* k = 3 */
  19457. lo = Math.imul(al3, bl0);
  19458. mid = Math.imul(al3, bh0);
  19459. mid = mid + Math.imul(ah3, bl0) | 0;
  19460. hi = Math.imul(ah3, bh0);
  19461. lo = lo + Math.imul(al2, bl1) | 0;
  19462. mid = mid + Math.imul(al2, bh1) | 0;
  19463. mid = mid + Math.imul(ah2, bl1) | 0;
  19464. hi = hi + Math.imul(ah2, bh1) | 0;
  19465. lo = lo + Math.imul(al1, bl2) | 0;
  19466. mid = mid + Math.imul(al1, bh2) | 0;
  19467. mid = mid + Math.imul(ah1, bl2) | 0;
  19468. hi = hi + Math.imul(ah1, bh2) | 0;
  19469. lo = lo + Math.imul(al0, bl3) | 0;
  19470. mid = mid + Math.imul(al0, bh3) | 0;
  19471. mid = mid + Math.imul(ah0, bl3) | 0;
  19472. hi = hi + Math.imul(ah0, bh3) | 0;
  19473. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19474. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  19475. w3 &= 0x3ffffff;
  19476. /* k = 4 */
  19477. lo = Math.imul(al4, bl0);
  19478. mid = Math.imul(al4, bh0);
  19479. mid = mid + Math.imul(ah4, bl0) | 0;
  19480. hi = Math.imul(ah4, bh0);
  19481. lo = lo + Math.imul(al3, bl1) | 0;
  19482. mid = mid + Math.imul(al3, bh1) | 0;
  19483. mid = mid + Math.imul(ah3, bl1) | 0;
  19484. hi = hi + Math.imul(ah3, bh1) | 0;
  19485. lo = lo + Math.imul(al2, bl2) | 0;
  19486. mid = mid + Math.imul(al2, bh2) | 0;
  19487. mid = mid + Math.imul(ah2, bl2) | 0;
  19488. hi = hi + Math.imul(ah2, bh2) | 0;
  19489. lo = lo + Math.imul(al1, bl3) | 0;
  19490. mid = mid + Math.imul(al1, bh3) | 0;
  19491. mid = mid + Math.imul(ah1, bl3) | 0;
  19492. hi = hi + Math.imul(ah1, bh3) | 0;
  19493. lo = lo + Math.imul(al0, bl4) | 0;
  19494. mid = mid + Math.imul(al0, bh4) | 0;
  19495. mid = mid + Math.imul(ah0, bl4) | 0;
  19496. hi = hi + Math.imul(ah0, bh4) | 0;
  19497. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19498. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  19499. w4 &= 0x3ffffff;
  19500. /* k = 5 */
  19501. lo = Math.imul(al5, bl0);
  19502. mid = Math.imul(al5, bh0);
  19503. mid = mid + Math.imul(ah5, bl0) | 0;
  19504. hi = Math.imul(ah5, bh0);
  19505. lo = lo + Math.imul(al4, bl1) | 0;
  19506. mid = mid + Math.imul(al4, bh1) | 0;
  19507. mid = mid + Math.imul(ah4, bl1) | 0;
  19508. hi = hi + Math.imul(ah4, bh1) | 0;
  19509. lo = lo + Math.imul(al3, bl2) | 0;
  19510. mid = mid + Math.imul(al3, bh2) | 0;
  19511. mid = mid + Math.imul(ah3, bl2) | 0;
  19512. hi = hi + Math.imul(ah3, bh2) | 0;
  19513. lo = lo + Math.imul(al2, bl3) | 0;
  19514. mid = mid + Math.imul(al2, bh3) | 0;
  19515. mid = mid + Math.imul(ah2, bl3) | 0;
  19516. hi = hi + Math.imul(ah2, bh3) | 0;
  19517. lo = lo + Math.imul(al1, bl4) | 0;
  19518. mid = mid + Math.imul(al1, bh4) | 0;
  19519. mid = mid + Math.imul(ah1, bl4) | 0;
  19520. hi = hi + Math.imul(ah1, bh4) | 0;
  19521. lo = lo + Math.imul(al0, bl5) | 0;
  19522. mid = mid + Math.imul(al0, bh5) | 0;
  19523. mid = mid + Math.imul(ah0, bl5) | 0;
  19524. hi = hi + Math.imul(ah0, bh5) | 0;
  19525. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19526. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  19527. w5 &= 0x3ffffff;
  19528. /* k = 6 */
  19529. lo = Math.imul(al6, bl0);
  19530. mid = Math.imul(al6, bh0);
  19531. mid = mid + Math.imul(ah6, bl0) | 0;
  19532. hi = Math.imul(ah6, bh0);
  19533. lo = lo + Math.imul(al5, bl1) | 0;
  19534. mid = mid + Math.imul(al5, bh1) | 0;
  19535. mid = mid + Math.imul(ah5, bl1) | 0;
  19536. hi = hi + Math.imul(ah5, bh1) | 0;
  19537. lo = lo + Math.imul(al4, bl2) | 0;
  19538. mid = mid + Math.imul(al4, bh2) | 0;
  19539. mid = mid + Math.imul(ah4, bl2) | 0;
  19540. hi = hi + Math.imul(ah4, bh2) | 0;
  19541. lo = lo + Math.imul(al3, bl3) | 0;
  19542. mid = mid + Math.imul(al3, bh3) | 0;
  19543. mid = mid + Math.imul(ah3, bl3) | 0;
  19544. hi = hi + Math.imul(ah3, bh3) | 0;
  19545. lo = lo + Math.imul(al2, bl4) | 0;
  19546. mid = mid + Math.imul(al2, bh4) | 0;
  19547. mid = mid + Math.imul(ah2, bl4) | 0;
  19548. hi = hi + Math.imul(ah2, bh4) | 0;
  19549. lo = lo + Math.imul(al1, bl5) | 0;
  19550. mid = mid + Math.imul(al1, bh5) | 0;
  19551. mid = mid + Math.imul(ah1, bl5) | 0;
  19552. hi = hi + Math.imul(ah1, bh5) | 0;
  19553. lo = lo + Math.imul(al0, bl6) | 0;
  19554. mid = mid + Math.imul(al0, bh6) | 0;
  19555. mid = mid + Math.imul(ah0, bl6) | 0;
  19556. hi = hi + Math.imul(ah0, bh6) | 0;
  19557. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19558. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  19559. w6 &= 0x3ffffff;
  19560. /* k = 7 */
  19561. lo = Math.imul(al7, bl0);
  19562. mid = Math.imul(al7, bh0);
  19563. mid = mid + Math.imul(ah7, bl0) | 0;
  19564. hi = Math.imul(ah7, bh0);
  19565. lo = lo + Math.imul(al6, bl1) | 0;
  19566. mid = mid + Math.imul(al6, bh1) | 0;
  19567. mid = mid + Math.imul(ah6, bl1) | 0;
  19568. hi = hi + Math.imul(ah6, bh1) | 0;
  19569. lo = lo + Math.imul(al5, bl2) | 0;
  19570. mid = mid + Math.imul(al5, bh2) | 0;
  19571. mid = mid + Math.imul(ah5, bl2) | 0;
  19572. hi = hi + Math.imul(ah5, bh2) | 0;
  19573. lo = lo + Math.imul(al4, bl3) | 0;
  19574. mid = mid + Math.imul(al4, bh3) | 0;
  19575. mid = mid + Math.imul(ah4, bl3) | 0;
  19576. hi = hi + Math.imul(ah4, bh3) | 0;
  19577. lo = lo + Math.imul(al3, bl4) | 0;
  19578. mid = mid + Math.imul(al3, bh4) | 0;
  19579. mid = mid + Math.imul(ah3, bl4) | 0;
  19580. hi = hi + Math.imul(ah3, bh4) | 0;
  19581. lo = lo + Math.imul(al2, bl5) | 0;
  19582. mid = mid + Math.imul(al2, bh5) | 0;
  19583. mid = mid + Math.imul(ah2, bl5) | 0;
  19584. hi = hi + Math.imul(ah2, bh5) | 0;
  19585. lo = lo + Math.imul(al1, bl6) | 0;
  19586. mid = mid + Math.imul(al1, bh6) | 0;
  19587. mid = mid + Math.imul(ah1, bl6) | 0;
  19588. hi = hi + Math.imul(ah1, bh6) | 0;
  19589. lo = lo + Math.imul(al0, bl7) | 0;
  19590. mid = mid + Math.imul(al0, bh7) | 0;
  19591. mid = mid + Math.imul(ah0, bl7) | 0;
  19592. hi = hi + Math.imul(ah0, bh7) | 0;
  19593. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19594. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  19595. w7 &= 0x3ffffff;
  19596. /* k = 8 */
  19597. lo = Math.imul(al8, bl0);
  19598. mid = Math.imul(al8, bh0);
  19599. mid = mid + Math.imul(ah8, bl0) | 0;
  19600. hi = Math.imul(ah8, bh0);
  19601. lo = lo + Math.imul(al7, bl1) | 0;
  19602. mid = mid + Math.imul(al7, bh1) | 0;
  19603. mid = mid + Math.imul(ah7, bl1) | 0;
  19604. hi = hi + Math.imul(ah7, bh1) | 0;
  19605. lo = lo + Math.imul(al6, bl2) | 0;
  19606. mid = mid + Math.imul(al6, bh2) | 0;
  19607. mid = mid + Math.imul(ah6, bl2) | 0;
  19608. hi = hi + Math.imul(ah6, bh2) | 0;
  19609. lo = lo + Math.imul(al5, bl3) | 0;
  19610. mid = mid + Math.imul(al5, bh3) | 0;
  19611. mid = mid + Math.imul(ah5, bl3) | 0;
  19612. hi = hi + Math.imul(ah5, bh3) | 0;
  19613. lo = lo + Math.imul(al4, bl4) | 0;
  19614. mid = mid + Math.imul(al4, bh4) | 0;
  19615. mid = mid + Math.imul(ah4, bl4) | 0;
  19616. hi = hi + Math.imul(ah4, bh4) | 0;
  19617. lo = lo + Math.imul(al3, bl5) | 0;
  19618. mid = mid + Math.imul(al3, bh5) | 0;
  19619. mid = mid + Math.imul(ah3, bl5) | 0;
  19620. hi = hi + Math.imul(ah3, bh5) | 0;
  19621. lo = lo + Math.imul(al2, bl6) | 0;
  19622. mid = mid + Math.imul(al2, bh6) | 0;
  19623. mid = mid + Math.imul(ah2, bl6) | 0;
  19624. hi = hi + Math.imul(ah2, bh6) | 0;
  19625. lo = lo + Math.imul(al1, bl7) | 0;
  19626. mid = mid + Math.imul(al1, bh7) | 0;
  19627. mid = mid + Math.imul(ah1, bl7) | 0;
  19628. hi = hi + Math.imul(ah1, bh7) | 0;
  19629. lo = lo + Math.imul(al0, bl8) | 0;
  19630. mid = mid + Math.imul(al0, bh8) | 0;
  19631. mid = mid + Math.imul(ah0, bl8) | 0;
  19632. hi = hi + Math.imul(ah0, bh8) | 0;
  19633. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19634. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  19635. w8 &= 0x3ffffff;
  19636. /* k = 9 */
  19637. lo = Math.imul(al9, bl0);
  19638. mid = Math.imul(al9, bh0);
  19639. mid = mid + Math.imul(ah9, bl0) | 0;
  19640. hi = Math.imul(ah9, bh0);
  19641. lo = lo + Math.imul(al8, bl1) | 0;
  19642. mid = mid + Math.imul(al8, bh1) | 0;
  19643. mid = mid + Math.imul(ah8, bl1) | 0;
  19644. hi = hi + Math.imul(ah8, bh1) | 0;
  19645. lo = lo + Math.imul(al7, bl2) | 0;
  19646. mid = mid + Math.imul(al7, bh2) | 0;
  19647. mid = mid + Math.imul(ah7, bl2) | 0;
  19648. hi = hi + Math.imul(ah7, bh2) | 0;
  19649. lo = lo + Math.imul(al6, bl3) | 0;
  19650. mid = mid + Math.imul(al6, bh3) | 0;
  19651. mid = mid + Math.imul(ah6, bl3) | 0;
  19652. hi = hi + Math.imul(ah6, bh3) | 0;
  19653. lo = lo + Math.imul(al5, bl4) | 0;
  19654. mid = mid + Math.imul(al5, bh4) | 0;
  19655. mid = mid + Math.imul(ah5, bl4) | 0;
  19656. hi = hi + Math.imul(ah5, bh4) | 0;
  19657. lo = lo + Math.imul(al4, bl5) | 0;
  19658. mid = mid + Math.imul(al4, bh5) | 0;
  19659. mid = mid + Math.imul(ah4, bl5) | 0;
  19660. hi = hi + Math.imul(ah4, bh5) | 0;
  19661. lo = lo + Math.imul(al3, bl6) | 0;
  19662. mid = mid + Math.imul(al3, bh6) | 0;
  19663. mid = mid + Math.imul(ah3, bl6) | 0;
  19664. hi = hi + Math.imul(ah3, bh6) | 0;
  19665. lo = lo + Math.imul(al2, bl7) | 0;
  19666. mid = mid + Math.imul(al2, bh7) | 0;
  19667. mid = mid + Math.imul(ah2, bl7) | 0;
  19668. hi = hi + Math.imul(ah2, bh7) | 0;
  19669. lo = lo + Math.imul(al1, bl8) | 0;
  19670. mid = mid + Math.imul(al1, bh8) | 0;
  19671. mid = mid + Math.imul(ah1, bl8) | 0;
  19672. hi = hi + Math.imul(ah1, bh8) | 0;
  19673. lo = lo + Math.imul(al0, bl9) | 0;
  19674. mid = mid + Math.imul(al0, bh9) | 0;
  19675. mid = mid + Math.imul(ah0, bl9) | 0;
  19676. hi = hi + Math.imul(ah0, bh9) | 0;
  19677. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19678. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  19679. w9 &= 0x3ffffff;
  19680. /* k = 10 */
  19681. lo = Math.imul(al9, bl1);
  19682. mid = Math.imul(al9, bh1);
  19683. mid = mid + Math.imul(ah9, bl1) | 0;
  19684. hi = Math.imul(ah9, bh1);
  19685. lo = lo + Math.imul(al8, bl2) | 0;
  19686. mid = mid + Math.imul(al8, bh2) | 0;
  19687. mid = mid + Math.imul(ah8, bl2) | 0;
  19688. hi = hi + Math.imul(ah8, bh2) | 0;
  19689. lo = lo + Math.imul(al7, bl3) | 0;
  19690. mid = mid + Math.imul(al7, bh3) | 0;
  19691. mid = mid + Math.imul(ah7, bl3) | 0;
  19692. hi = hi + Math.imul(ah7, bh3) | 0;
  19693. lo = lo + Math.imul(al6, bl4) | 0;
  19694. mid = mid + Math.imul(al6, bh4) | 0;
  19695. mid = mid + Math.imul(ah6, bl4) | 0;
  19696. hi = hi + Math.imul(ah6, bh4) | 0;
  19697. lo = lo + Math.imul(al5, bl5) | 0;
  19698. mid = mid + Math.imul(al5, bh5) | 0;
  19699. mid = mid + Math.imul(ah5, bl5) | 0;
  19700. hi = hi + Math.imul(ah5, bh5) | 0;
  19701. lo = lo + Math.imul(al4, bl6) | 0;
  19702. mid = mid + Math.imul(al4, bh6) | 0;
  19703. mid = mid + Math.imul(ah4, bl6) | 0;
  19704. hi = hi + Math.imul(ah4, bh6) | 0;
  19705. lo = lo + Math.imul(al3, bl7) | 0;
  19706. mid = mid + Math.imul(al3, bh7) | 0;
  19707. mid = mid + Math.imul(ah3, bl7) | 0;
  19708. hi = hi + Math.imul(ah3, bh7) | 0;
  19709. lo = lo + Math.imul(al2, bl8) | 0;
  19710. mid = mid + Math.imul(al2, bh8) | 0;
  19711. mid = mid + Math.imul(ah2, bl8) | 0;
  19712. hi = hi + Math.imul(ah2, bh8) | 0;
  19713. lo = lo + Math.imul(al1, bl9) | 0;
  19714. mid = mid + Math.imul(al1, bh9) | 0;
  19715. mid = mid + Math.imul(ah1, bl9) | 0;
  19716. hi = hi + Math.imul(ah1, bh9) | 0;
  19717. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19718. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  19719. w10 &= 0x3ffffff;
  19720. /* k = 11 */
  19721. lo = Math.imul(al9, bl2);
  19722. mid = Math.imul(al9, bh2);
  19723. mid = mid + Math.imul(ah9, bl2) | 0;
  19724. hi = Math.imul(ah9, bh2);
  19725. lo = lo + Math.imul(al8, bl3) | 0;
  19726. mid = mid + Math.imul(al8, bh3) | 0;
  19727. mid = mid + Math.imul(ah8, bl3) | 0;
  19728. hi = hi + Math.imul(ah8, bh3) | 0;
  19729. lo = lo + Math.imul(al7, bl4) | 0;
  19730. mid = mid + Math.imul(al7, bh4) | 0;
  19731. mid = mid + Math.imul(ah7, bl4) | 0;
  19732. hi = hi + Math.imul(ah7, bh4) | 0;
  19733. lo = lo + Math.imul(al6, bl5) | 0;
  19734. mid = mid + Math.imul(al6, bh5) | 0;
  19735. mid = mid + Math.imul(ah6, bl5) | 0;
  19736. hi = hi + Math.imul(ah6, bh5) | 0;
  19737. lo = lo + Math.imul(al5, bl6) | 0;
  19738. mid = mid + Math.imul(al5, bh6) | 0;
  19739. mid = mid + Math.imul(ah5, bl6) | 0;
  19740. hi = hi + Math.imul(ah5, bh6) | 0;
  19741. lo = lo + Math.imul(al4, bl7) | 0;
  19742. mid = mid + Math.imul(al4, bh7) | 0;
  19743. mid = mid + Math.imul(ah4, bl7) | 0;
  19744. hi = hi + Math.imul(ah4, bh7) | 0;
  19745. lo = lo + Math.imul(al3, bl8) | 0;
  19746. mid = mid + Math.imul(al3, bh8) | 0;
  19747. mid = mid + Math.imul(ah3, bl8) | 0;
  19748. hi = hi + Math.imul(ah3, bh8) | 0;
  19749. lo = lo + Math.imul(al2, bl9) | 0;
  19750. mid = mid + Math.imul(al2, bh9) | 0;
  19751. mid = mid + Math.imul(ah2, bl9) | 0;
  19752. hi = hi + Math.imul(ah2, bh9) | 0;
  19753. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19754. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  19755. w11 &= 0x3ffffff;
  19756. /* k = 12 */
  19757. lo = Math.imul(al9, bl3);
  19758. mid = Math.imul(al9, bh3);
  19759. mid = mid + Math.imul(ah9, bl3) | 0;
  19760. hi = Math.imul(ah9, bh3);
  19761. lo = lo + Math.imul(al8, bl4) | 0;
  19762. mid = mid + Math.imul(al8, bh4) | 0;
  19763. mid = mid + Math.imul(ah8, bl4) | 0;
  19764. hi = hi + Math.imul(ah8, bh4) | 0;
  19765. lo = lo + Math.imul(al7, bl5) | 0;
  19766. mid = mid + Math.imul(al7, bh5) | 0;
  19767. mid = mid + Math.imul(ah7, bl5) | 0;
  19768. hi = hi + Math.imul(ah7, bh5) | 0;
  19769. lo = lo + Math.imul(al6, bl6) | 0;
  19770. mid = mid + Math.imul(al6, bh6) | 0;
  19771. mid = mid + Math.imul(ah6, bl6) | 0;
  19772. hi = hi + Math.imul(ah6, bh6) | 0;
  19773. lo = lo + Math.imul(al5, bl7) | 0;
  19774. mid = mid + Math.imul(al5, bh7) | 0;
  19775. mid = mid + Math.imul(ah5, bl7) | 0;
  19776. hi = hi + Math.imul(ah5, bh7) | 0;
  19777. lo = lo + Math.imul(al4, bl8) | 0;
  19778. mid = mid + Math.imul(al4, bh8) | 0;
  19779. mid = mid + Math.imul(ah4, bl8) | 0;
  19780. hi = hi + Math.imul(ah4, bh8) | 0;
  19781. lo = lo + Math.imul(al3, bl9) | 0;
  19782. mid = mid + Math.imul(al3, bh9) | 0;
  19783. mid = mid + Math.imul(ah3, bl9) | 0;
  19784. hi = hi + Math.imul(ah3, bh9) | 0;
  19785. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19786. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  19787. w12 &= 0x3ffffff;
  19788. /* k = 13 */
  19789. lo = Math.imul(al9, bl4);
  19790. mid = Math.imul(al9, bh4);
  19791. mid = mid + Math.imul(ah9, bl4) | 0;
  19792. hi = Math.imul(ah9, bh4);
  19793. lo = lo + Math.imul(al8, bl5) | 0;
  19794. mid = mid + Math.imul(al8, bh5) | 0;
  19795. mid = mid + Math.imul(ah8, bl5) | 0;
  19796. hi = hi + Math.imul(ah8, bh5) | 0;
  19797. lo = lo + Math.imul(al7, bl6) | 0;
  19798. mid = mid + Math.imul(al7, bh6) | 0;
  19799. mid = mid + Math.imul(ah7, bl6) | 0;
  19800. hi = hi + Math.imul(ah7, bh6) | 0;
  19801. lo = lo + Math.imul(al6, bl7) | 0;
  19802. mid = mid + Math.imul(al6, bh7) | 0;
  19803. mid = mid + Math.imul(ah6, bl7) | 0;
  19804. hi = hi + Math.imul(ah6, bh7) | 0;
  19805. lo = lo + Math.imul(al5, bl8) | 0;
  19806. mid = mid + Math.imul(al5, bh8) | 0;
  19807. mid = mid + Math.imul(ah5, bl8) | 0;
  19808. hi = hi + Math.imul(ah5, bh8) | 0;
  19809. lo = lo + Math.imul(al4, bl9) | 0;
  19810. mid = mid + Math.imul(al4, bh9) | 0;
  19811. mid = mid + Math.imul(ah4, bl9) | 0;
  19812. hi = hi + Math.imul(ah4, bh9) | 0;
  19813. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19814. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  19815. w13 &= 0x3ffffff;
  19816. /* k = 14 */
  19817. lo = Math.imul(al9, bl5);
  19818. mid = Math.imul(al9, bh5);
  19819. mid = mid + Math.imul(ah9, bl5) | 0;
  19820. hi = Math.imul(ah9, bh5);
  19821. lo = lo + Math.imul(al8, bl6) | 0;
  19822. mid = mid + Math.imul(al8, bh6) | 0;
  19823. mid = mid + Math.imul(ah8, bl6) | 0;
  19824. hi = hi + Math.imul(ah8, bh6) | 0;
  19825. lo = lo + Math.imul(al7, bl7) | 0;
  19826. mid = mid + Math.imul(al7, bh7) | 0;
  19827. mid = mid + Math.imul(ah7, bl7) | 0;
  19828. hi = hi + Math.imul(ah7, bh7) | 0;
  19829. lo = lo + Math.imul(al6, bl8) | 0;
  19830. mid = mid + Math.imul(al6, bh8) | 0;
  19831. mid = mid + Math.imul(ah6, bl8) | 0;
  19832. hi = hi + Math.imul(ah6, bh8) | 0;
  19833. lo = lo + Math.imul(al5, bl9) | 0;
  19834. mid = mid + Math.imul(al5, bh9) | 0;
  19835. mid = mid + Math.imul(ah5, bl9) | 0;
  19836. hi = hi + Math.imul(ah5, bh9) | 0;
  19837. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19838. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  19839. w14 &= 0x3ffffff;
  19840. /* k = 15 */
  19841. lo = Math.imul(al9, bl6);
  19842. mid = Math.imul(al9, bh6);
  19843. mid = mid + Math.imul(ah9, bl6) | 0;
  19844. hi = Math.imul(ah9, bh6);
  19845. lo = lo + Math.imul(al8, bl7) | 0;
  19846. mid = mid + Math.imul(al8, bh7) | 0;
  19847. mid = mid + Math.imul(ah8, bl7) | 0;
  19848. hi = hi + Math.imul(ah8, bh7) | 0;
  19849. lo = lo + Math.imul(al7, bl8) | 0;
  19850. mid = mid + Math.imul(al7, bh8) | 0;
  19851. mid = mid + Math.imul(ah7, bl8) | 0;
  19852. hi = hi + Math.imul(ah7, bh8) | 0;
  19853. lo = lo + Math.imul(al6, bl9) | 0;
  19854. mid = mid + Math.imul(al6, bh9) | 0;
  19855. mid = mid + Math.imul(ah6, bl9) | 0;
  19856. hi = hi + Math.imul(ah6, bh9) | 0;
  19857. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19858. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  19859. w15 &= 0x3ffffff;
  19860. /* k = 16 */
  19861. lo = Math.imul(al9, bl7);
  19862. mid = Math.imul(al9, bh7);
  19863. mid = mid + Math.imul(ah9, bl7) | 0;
  19864. hi = Math.imul(ah9, bh7);
  19865. lo = lo + Math.imul(al8, bl8) | 0;
  19866. mid = mid + Math.imul(al8, bh8) | 0;
  19867. mid = mid + Math.imul(ah8, bl8) | 0;
  19868. hi = hi + Math.imul(ah8, bh8) | 0;
  19869. lo = lo + Math.imul(al7, bl9) | 0;
  19870. mid = mid + Math.imul(al7, bh9) | 0;
  19871. mid = mid + Math.imul(ah7, bl9) | 0;
  19872. hi = hi + Math.imul(ah7, bh9) | 0;
  19873. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19874. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  19875. w16 &= 0x3ffffff;
  19876. /* k = 17 */
  19877. lo = Math.imul(al9, bl8);
  19878. mid = Math.imul(al9, bh8);
  19879. mid = mid + Math.imul(ah9, bl8) | 0;
  19880. hi = Math.imul(ah9, bh8);
  19881. lo = lo + Math.imul(al8, bl9) | 0;
  19882. mid = mid + Math.imul(al8, bh9) | 0;
  19883. mid = mid + Math.imul(ah8, bl9) | 0;
  19884. hi = hi + Math.imul(ah8, bh9) | 0;
  19885. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19886. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  19887. w17 &= 0x3ffffff;
  19888. /* k = 18 */
  19889. lo = Math.imul(al9, bl9);
  19890. mid = Math.imul(al9, bh9);
  19891. mid = mid + Math.imul(ah9, bl9) | 0;
  19892. hi = Math.imul(ah9, bh9);
  19893. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  19894. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  19895. w18 &= 0x3ffffff;
  19896. o[0] = w0;
  19897. o[1] = w1;
  19898. o[2] = w2;
  19899. o[3] = w3;
  19900. o[4] = w4;
  19901. o[5] = w5;
  19902. o[6] = w6;
  19903. o[7] = w7;
  19904. o[8] = w8;
  19905. o[9] = w9;
  19906. o[10] = w10;
  19907. o[11] = w11;
  19908. o[12] = w12;
  19909. o[13] = w13;
  19910. o[14] = w14;
  19911. o[15] = w15;
  19912. o[16] = w16;
  19913. o[17] = w17;
  19914. o[18] = w18;
  19915. if (c !== 0) {
  19916. o[19] = c;
  19917. out.length++;
  19918. }
  19919. return out;
  19920. };
  19921. // Polyfill comb
  19922. if (!Math.imul) {
  19923. comb10MulTo = smallMulTo;
  19924. }
  19925. function bigMulTo(self, num, out) {
  19926. out.negative = num.negative ^ self.negative;
  19927. out.length = self.length + num.length;
  19928. var carry = 0;
  19929. var hncarry = 0;
  19930. for (var k = 0; k < out.length - 1; k++) {
  19931. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  19932. // note that ncarry could be >= 0x3ffffff
  19933. var ncarry = hncarry;
  19934. hncarry = 0;
  19935. var rword = carry & 0x3ffffff;
  19936. var maxJ = Math.min(k, num.length - 1);
  19937. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  19938. var i = k - j;
  19939. var a = self.words[i] | 0;
  19940. var b = num.words[j] | 0;
  19941. var r = a * b;
  19942. var lo = r & 0x3ffffff;
  19943. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  19944. lo = lo + rword | 0;
  19945. rword = lo & 0x3ffffff;
  19946. ncarry = ncarry + (lo >>> 26) | 0;
  19947. hncarry += ncarry >>> 26;
  19948. ncarry &= 0x3ffffff;
  19949. }
  19950. out.words[k] = rword;
  19951. carry = ncarry;
  19952. ncarry = hncarry;
  19953. }
  19954. if (carry !== 0) {
  19955. out.words[k] = carry;
  19956. } else {
  19957. out.length--;
  19958. }
  19959. return out.strip();
  19960. }
  19961. function jumboMulTo(self, num, out) {
  19962. var fftm = new FFTM();
  19963. return fftm.mulp(self, num, out);
  19964. }
  19965. BN.prototype.mulTo = function mulTo(num, out) {
  19966. var res;
  19967. var len = this.length + num.length;
  19968. if (this.length === 10 && num.length === 10) {
  19969. res = comb10MulTo(this, num, out);
  19970. } else if (len < 63) {
  19971. res = smallMulTo(this, num, out);
  19972. } else if (len < 1024) {
  19973. res = bigMulTo(this, num, out);
  19974. } else {
  19975. res = jumboMulTo(this, num, out);
  19976. }
  19977. return res;
  19978. };
  19979. // Cooley-Tukey algorithm for FFT
  19980. // slightly revisited to rely on looping instead of recursion
  19981. function FFTM(x, y) {
  19982. this.x = x;
  19983. this.y = y;
  19984. }
  19985. FFTM.prototype.makeRBT = function makeRBT(N) {
  19986. var t = new Array(N);
  19987. var l = BN.prototype._countBits(N) - 1;
  19988. for (var i = 0; i < N; i++) {
  19989. t[i] = this.revBin(i, l, N);
  19990. }
  19991. return t;
  19992. };
  19993. // Returns binary-reversed representation of `x`
  19994. FFTM.prototype.revBin = function revBin(x, l, N) {
  19995. if (x === 0 || x === N - 1) return x;
  19996. var rb = 0;
  19997. for (var i = 0; i < l; i++) {
  19998. rb |= (x & 1) << l - i - 1;
  19999. x >>= 1;
  20000. }
  20001. return rb;
  20002. };
  20003. // Performs "tweedling" phase, therefore 'emulating'
  20004. // behaviour of the recursive algorithm
  20005. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  20006. for (var i = 0; i < N; i++) {
  20007. rtws[i] = rws[rbt[i]];
  20008. itws[i] = iws[rbt[i]];
  20009. }
  20010. };
  20011. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  20012. this.permute(rbt, rws, iws, rtws, itws, N);
  20013. for (var s = 1; s < N; s <<= 1) {
  20014. var l = s << 1;
  20015. var rtwdf = Math.cos(2 * Math.PI / l);
  20016. var itwdf = Math.sin(2 * Math.PI / l);
  20017. for (var p = 0; p < N; p += l) {
  20018. var rtwdf_ = rtwdf;
  20019. var itwdf_ = itwdf;
  20020. for (var j = 0; j < s; j++) {
  20021. var re = rtws[p + j];
  20022. var ie = itws[p + j];
  20023. var ro = rtws[p + j + s];
  20024. var io = itws[p + j + s];
  20025. var rx = rtwdf_ * ro - itwdf_ * io;
  20026. io = rtwdf_ * io + itwdf_ * ro;
  20027. ro = rx;
  20028. rtws[p + j] = re + ro;
  20029. itws[p + j] = ie + io;
  20030. rtws[p + j + s] = re - ro;
  20031. itws[p + j + s] = ie - io;
  20032. /* jshint maxdepth : false */
  20033. if (j !== l) {
  20034. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  20035. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  20036. rtwdf_ = rx;
  20037. }
  20038. }
  20039. }
  20040. }
  20041. };
  20042. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  20043. var N = Math.max(m, n) | 1;
  20044. var odd = N & 1;
  20045. var i = 0;
  20046. for (N = N / 2 | 0; N; N = N >>> 1) {
  20047. i++;
  20048. }
  20049. return 1 << i + 1 + odd;
  20050. };
  20051. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  20052. if (N <= 1) return;
  20053. for (var i = 0; i < N / 2; i++) {
  20054. var t = rws[i];
  20055. rws[i] = rws[N - i - 1];
  20056. rws[N - i - 1] = t;
  20057. t = iws[i];
  20058. iws[i] = -iws[N - i - 1];
  20059. iws[N - i - 1] = -t;
  20060. }
  20061. };
  20062. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  20063. var carry = 0;
  20064. for (var i = 0; i < N / 2; i++) {
  20065. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  20066. ws[i] = w & 0x3ffffff;
  20067. if (w < 0x4000000) {
  20068. carry = 0;
  20069. } else {
  20070. carry = w / 0x4000000 | 0;
  20071. }
  20072. }
  20073. return ws;
  20074. };
  20075. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  20076. var carry = 0;
  20077. for (var i = 0; i < len; i++) {
  20078. carry = carry + (ws[i] | 0);
  20079. rws[2 * i] = carry & 0x1fff;
  20080. carry = carry >>> 13;
  20081. rws[2 * i + 1] = carry & 0x1fff;
  20082. carry = carry >>> 13;
  20083. }
  20084. // Pad with zeroes
  20085. for (i = 2 * len; i < N; ++i) {
  20086. rws[i] = 0;
  20087. }
  20088. assert(carry === 0);
  20089. assert((carry & ~0x1fff) === 0);
  20090. };
  20091. FFTM.prototype.stub = function stub(N) {
  20092. var ph = new Array(N);
  20093. for (var i = 0; i < N; i++) {
  20094. ph[i] = 0;
  20095. }
  20096. return ph;
  20097. };
  20098. FFTM.prototype.mulp = function mulp(x, y, out) {
  20099. var N = 2 * this.guessLen13b(x.length, y.length);
  20100. var rbt = this.makeRBT(N);
  20101. var _ = this.stub(N);
  20102. var rws = new Array(N);
  20103. var rwst = new Array(N);
  20104. var iwst = new Array(N);
  20105. var nrws = new Array(N);
  20106. var nrwst = new Array(N);
  20107. var niwst = new Array(N);
  20108. var rmws = out.words;
  20109. rmws.length = N;
  20110. this.convert13b(x.words, x.length, rws, N);
  20111. this.convert13b(y.words, y.length, nrws, N);
  20112. this.transform(rws, _, rwst, iwst, N, rbt);
  20113. this.transform(nrws, _, nrwst, niwst, N, rbt);
  20114. for (var i = 0; i < N; i++) {
  20115. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  20116. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  20117. rwst[i] = rx;
  20118. }
  20119. this.conjugate(rwst, iwst, N);
  20120. this.transform(rwst, iwst, rmws, _, N, rbt);
  20121. this.conjugate(rmws, _, N);
  20122. this.normalize13b(rmws, N);
  20123. out.negative = x.negative ^ y.negative;
  20124. out.length = x.length + y.length;
  20125. return out.strip();
  20126. };
  20127. // Multiply `this` by `num`
  20128. BN.prototype.mul = function mul(num) {
  20129. var out = new BN(null);
  20130. out.words = new Array(this.length + num.length);
  20131. return this.mulTo(num, out);
  20132. };
  20133. // Multiply employing FFT
  20134. BN.prototype.mulf = function mulf(num) {
  20135. var out = new BN(null);
  20136. out.words = new Array(this.length + num.length);
  20137. return jumboMulTo(this, num, out);
  20138. };
  20139. // In-place Multiplication
  20140. BN.prototype.imul = function imul(num) {
  20141. return this.clone().mulTo(num, this);
  20142. };
  20143. BN.prototype.imuln = function imuln(num) {
  20144. assert(typeof num === 'number');
  20145. assert(num < 0x4000000);
  20146. // Carry
  20147. var carry = 0;
  20148. for (var i = 0; i < this.length; i++) {
  20149. var w = (this.words[i] | 0) * num;
  20150. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  20151. carry >>= 26;
  20152. carry += w / 0x4000000 | 0;
  20153. // NOTE: lo is 27bit maximum
  20154. carry += lo >>> 26;
  20155. this.words[i] = lo & 0x3ffffff;
  20156. }
  20157. if (carry !== 0) {
  20158. this.words[i] = carry;
  20159. this.length++;
  20160. }
  20161. return this;
  20162. };
  20163. BN.prototype.muln = function muln(num) {
  20164. return this.clone().imuln(num);
  20165. };
  20166. // `this` * `this`
  20167. BN.prototype.sqr = function sqr() {
  20168. return this.mul(this);
  20169. };
  20170. // `this` * `this` in-place
  20171. BN.prototype.isqr = function isqr() {
  20172. return this.imul(this.clone());
  20173. };
  20174. // Math.pow(`this`, `num`)
  20175. BN.prototype.pow = function pow(num) {
  20176. var w = toBitArray(num);
  20177. if (w.length === 0) return new BN(1);
  20178. // Skip leading zeroes
  20179. var res = this;
  20180. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  20181. if (w[i] !== 0) break;
  20182. }
  20183. if (++i < w.length) {
  20184. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  20185. if (w[i] === 0) continue;
  20186. res = res.mul(q);
  20187. }
  20188. }
  20189. return res;
  20190. };
  20191. // Shift-left in-place
  20192. BN.prototype.iushln = function iushln(bits) {
  20193. assert(typeof bits === 'number' && bits >= 0);
  20194. var r = bits % 26;
  20195. var s = (bits - r) / 26;
  20196. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  20197. var i;
  20198. if (r !== 0) {
  20199. var carry = 0;
  20200. for (i = 0; i < this.length; i++) {
  20201. var newCarry = this.words[i] & carryMask;
  20202. var c = (this.words[i] | 0) - newCarry << r;
  20203. this.words[i] = c | carry;
  20204. carry = newCarry >>> 26 - r;
  20205. }
  20206. if (carry) {
  20207. this.words[i] = carry;
  20208. this.length++;
  20209. }
  20210. }
  20211. if (s !== 0) {
  20212. for (i = this.length - 1; i >= 0; i--) {
  20213. this.words[i + s] = this.words[i];
  20214. }
  20215. for (i = 0; i < s; i++) {
  20216. this.words[i] = 0;
  20217. }
  20218. this.length += s;
  20219. }
  20220. return this.strip();
  20221. };
  20222. BN.prototype.ishln = function ishln(bits) {
  20223. // TODO(indutny): implement me
  20224. assert(this.negative === 0);
  20225. return this.iushln(bits);
  20226. };
  20227. // Shift-right in-place
  20228. // NOTE: `hint` is a lowest bit before trailing zeroes
  20229. // NOTE: if `extended` is present - it will be filled with destroyed bits
  20230. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  20231. assert(typeof bits === 'number' && bits >= 0);
  20232. var h;
  20233. if (hint) {
  20234. h = (hint - hint % 26) / 26;
  20235. } else {
  20236. h = 0;
  20237. }
  20238. var r = bits % 26;
  20239. var s = Math.min((bits - r) / 26, this.length);
  20240. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  20241. var maskedWords = extended;
  20242. h -= s;
  20243. h = Math.max(0, h);
  20244. // Extended mode, copy masked part
  20245. if (maskedWords) {
  20246. for (var i = 0; i < s; i++) {
  20247. maskedWords.words[i] = this.words[i];
  20248. }
  20249. maskedWords.length = s;
  20250. }
  20251. if (s === 0) {
  20252. // No-op, we should not move anything at all
  20253. } else if (this.length > s) {
  20254. this.length -= s;
  20255. for (i = 0; i < this.length; i++) {
  20256. this.words[i] = this.words[i + s];
  20257. }
  20258. } else {
  20259. this.words[0] = 0;
  20260. this.length = 1;
  20261. }
  20262. var carry = 0;
  20263. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  20264. var word = this.words[i] | 0;
  20265. this.words[i] = carry << 26 - r | word >>> r;
  20266. carry = word & mask;
  20267. }
  20268. // Push carried bits as a mask
  20269. if (maskedWords && carry !== 0) {
  20270. maskedWords.words[maskedWords.length++] = carry;
  20271. }
  20272. if (this.length === 0) {
  20273. this.words[0] = 0;
  20274. this.length = 1;
  20275. }
  20276. return this.strip();
  20277. };
  20278. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  20279. // TODO(indutny): implement me
  20280. assert(this.negative === 0);
  20281. return this.iushrn(bits, hint, extended);
  20282. };
  20283. // Shift-left
  20284. BN.prototype.shln = function shln(bits) {
  20285. return this.clone().ishln(bits);
  20286. };
  20287. BN.prototype.ushln = function ushln(bits) {
  20288. return this.clone().iushln(bits);
  20289. };
  20290. // Shift-right
  20291. BN.prototype.shrn = function shrn(bits) {
  20292. return this.clone().ishrn(bits);
  20293. };
  20294. BN.prototype.ushrn = function ushrn(bits) {
  20295. return this.clone().iushrn(bits);
  20296. };
  20297. // Test if n bit is set
  20298. BN.prototype.testn = function testn(bit) {
  20299. assert(typeof bit === 'number' && bit >= 0);
  20300. var r = bit % 26;
  20301. var s = (bit - r) / 26;
  20302. var q = 1 << r;
  20303. // Fast case: bit is much higher than all existing words
  20304. if (this.length <= s) return false;
  20305. // Check bit and return
  20306. var w = this.words[s];
  20307. return !!(w & q);
  20308. };
  20309. // Return only lowers bits of number (in-place)
  20310. BN.prototype.imaskn = function imaskn(bits) {
  20311. assert(typeof bits === 'number' && bits >= 0);
  20312. var r = bits % 26;
  20313. var s = (bits - r) / 26;
  20314. assert(this.negative === 0, 'imaskn works only with positive numbers');
  20315. if (this.length <= s) {
  20316. return this;
  20317. }
  20318. if (r !== 0) {
  20319. s++;
  20320. }
  20321. this.length = Math.min(s, this.length);
  20322. if (r !== 0) {
  20323. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  20324. this.words[this.length - 1] &= mask;
  20325. }
  20326. return this.strip();
  20327. };
  20328. // Return only lowers bits of number
  20329. BN.prototype.maskn = function maskn(bits) {
  20330. return this.clone().imaskn(bits);
  20331. };
  20332. // Add plain number `num` to `this`
  20333. BN.prototype.iaddn = function iaddn(num) {
  20334. assert(typeof num === 'number');
  20335. assert(num < 0x4000000);
  20336. if (num < 0) return this.isubn(-num);
  20337. // Possible sign change
  20338. if (this.negative !== 0) {
  20339. if (this.length === 1 && (this.words[0] | 0) < num) {
  20340. this.words[0] = num - (this.words[0] | 0);
  20341. this.negative = 0;
  20342. return this;
  20343. }
  20344. this.negative = 0;
  20345. this.isubn(num);
  20346. this.negative = 1;
  20347. return this;
  20348. }
  20349. // Add without checks
  20350. return this._iaddn(num);
  20351. };
  20352. BN.prototype._iaddn = function _iaddn(num) {
  20353. this.words[0] += num;
  20354. // Carry
  20355. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  20356. this.words[i] -= 0x4000000;
  20357. if (i === this.length - 1) {
  20358. this.words[i + 1] = 1;
  20359. } else {
  20360. this.words[i + 1]++;
  20361. }
  20362. }
  20363. this.length = Math.max(this.length, i + 1);
  20364. return this;
  20365. };
  20366. // Subtract plain number `num` from `this`
  20367. BN.prototype.isubn = function isubn(num) {
  20368. assert(typeof num === 'number');
  20369. assert(num < 0x4000000);
  20370. if (num < 0) return this.iaddn(-num);
  20371. if (this.negative !== 0) {
  20372. this.negative = 0;
  20373. this.iaddn(num);
  20374. this.negative = 1;
  20375. return this;
  20376. }
  20377. this.words[0] -= num;
  20378. if (this.length === 1 && this.words[0] < 0) {
  20379. this.words[0] = -this.words[0];
  20380. this.negative = 1;
  20381. } else {
  20382. // Carry
  20383. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  20384. this.words[i] += 0x4000000;
  20385. this.words[i + 1] -= 1;
  20386. }
  20387. }
  20388. return this.strip();
  20389. };
  20390. BN.prototype.addn = function addn(num) {
  20391. return this.clone().iaddn(num);
  20392. };
  20393. BN.prototype.subn = function subn(num) {
  20394. return this.clone().isubn(num);
  20395. };
  20396. BN.prototype.iabs = function iabs() {
  20397. this.negative = 0;
  20398. return this;
  20399. };
  20400. BN.prototype.abs = function abs() {
  20401. return this.clone().iabs();
  20402. };
  20403. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  20404. var len = num.length + shift;
  20405. var i;
  20406. this._expand(len);
  20407. var w;
  20408. var carry = 0;
  20409. for (i = 0; i < num.length; i++) {
  20410. w = (this.words[i + shift] | 0) + carry;
  20411. var right = (num.words[i] | 0) * mul;
  20412. w -= right & 0x3ffffff;
  20413. carry = (w >> 26) - (right / 0x4000000 | 0);
  20414. this.words[i + shift] = w & 0x3ffffff;
  20415. }
  20416. for (; i < this.length - shift; i++) {
  20417. w = (this.words[i + shift] | 0) + carry;
  20418. carry = w >> 26;
  20419. this.words[i + shift] = w & 0x3ffffff;
  20420. }
  20421. if (carry === 0) return this.strip();
  20422. // Subtraction overflow
  20423. assert(carry === -1);
  20424. carry = 0;
  20425. for (i = 0; i < this.length; i++) {
  20426. w = -(this.words[i] | 0) + carry;
  20427. carry = w >> 26;
  20428. this.words[i] = w & 0x3ffffff;
  20429. }
  20430. this.negative = 1;
  20431. return this.strip();
  20432. };
  20433. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  20434. var shift = this.length - num.length;
  20435. var a = this.clone();
  20436. var b = num;
  20437. // Normalize
  20438. var bhi = b.words[b.length - 1] | 0;
  20439. var bhiBits = this._countBits(bhi);
  20440. shift = 26 - bhiBits;
  20441. if (shift !== 0) {
  20442. b = b.ushln(shift);
  20443. a.iushln(shift);
  20444. bhi = b.words[b.length - 1] | 0;
  20445. }
  20446. // Initialize quotient
  20447. var m = a.length - b.length;
  20448. var q;
  20449. if (mode !== 'mod') {
  20450. q = new BN(null);
  20451. q.length = m + 1;
  20452. q.words = new Array(q.length);
  20453. for (var i = 0; i < q.length; i++) {
  20454. q.words[i] = 0;
  20455. }
  20456. }
  20457. var diff = a.clone()._ishlnsubmul(b, 1, m);
  20458. if (diff.negative === 0) {
  20459. a = diff;
  20460. if (q) {
  20461. q.words[m] = 1;
  20462. }
  20463. }
  20464. for (var j = m - 1; j >= 0; j--) {
  20465. var qj = (a.words[b.length + j] | 0) * 0x4000000 + (a.words[b.length + j - 1] | 0);
  20466. // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  20467. // (0x7ffffff)
  20468. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  20469. a._ishlnsubmul(b, qj, j);
  20470. while (a.negative !== 0) {
  20471. qj--;
  20472. a.negative = 0;
  20473. a._ishlnsubmul(b, 1, j);
  20474. if (!a.isZero()) {
  20475. a.negative ^= 1;
  20476. }
  20477. }
  20478. if (q) {
  20479. q.words[j] = qj;
  20480. }
  20481. }
  20482. if (q) {
  20483. q.strip();
  20484. }
  20485. a.strip();
  20486. // Denormalize
  20487. if (mode !== 'div' && shift !== 0) {
  20488. a.iushrn(shift);
  20489. }
  20490. return {
  20491. div: q || null,
  20492. mod: a
  20493. };
  20494. };
  20495. // NOTE: 1) `mode` can be set to `mod` to request mod only,
  20496. // to `div` to request div only, or be absent to
  20497. // request both div & mod
  20498. // 2) `positive` is true if unsigned mod is requested
  20499. BN.prototype.divmod = function divmod(num, mode, positive) {
  20500. assert(!num.isZero());
  20501. if (this.isZero()) {
  20502. return {
  20503. div: new BN(0),
  20504. mod: new BN(0)
  20505. };
  20506. }
  20507. var div, mod, res;
  20508. if (this.negative !== 0 && num.negative === 0) {
  20509. res = this.neg().divmod(num, mode);
  20510. if (mode !== 'mod') {
  20511. div = res.div.neg();
  20512. }
  20513. if (mode !== 'div') {
  20514. mod = res.mod.neg();
  20515. if (positive && mod.negative !== 0) {
  20516. mod.iadd(num);
  20517. }
  20518. }
  20519. return {
  20520. div: div,
  20521. mod: mod
  20522. };
  20523. }
  20524. if (this.negative === 0 && num.negative !== 0) {
  20525. res = this.divmod(num.neg(), mode);
  20526. if (mode !== 'mod') {
  20527. div = res.div.neg();
  20528. }
  20529. return {
  20530. div: div,
  20531. mod: res.mod
  20532. };
  20533. }
  20534. if ((this.negative & num.negative) !== 0) {
  20535. res = this.neg().divmod(num.neg(), mode);
  20536. if (mode !== 'div') {
  20537. mod = res.mod.neg();
  20538. if (positive && mod.negative !== 0) {
  20539. mod.isub(num);
  20540. }
  20541. }
  20542. return {
  20543. div: res.div,
  20544. mod: mod
  20545. };
  20546. }
  20547. // Both numbers are positive at this point
  20548. // Strip both numbers to approximate shift value
  20549. if (num.length > this.length || this.cmp(num) < 0) {
  20550. return {
  20551. div: new BN(0),
  20552. mod: this
  20553. };
  20554. }
  20555. // Very short reduction
  20556. if (num.length === 1) {
  20557. if (mode === 'div') {
  20558. return {
  20559. div: this.divn(num.words[0]),
  20560. mod: null
  20561. };
  20562. }
  20563. if (mode === 'mod') {
  20564. return {
  20565. div: null,
  20566. mod: new BN(this.modn(num.words[0]))
  20567. };
  20568. }
  20569. return {
  20570. div: this.divn(num.words[0]),
  20571. mod: new BN(this.modn(num.words[0]))
  20572. };
  20573. }
  20574. return this._wordDiv(num, mode);
  20575. };
  20576. // Find `this` / `num`
  20577. BN.prototype.div = function div(num) {
  20578. return this.divmod(num, 'div', false).div;
  20579. };
  20580. // Find `this` % `num`
  20581. BN.prototype.mod = function mod(num) {
  20582. return this.divmod(num, 'mod', false).mod;
  20583. };
  20584. BN.prototype.umod = function umod(num) {
  20585. return this.divmod(num, 'mod', true).mod;
  20586. };
  20587. // Find Round(`this` / `num`)
  20588. BN.prototype.divRound = function divRound(num) {
  20589. var dm = this.divmod(num);
  20590. // Fast case - exact division
  20591. if (dm.mod.isZero()) return dm.div;
  20592. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  20593. var half = num.ushrn(1);
  20594. var r2 = num.andln(1);
  20595. var cmp = mod.cmp(half);
  20596. // Round down
  20597. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
  20598. // Round up
  20599. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  20600. };
  20601. BN.prototype.modn = function modn(num) {
  20602. assert(num <= 0x3ffffff);
  20603. var p = (1 << 26) % num;
  20604. var acc = 0;
  20605. for (var i = this.length - 1; i >= 0; i--) {
  20606. acc = (p * acc + (this.words[i] | 0)) % num;
  20607. }
  20608. return acc;
  20609. };
  20610. // In-place division by number
  20611. BN.prototype.idivn = function idivn(num) {
  20612. assert(num <= 0x3ffffff);
  20613. var carry = 0;
  20614. for (var i = this.length - 1; i >= 0; i--) {
  20615. var w = (this.words[i] | 0) + carry * 0x4000000;
  20616. this.words[i] = w / num | 0;
  20617. carry = w % num;
  20618. }
  20619. return this.strip();
  20620. };
  20621. BN.prototype.divn = function divn(num) {
  20622. return this.clone().idivn(num);
  20623. };
  20624. BN.prototype.egcd = function egcd(p) {
  20625. assert(p.negative === 0);
  20626. assert(!p.isZero());
  20627. var x = this;
  20628. var y = p.clone();
  20629. if (x.negative !== 0) {
  20630. x = x.umod(p);
  20631. } else {
  20632. x = x.clone();
  20633. }
  20634. // A * x + B * y = x
  20635. var A = new BN(1);
  20636. var B = new BN(0);
  20637. // C * x + D * y = y
  20638. var C = new BN(0);
  20639. var D = new BN(1);
  20640. var g = 0;
  20641. while (x.isEven() && y.isEven()) {
  20642. x.iushrn(1);
  20643. y.iushrn(1);
  20644. ++g;
  20645. }
  20646. var yp = y.clone();
  20647. var xp = x.clone();
  20648. while (!x.isZero()) {
  20649. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  20650. if (i > 0) {
  20651. x.iushrn(i);
  20652. while (i-- > 0) {
  20653. if (A.isOdd() || B.isOdd()) {
  20654. A.iadd(yp);
  20655. B.isub(xp);
  20656. }
  20657. A.iushrn(1);
  20658. B.iushrn(1);
  20659. }
  20660. }
  20661. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  20662. if (j > 0) {
  20663. y.iushrn(j);
  20664. while (j-- > 0) {
  20665. if (C.isOdd() || D.isOdd()) {
  20666. C.iadd(yp);
  20667. D.isub(xp);
  20668. }
  20669. C.iushrn(1);
  20670. D.iushrn(1);
  20671. }
  20672. }
  20673. if (x.cmp(y) >= 0) {
  20674. x.isub(y);
  20675. A.isub(C);
  20676. B.isub(D);
  20677. } else {
  20678. y.isub(x);
  20679. C.isub(A);
  20680. D.isub(B);
  20681. }
  20682. }
  20683. return {
  20684. a: C,
  20685. b: D,
  20686. gcd: y.iushln(g)
  20687. };
  20688. };
  20689. // This is reduced incarnation of the binary EEA
  20690. // above, designated to invert members of the
  20691. // _prime_ fields F(p) at a maximal speed
  20692. BN.prototype._invmp = function _invmp(p) {
  20693. assert(p.negative === 0);
  20694. assert(!p.isZero());
  20695. var a = this;
  20696. var b = p.clone();
  20697. if (a.negative !== 0) {
  20698. a = a.umod(p);
  20699. } else {
  20700. a = a.clone();
  20701. }
  20702. var x1 = new BN(1);
  20703. var x2 = new BN(0);
  20704. var delta = b.clone();
  20705. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  20706. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  20707. if (i > 0) {
  20708. a.iushrn(i);
  20709. while (i-- > 0) {
  20710. if (x1.isOdd()) {
  20711. x1.iadd(delta);
  20712. }
  20713. x1.iushrn(1);
  20714. }
  20715. }
  20716. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  20717. if (j > 0) {
  20718. b.iushrn(j);
  20719. while (j-- > 0) {
  20720. if (x2.isOdd()) {
  20721. x2.iadd(delta);
  20722. }
  20723. x2.iushrn(1);
  20724. }
  20725. }
  20726. if (a.cmp(b) >= 0) {
  20727. a.isub(b);
  20728. x1.isub(x2);
  20729. } else {
  20730. b.isub(a);
  20731. x2.isub(x1);
  20732. }
  20733. }
  20734. var res;
  20735. if (a.cmpn(1) === 0) {
  20736. res = x1;
  20737. } else {
  20738. res = x2;
  20739. }
  20740. if (res.cmpn(0) < 0) {
  20741. res.iadd(p);
  20742. }
  20743. return res;
  20744. };
  20745. BN.prototype.gcd = function gcd(num) {
  20746. if (this.isZero()) return num.abs();
  20747. if (num.isZero()) return this.abs();
  20748. var a = this.clone();
  20749. var b = num.clone();
  20750. a.negative = 0;
  20751. b.negative = 0;
  20752. // Remove common factor of two
  20753. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  20754. a.iushrn(1);
  20755. b.iushrn(1);
  20756. }
  20757. do {
  20758. while (a.isEven()) {
  20759. a.iushrn(1);
  20760. }
  20761. while (b.isEven()) {
  20762. b.iushrn(1);
  20763. }
  20764. var r = a.cmp(b);
  20765. if (r < 0) {
  20766. // Swap `a` and `b` to make `a` always bigger than `b`
  20767. var t = a;
  20768. a = b;
  20769. b = t;
  20770. } else if (r === 0 || b.cmpn(1) === 0) {
  20771. break;
  20772. }
  20773. a.isub(b);
  20774. } while (true);
  20775. return b.iushln(shift);
  20776. };
  20777. // Invert number in the field F(num)
  20778. BN.prototype.invm = function invm(num) {
  20779. return this.egcd(num).a.umod(num);
  20780. };
  20781. BN.prototype.isEven = function isEven() {
  20782. return (this.words[0] & 1) === 0;
  20783. };
  20784. BN.prototype.isOdd = function isOdd() {
  20785. return (this.words[0] & 1) === 1;
  20786. };
  20787. // And first word and num
  20788. BN.prototype.andln = function andln(num) {
  20789. return this.words[0] & num;
  20790. };
  20791. // Increment at the bit position in-line
  20792. BN.prototype.bincn = function bincn(bit) {
  20793. assert(typeof bit === 'number');
  20794. var r = bit % 26;
  20795. var s = (bit - r) / 26;
  20796. var q = 1 << r;
  20797. // Fast case: bit is much higher than all existing words
  20798. if (this.length <= s) {
  20799. this._expand(s + 1);
  20800. this.words[s] |= q;
  20801. return this;
  20802. }
  20803. // Add bit and propagate, if needed
  20804. var carry = q;
  20805. for (var i = s; carry !== 0 && i < this.length; i++) {
  20806. var w = this.words[i] | 0;
  20807. w += carry;
  20808. carry = w >>> 26;
  20809. w &= 0x3ffffff;
  20810. this.words[i] = w;
  20811. }
  20812. if (carry !== 0) {
  20813. this.words[i] = carry;
  20814. this.length++;
  20815. }
  20816. return this;
  20817. };
  20818. BN.prototype.isZero = function isZero() {
  20819. return this.length === 1 && this.words[0] === 0;
  20820. };
  20821. BN.prototype.cmpn = function cmpn(num) {
  20822. var negative = num < 0;
  20823. if (this.negative !== 0 && !negative) return -1;
  20824. if (this.negative === 0 && negative) return 1;
  20825. this.strip();
  20826. var res;
  20827. if (this.length > 1) {
  20828. res = 1;
  20829. } else {
  20830. if (negative) {
  20831. num = -num;
  20832. }
  20833. assert(num <= 0x3ffffff, 'Number is too big');
  20834. var w = this.words[0] | 0;
  20835. res = w === num ? 0 : w < num ? -1 : 1;
  20836. }
  20837. if (this.negative !== 0) return -res | 0;
  20838. return res;
  20839. };
  20840. // Compare two numbers and return:
  20841. // 1 - if `this` > `num`
  20842. // 0 - if `this` == `num`
  20843. // -1 - if `this` < `num`
  20844. BN.prototype.cmp = function cmp(num) {
  20845. if (this.negative !== 0 && num.negative === 0) return -1;
  20846. if (this.negative === 0 && num.negative !== 0) return 1;
  20847. var res = this.ucmp(num);
  20848. if (this.negative !== 0) return -res | 0;
  20849. return res;
  20850. };
  20851. // Unsigned comparison
  20852. BN.prototype.ucmp = function ucmp(num) {
  20853. // At this point both numbers have the same sign
  20854. if (this.length > num.length) return 1;
  20855. if (this.length < num.length) return -1;
  20856. var res = 0;
  20857. for (var i = this.length - 1; i >= 0; i--) {
  20858. var a = this.words[i] | 0;
  20859. var b = num.words[i] | 0;
  20860. if (a === b) continue;
  20861. if (a < b) {
  20862. res = -1;
  20863. } else if (a > b) {
  20864. res = 1;
  20865. }
  20866. break;
  20867. }
  20868. return res;
  20869. };
  20870. BN.prototype.gtn = function gtn(num) {
  20871. return this.cmpn(num) === 1;
  20872. };
  20873. BN.prototype.gt = function gt(num) {
  20874. return this.cmp(num) === 1;
  20875. };
  20876. BN.prototype.gten = function gten(num) {
  20877. return this.cmpn(num) >= 0;
  20878. };
  20879. BN.prototype.gte = function gte(num) {
  20880. return this.cmp(num) >= 0;
  20881. };
  20882. BN.prototype.ltn = function ltn(num) {
  20883. return this.cmpn(num) === -1;
  20884. };
  20885. BN.prototype.lt = function lt(num) {
  20886. return this.cmp(num) === -1;
  20887. };
  20888. BN.prototype.lten = function lten(num) {
  20889. return this.cmpn(num) <= 0;
  20890. };
  20891. BN.prototype.lte = function lte(num) {
  20892. return this.cmp(num) <= 0;
  20893. };
  20894. BN.prototype.eqn = function eqn(num) {
  20895. return this.cmpn(num) === 0;
  20896. };
  20897. BN.prototype.eq = function eq(num) {
  20898. return this.cmp(num) === 0;
  20899. };
  20900. //
  20901. // A reduce context, could be using montgomery or something better, depending
  20902. // on the `m` itself.
  20903. //
  20904. BN.red = function red(num) {
  20905. return new Red(num);
  20906. };
  20907. BN.prototype.toRed = function toRed(ctx) {
  20908. assert(!this.red, 'Already a number in reduction context');
  20909. assert(this.negative === 0, 'red works only with positives');
  20910. return ctx.convertTo(this)._forceRed(ctx);
  20911. };
  20912. BN.prototype.fromRed = function fromRed() {
  20913. assert(this.red, 'fromRed works only with numbers in reduction context');
  20914. return this.red.convertFrom(this);
  20915. };
  20916. BN.prototype._forceRed = function _forceRed(ctx) {
  20917. this.red = ctx;
  20918. return this;
  20919. };
  20920. BN.prototype.forceRed = function forceRed(ctx) {
  20921. assert(!this.red, 'Already a number in reduction context');
  20922. return this._forceRed(ctx);
  20923. };
  20924. BN.prototype.redAdd = function redAdd(num) {
  20925. assert(this.red, 'redAdd works only with red numbers');
  20926. return this.red.add(this, num);
  20927. };
  20928. BN.prototype.redIAdd = function redIAdd(num) {
  20929. assert(this.red, 'redIAdd works only with red numbers');
  20930. return this.red.iadd(this, num);
  20931. };
  20932. BN.prototype.redSub = function redSub(num) {
  20933. assert(this.red, 'redSub works only with red numbers');
  20934. return this.red.sub(this, num);
  20935. };
  20936. BN.prototype.redISub = function redISub(num) {
  20937. assert(this.red, 'redISub works only with red numbers');
  20938. return this.red.isub(this, num);
  20939. };
  20940. BN.prototype.redShl = function redShl(num) {
  20941. assert(this.red, 'redShl works only with red numbers');
  20942. return this.red.shl(this, num);
  20943. };
  20944. BN.prototype.redMul = function redMul(num) {
  20945. assert(this.red, 'redMul works only with red numbers');
  20946. this.red._verify2(this, num);
  20947. return this.red.mul(this, num);
  20948. };
  20949. BN.prototype.redIMul = function redIMul(num) {
  20950. assert(this.red, 'redMul works only with red numbers');
  20951. this.red._verify2(this, num);
  20952. return this.red.imul(this, num);
  20953. };
  20954. BN.prototype.redSqr = function redSqr() {
  20955. assert(this.red, 'redSqr works only with red numbers');
  20956. this.red._verify1(this);
  20957. return this.red.sqr(this);
  20958. };
  20959. BN.prototype.redISqr = function redISqr() {
  20960. assert(this.red, 'redISqr works only with red numbers');
  20961. this.red._verify1(this);
  20962. return this.red.isqr(this);
  20963. };
  20964. // Square root over p
  20965. BN.prototype.redSqrt = function redSqrt() {
  20966. assert(this.red, 'redSqrt works only with red numbers');
  20967. this.red._verify1(this);
  20968. return this.red.sqrt(this);
  20969. };
  20970. BN.prototype.redInvm = function redInvm() {
  20971. assert(this.red, 'redInvm works only with red numbers');
  20972. this.red._verify1(this);
  20973. return this.red.invm(this);
  20974. };
  20975. // Return negative clone of `this` % `red modulo`
  20976. BN.prototype.redNeg = function redNeg() {
  20977. assert(this.red, 'redNeg works only with red numbers');
  20978. this.red._verify1(this);
  20979. return this.red.neg(this);
  20980. };
  20981. BN.prototype.redPow = function redPow(num) {
  20982. assert(this.red && !num.red, 'redPow(normalNum)');
  20983. this.red._verify1(this);
  20984. return this.red.pow(this, num);
  20985. };
  20986. // Prime numbers with efficient reduction
  20987. var primes = {
  20988. k256: null,
  20989. p224: null,
  20990. p192: null,
  20991. p25519: null
  20992. };
  20993. // Pseudo-Mersenne prime
  20994. function MPrime(name, p) {
  20995. // P = 2 ^ N - K
  20996. this.name = name;
  20997. this.p = new BN(p, 16);
  20998. this.n = this.p.bitLength();
  20999. this.k = new BN(1).iushln(this.n).isub(this.p);
  21000. this.tmp = this._tmp();
  21001. }
  21002. MPrime.prototype._tmp = function _tmp() {
  21003. var tmp = new BN(null);
  21004. tmp.words = new Array(Math.ceil(this.n / 13));
  21005. return tmp;
  21006. };
  21007. MPrime.prototype.ireduce = function ireduce(num) {
  21008. // Assumes that `num` is less than `P^2`
  21009. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  21010. var r = num;
  21011. var rlen;
  21012. do {
  21013. this.split(r, this.tmp);
  21014. r = this.imulK(r);
  21015. r = r.iadd(this.tmp);
  21016. rlen = r.bitLength();
  21017. } while (rlen > this.n);
  21018. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  21019. if (cmp === 0) {
  21020. r.words[0] = 0;
  21021. r.length = 1;
  21022. } else if (cmp > 0) {
  21023. r.isub(this.p);
  21024. } else {
  21025. if (r.strip !== undefined) {
  21026. // r is BN v4 instance
  21027. r.strip();
  21028. } else {
  21029. // r is BN v5 instance
  21030. r._strip();
  21031. }
  21032. }
  21033. return r;
  21034. };
  21035. MPrime.prototype.split = function split(input, out) {
  21036. input.iushrn(this.n, 0, out);
  21037. };
  21038. MPrime.prototype.imulK = function imulK(num) {
  21039. return num.imul(this.k);
  21040. };
  21041. function K256() {
  21042. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  21043. }
  21044. inherits(K256, MPrime);
  21045. K256.prototype.split = function split(input, output) {
  21046. // 256 = 9 * 26 + 22
  21047. var mask = 0x3fffff;
  21048. var outLen = Math.min(input.length, 9);
  21049. for (var i = 0; i < outLen; i++) {
  21050. output.words[i] = input.words[i];
  21051. }
  21052. output.length = outLen;
  21053. if (input.length <= 9) {
  21054. input.words[0] = 0;
  21055. input.length = 1;
  21056. return;
  21057. }
  21058. // Shift by 9 limbs
  21059. var prev = input.words[9];
  21060. output.words[output.length++] = prev & mask;
  21061. for (i = 10; i < input.length; i++) {
  21062. var next = input.words[i] | 0;
  21063. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  21064. prev = next;
  21065. }
  21066. prev >>>= 22;
  21067. input.words[i - 10] = prev;
  21068. if (prev === 0 && input.length > 10) {
  21069. input.length -= 10;
  21070. } else {
  21071. input.length -= 9;
  21072. }
  21073. };
  21074. K256.prototype.imulK = function imulK(num) {
  21075. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  21076. num.words[num.length] = 0;
  21077. num.words[num.length + 1] = 0;
  21078. num.length += 2;
  21079. // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  21080. var lo = 0;
  21081. for (var i = 0; i < num.length; i++) {
  21082. var w = num.words[i] | 0;
  21083. lo += w * 0x3d1;
  21084. num.words[i] = lo & 0x3ffffff;
  21085. lo = w * 0x40 + (lo / 0x4000000 | 0);
  21086. }
  21087. // Fast length reduction
  21088. if (num.words[num.length - 1] === 0) {
  21089. num.length--;
  21090. if (num.words[num.length - 1] === 0) {
  21091. num.length--;
  21092. }
  21093. }
  21094. return num;
  21095. };
  21096. function P224() {
  21097. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  21098. }
  21099. inherits(P224, MPrime);
  21100. function P192() {
  21101. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  21102. }
  21103. inherits(P192, MPrime);
  21104. function P25519() {
  21105. // 2 ^ 255 - 19
  21106. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  21107. }
  21108. inherits(P25519, MPrime);
  21109. P25519.prototype.imulK = function imulK(num) {
  21110. // K = 0x13
  21111. var carry = 0;
  21112. for (var i = 0; i < num.length; i++) {
  21113. var hi = (num.words[i] | 0) * 0x13 + carry;
  21114. var lo = hi & 0x3ffffff;
  21115. hi >>>= 26;
  21116. num.words[i] = lo;
  21117. carry = hi;
  21118. }
  21119. if (carry !== 0) {
  21120. num.words[num.length++] = carry;
  21121. }
  21122. return num;
  21123. };
  21124. // Exported mostly for testing purposes, use plain name instead
  21125. BN._prime = function prime(name) {
  21126. // Cached version of prime
  21127. if (primes[name]) return primes[name];
  21128. var prime;
  21129. if (name === 'k256') {
  21130. prime = new K256();
  21131. } else if (name === 'p224') {
  21132. prime = new P224();
  21133. } else if (name === 'p192') {
  21134. prime = new P192();
  21135. } else if (name === 'p25519') {
  21136. prime = new P25519();
  21137. } else {
  21138. throw new Error('Unknown prime ' + name);
  21139. }
  21140. primes[name] = prime;
  21141. return prime;
  21142. };
  21143. //
  21144. // Base reduction engine
  21145. //
  21146. function Red(m) {
  21147. if (typeof m === 'string') {
  21148. var prime = BN._prime(m);
  21149. this.m = prime.p;
  21150. this.prime = prime;
  21151. } else {
  21152. assert(m.gtn(1), 'modulus must be greater than 1');
  21153. this.m = m;
  21154. this.prime = null;
  21155. }
  21156. }
  21157. Red.prototype._verify1 = function _verify1(a) {
  21158. assert(a.negative === 0, 'red works only with positives');
  21159. assert(a.red, 'red works only with red numbers');
  21160. };
  21161. Red.prototype._verify2 = function _verify2(a, b) {
  21162. assert((a.negative | b.negative) === 0, 'red works only with positives');
  21163. assert(a.red && a.red === b.red, 'red works only with red numbers');
  21164. };
  21165. Red.prototype.imod = function imod(a) {
  21166. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  21167. return a.umod(this.m)._forceRed(this);
  21168. };
  21169. Red.prototype.neg = function neg(a) {
  21170. if (a.isZero()) {
  21171. return a.clone();
  21172. }
  21173. return this.m.sub(a)._forceRed(this);
  21174. };
  21175. Red.prototype.add = function add(a, b) {
  21176. this._verify2(a, b);
  21177. var res = a.add(b);
  21178. if (res.cmp(this.m) >= 0) {
  21179. res.isub(this.m);
  21180. }
  21181. return res._forceRed(this);
  21182. };
  21183. Red.prototype.iadd = function iadd(a, b) {
  21184. this._verify2(a, b);
  21185. var res = a.iadd(b);
  21186. if (res.cmp(this.m) >= 0) {
  21187. res.isub(this.m);
  21188. }
  21189. return res;
  21190. };
  21191. Red.prototype.sub = function sub(a, b) {
  21192. this._verify2(a, b);
  21193. var res = a.sub(b);
  21194. if (res.cmpn(0) < 0) {
  21195. res.iadd(this.m);
  21196. }
  21197. return res._forceRed(this);
  21198. };
  21199. Red.prototype.isub = function isub(a, b) {
  21200. this._verify2(a, b);
  21201. var res = a.isub(b);
  21202. if (res.cmpn(0) < 0) {
  21203. res.iadd(this.m);
  21204. }
  21205. return res;
  21206. };
  21207. Red.prototype.shl = function shl(a, num) {
  21208. this._verify1(a);
  21209. return this.imod(a.ushln(num));
  21210. };
  21211. Red.prototype.imul = function imul(a, b) {
  21212. this._verify2(a, b);
  21213. return this.imod(a.imul(b));
  21214. };
  21215. Red.prototype.mul = function mul(a, b) {
  21216. this._verify2(a, b);
  21217. return this.imod(a.mul(b));
  21218. };
  21219. Red.prototype.isqr = function isqr(a) {
  21220. return this.imul(a, a.clone());
  21221. };
  21222. Red.prototype.sqr = function sqr(a) {
  21223. return this.mul(a, a);
  21224. };
  21225. Red.prototype.sqrt = function sqrt(a) {
  21226. if (a.isZero()) return a.clone();
  21227. var mod3 = this.m.andln(3);
  21228. assert(mod3 % 2 === 1);
  21229. // Fast case
  21230. if (mod3 === 3) {
  21231. var pow = this.m.add(new BN(1)).iushrn(2);
  21232. return this.pow(a, pow);
  21233. }
  21234. // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  21235. //
  21236. // Find Q and S, that Q * 2 ^ S = (P - 1)
  21237. var q = this.m.subn(1);
  21238. var s = 0;
  21239. while (!q.isZero() && q.andln(1) === 0) {
  21240. s++;
  21241. q.iushrn(1);
  21242. }
  21243. assert(!q.isZero());
  21244. var one = new BN(1).toRed(this);
  21245. var nOne = one.redNeg();
  21246. // Find quadratic non-residue
  21247. // NOTE: Max is such because of generalized Riemann hypothesis.
  21248. var lpow = this.m.subn(1).iushrn(1);
  21249. var z = this.m.bitLength();
  21250. z = new BN(2 * z * z).toRed(this);
  21251. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  21252. z.redIAdd(nOne);
  21253. }
  21254. var c = this.pow(z, q);
  21255. var r = this.pow(a, q.addn(1).iushrn(1));
  21256. var t = this.pow(a, q);
  21257. var m = s;
  21258. while (t.cmp(one) !== 0) {
  21259. var tmp = t;
  21260. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  21261. tmp = tmp.redSqr();
  21262. }
  21263. assert(i < m);
  21264. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  21265. r = r.redMul(b);
  21266. c = b.redSqr();
  21267. t = t.redMul(c);
  21268. m = i;
  21269. }
  21270. return r;
  21271. };
  21272. Red.prototype.invm = function invm(a) {
  21273. var inv = a._invmp(this.m);
  21274. if (inv.negative !== 0) {
  21275. inv.negative = 0;
  21276. return this.imod(inv).redNeg();
  21277. } else {
  21278. return this.imod(inv);
  21279. }
  21280. };
  21281. Red.prototype.pow = function pow(a, num) {
  21282. if (num.isZero()) return new BN(1).toRed(this);
  21283. if (num.cmpn(1) === 0) return a.clone();
  21284. var windowSize = 4;
  21285. var wnd = new Array(1 << windowSize);
  21286. wnd[0] = new BN(1).toRed(this);
  21287. wnd[1] = a;
  21288. for (var i = 2; i < wnd.length; i++) {
  21289. wnd[i] = this.mul(wnd[i - 1], a);
  21290. }
  21291. var res = wnd[0];
  21292. var current = 0;
  21293. var currentLen = 0;
  21294. var start = num.bitLength() % 26;
  21295. if (start === 0) {
  21296. start = 26;
  21297. }
  21298. for (i = num.length - 1; i >= 0; i--) {
  21299. var word = num.words[i];
  21300. for (var j = start - 1; j >= 0; j--) {
  21301. var bit = word >> j & 1;
  21302. if (res !== wnd[0]) {
  21303. res = this.sqr(res);
  21304. }
  21305. if (bit === 0 && current === 0) {
  21306. currentLen = 0;
  21307. continue;
  21308. }
  21309. current <<= 1;
  21310. current |= bit;
  21311. currentLen++;
  21312. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  21313. res = this.mul(res, wnd[current]);
  21314. currentLen = 0;
  21315. current = 0;
  21316. }
  21317. start = 26;
  21318. }
  21319. return res;
  21320. };
  21321. Red.prototype.convertTo = function convertTo(num) {
  21322. var r = num.umod(this.m);
  21323. return r === num ? r.clone() : r;
  21324. };
  21325. Red.prototype.convertFrom = function convertFrom(num) {
  21326. var res = num.clone();
  21327. res.red = null;
  21328. return res;
  21329. };
  21330. //
  21331. // Montgomery method engine
  21332. //
  21333. BN.mont = function mont(num) {
  21334. return new Mont(num);
  21335. };
  21336. function Mont(m) {
  21337. Red.call(this, m);
  21338. this.shift = this.m.bitLength();
  21339. if (this.shift % 26 !== 0) {
  21340. this.shift += 26 - this.shift % 26;
  21341. }
  21342. this.r = new BN(1).iushln(this.shift);
  21343. this.r2 = this.imod(this.r.sqr());
  21344. this.rinv = this.r._invmp(this.m);
  21345. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  21346. this.minv = this.minv.umod(this.r);
  21347. this.minv = this.r.sub(this.minv);
  21348. }
  21349. inherits(Mont, Red);
  21350. Mont.prototype.convertTo = function convertTo(num) {
  21351. return this.imod(num.ushln(this.shift));
  21352. };
  21353. Mont.prototype.convertFrom = function convertFrom(num) {
  21354. var r = this.imod(num.mul(this.rinv));
  21355. r.red = null;
  21356. return r;
  21357. };
  21358. Mont.prototype.imul = function imul(a, b) {
  21359. if (a.isZero() || b.isZero()) {
  21360. a.words[0] = 0;
  21361. a.length = 1;
  21362. return a;
  21363. }
  21364. var t = a.imul(b);
  21365. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  21366. var u = t.isub(c).iushrn(this.shift);
  21367. var res = u;
  21368. if (u.cmp(this.m) >= 0) {
  21369. res = u.isub(this.m);
  21370. } else if (u.cmpn(0) < 0) {
  21371. res = u.iadd(this.m);
  21372. }
  21373. return res._forceRed(this);
  21374. };
  21375. Mont.prototype.mul = function mul(a, b) {
  21376. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  21377. var t = a.mul(b);
  21378. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  21379. var u = t.isub(c).iushrn(this.shift);
  21380. var res = u;
  21381. if (u.cmp(this.m) >= 0) {
  21382. res = u.isub(this.m);
  21383. } else if (u.cmpn(0) < 0) {
  21384. res = u.iadd(this.m);
  21385. }
  21386. return res._forceRed(this);
  21387. };
  21388. Mont.prototype.invm = function invm(a) {
  21389. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  21390. var res = this.imod(a._invmp(this.m).mul(this.r2));
  21391. return res._forceRed(this);
  21392. };
  21393. })(typeof module === 'undefined' || module, void 0);
  21394. },{"buffer":188}],185:[function(require,module,exports){
  21395. 'use strict';
  21396. exports.byteLength = byteLength;
  21397. exports.toByteArray = toByteArray;
  21398. exports.fromByteArray = fromByteArray;
  21399. var lookup = [];
  21400. var revLookup = [];
  21401. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  21402. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  21403. for (var i = 0, len = code.length; i < len; ++i) {
  21404. lookup[i] = code[i];
  21405. revLookup[code.charCodeAt(i)] = i;
  21406. }
  21407. // Support decoding URL-safe base64 strings, as Node.js does.
  21408. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  21409. revLookup['-'.charCodeAt(0)] = 62;
  21410. revLookup['_'.charCodeAt(0)] = 63;
  21411. function getLens(b64) {
  21412. var len = b64.length;
  21413. if (len % 4 > 0) {
  21414. throw new Error('Invalid string. Length must be a multiple of 4');
  21415. }
  21416. // Trim off extra bytes after placeholder bytes are found
  21417. // See: https://github.com/beatgammit/base64-js/issues/42
  21418. var validLen = b64.indexOf('=');
  21419. if (validLen === -1) validLen = len;
  21420. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  21421. return [validLen, placeHoldersLen];
  21422. }
  21423. // base64 is 4/3 + up to two characters of the original data
  21424. function byteLength(b64) {
  21425. var lens = getLens(b64);
  21426. var validLen = lens[0];
  21427. var placeHoldersLen = lens[1];
  21428. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  21429. }
  21430. function _byteLength(b64, validLen, placeHoldersLen) {
  21431. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  21432. }
  21433. function toByteArray(b64) {
  21434. var tmp;
  21435. var lens = getLens(b64);
  21436. var validLen = lens[0];
  21437. var placeHoldersLen = lens[1];
  21438. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  21439. var curByte = 0;
  21440. // if there are placeholders, only get up to the last complete 4 chars
  21441. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  21442. var i;
  21443. for (i = 0; i < len; i += 4) {
  21444. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  21445. arr[curByte++] = tmp >> 16 & 0xFF;
  21446. arr[curByte++] = tmp >> 8 & 0xFF;
  21447. arr[curByte++] = tmp & 0xFF;
  21448. }
  21449. if (placeHoldersLen === 2) {
  21450. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  21451. arr[curByte++] = tmp & 0xFF;
  21452. }
  21453. if (placeHoldersLen === 1) {
  21454. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  21455. arr[curByte++] = tmp >> 8 & 0xFF;
  21456. arr[curByte++] = tmp & 0xFF;
  21457. }
  21458. return arr;
  21459. }
  21460. function tripletToBase64(num) {
  21461. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  21462. }
  21463. function encodeChunk(uint8, start, end) {
  21464. var tmp;
  21465. var output = [];
  21466. for (var i = start; i < end; i += 3) {
  21467. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  21468. output.push(tripletToBase64(tmp));
  21469. }
  21470. return output.join('');
  21471. }
  21472. function fromByteArray(uint8) {
  21473. var tmp;
  21474. var len = uint8.length;
  21475. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  21476. var parts = [];
  21477. var maxChunkLength = 16383; // must be multiple of 3
  21478. // go through the array every three bytes, we'll deal with trailing stuff later
  21479. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  21480. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  21481. }
  21482. // pad the end with zeros, but make sure to not forget the extra bytes
  21483. if (extraBytes === 1) {
  21484. tmp = uint8[len - 1];
  21485. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  21486. } else if (extraBytes === 2) {
  21487. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  21488. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  21489. }
  21490. return parts.join('');
  21491. }
  21492. },{}],186:[function(require,module,exports){
  21493. "use strict";
  21494. (function (module, exports) {
  21495. 'use strict';
  21496. // Utils
  21497. function assert(val, msg) {
  21498. if (!val) throw new Error(msg || 'Assertion failed');
  21499. }
  21500. // Could use `inherits` module, but don't want to move from single file
  21501. // architecture yet.
  21502. function inherits(ctor, superCtor) {
  21503. ctor.super_ = superCtor;
  21504. var TempCtor = function () {};
  21505. TempCtor.prototype = superCtor.prototype;
  21506. ctor.prototype = new TempCtor();
  21507. ctor.prototype.constructor = ctor;
  21508. }
  21509. // BN
  21510. function BN(number, base, endian) {
  21511. if (BN.isBN(number)) {
  21512. return number;
  21513. }
  21514. this.negative = 0;
  21515. this.words = null;
  21516. this.length = 0;
  21517. // Reduction context
  21518. this.red = null;
  21519. if (number !== null) {
  21520. if (base === 'le' || base === 'be') {
  21521. endian = base;
  21522. base = 10;
  21523. }
  21524. this._init(number || 0, base || 10, endian || 'be');
  21525. }
  21526. }
  21527. if (typeof module === 'object') {
  21528. module.exports = BN;
  21529. } else {
  21530. exports.BN = BN;
  21531. }
  21532. BN.BN = BN;
  21533. BN.wordSize = 26;
  21534. var Buffer;
  21535. try {
  21536. if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
  21537. Buffer = window.Buffer;
  21538. } else {
  21539. Buffer = require('buffer').Buffer;
  21540. }
  21541. } catch (e) {}
  21542. BN.isBN = function isBN(num) {
  21543. if (num instanceof BN) {
  21544. return true;
  21545. }
  21546. return num !== null && typeof num === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  21547. };
  21548. BN.max = function max(left, right) {
  21549. if (left.cmp(right) > 0) return left;
  21550. return right;
  21551. };
  21552. BN.min = function min(left, right) {
  21553. if (left.cmp(right) < 0) return left;
  21554. return right;
  21555. };
  21556. BN.prototype._init = function init(number, base, endian) {
  21557. if (typeof number === 'number') {
  21558. return this._initNumber(number, base, endian);
  21559. }
  21560. if (typeof number === 'object') {
  21561. return this._initArray(number, base, endian);
  21562. }
  21563. if (base === 'hex') {
  21564. base = 16;
  21565. }
  21566. assert(base === (base | 0) && base >= 2 && base <= 36);
  21567. number = number.toString().replace(/\s+/g, '');
  21568. var start = 0;
  21569. if (number[0] === '-') {
  21570. start++;
  21571. this.negative = 1;
  21572. }
  21573. if (start < number.length) {
  21574. if (base === 16) {
  21575. this._parseHex(number, start, endian);
  21576. } else {
  21577. this._parseBase(number, base, start);
  21578. if (endian === 'le') {
  21579. this._initArray(this.toArray(), base, endian);
  21580. }
  21581. }
  21582. }
  21583. };
  21584. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  21585. if (number < 0) {
  21586. this.negative = 1;
  21587. number = -number;
  21588. }
  21589. if (number < 0x4000000) {
  21590. this.words = [number & 0x3ffffff];
  21591. this.length = 1;
  21592. } else if (number < 0x10000000000000) {
  21593. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  21594. this.length = 2;
  21595. } else {
  21596. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  21597. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  21598. this.length = 3;
  21599. }
  21600. if (endian !== 'le') return;
  21601. // Reverse the bytes
  21602. this._initArray(this.toArray(), base, endian);
  21603. };
  21604. BN.prototype._initArray = function _initArray(number, base, endian) {
  21605. // Perhaps a Uint8Array
  21606. assert(typeof number.length === 'number');
  21607. if (number.length <= 0) {
  21608. this.words = [0];
  21609. this.length = 1;
  21610. return this;
  21611. }
  21612. this.length = Math.ceil(number.length / 3);
  21613. this.words = new Array(this.length);
  21614. for (var i = 0; i < this.length; i++) {
  21615. this.words[i] = 0;
  21616. }
  21617. var j, w;
  21618. var off = 0;
  21619. if (endian === 'be') {
  21620. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  21621. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  21622. this.words[j] |= w << off & 0x3ffffff;
  21623. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  21624. off += 24;
  21625. if (off >= 26) {
  21626. off -= 26;
  21627. j++;
  21628. }
  21629. }
  21630. } else if (endian === 'le') {
  21631. for (i = 0, j = 0; i < number.length; i += 3) {
  21632. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  21633. this.words[j] |= w << off & 0x3ffffff;
  21634. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  21635. off += 24;
  21636. if (off >= 26) {
  21637. off -= 26;
  21638. j++;
  21639. }
  21640. }
  21641. }
  21642. return this._strip();
  21643. };
  21644. function parseHex4Bits(string, index) {
  21645. var c = string.charCodeAt(index);
  21646. // '0' - '9'
  21647. if (c >= 48 && c <= 57) {
  21648. return c - 48;
  21649. // 'A' - 'F'
  21650. } else if (c >= 65 && c <= 70) {
  21651. return c - 55;
  21652. // 'a' - 'f'
  21653. } else if (c >= 97 && c <= 102) {
  21654. return c - 87;
  21655. } else {
  21656. assert(false, 'Invalid character in ' + string);
  21657. }
  21658. }
  21659. function parseHexByte(string, lowerBound, index) {
  21660. var r = parseHex4Bits(string, index);
  21661. if (index - 1 >= lowerBound) {
  21662. r |= parseHex4Bits(string, index - 1) << 4;
  21663. }
  21664. return r;
  21665. }
  21666. BN.prototype._parseHex = function _parseHex(number, start, endian) {
  21667. // Create possibly bigger array to ensure that it fits the number
  21668. this.length = Math.ceil((number.length - start) / 6);
  21669. this.words = new Array(this.length);
  21670. for (var i = 0; i < this.length; i++) {
  21671. this.words[i] = 0;
  21672. }
  21673. // 24-bits chunks
  21674. var off = 0;
  21675. var j = 0;
  21676. var w;
  21677. if (endian === 'be') {
  21678. for (i = number.length - 1; i >= start; i -= 2) {
  21679. w = parseHexByte(number, start, i) << off;
  21680. this.words[j] |= w & 0x3ffffff;
  21681. if (off >= 18) {
  21682. off -= 18;
  21683. j += 1;
  21684. this.words[j] |= w >>> 26;
  21685. } else {
  21686. off += 8;
  21687. }
  21688. }
  21689. } else {
  21690. var parseLength = number.length - start;
  21691. for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
  21692. w = parseHexByte(number, start, i) << off;
  21693. this.words[j] |= w & 0x3ffffff;
  21694. if (off >= 18) {
  21695. off -= 18;
  21696. j += 1;
  21697. this.words[j] |= w >>> 26;
  21698. } else {
  21699. off += 8;
  21700. }
  21701. }
  21702. }
  21703. this._strip();
  21704. };
  21705. function parseBase(str, start, end, mul) {
  21706. var r = 0;
  21707. var b = 0;
  21708. var len = Math.min(str.length, end);
  21709. for (var i = start; i < len; i++) {
  21710. var c = str.charCodeAt(i) - 48;
  21711. r *= mul;
  21712. // 'a'
  21713. if (c >= 49) {
  21714. b = c - 49 + 0xa;
  21715. // 'A'
  21716. } else if (c >= 17) {
  21717. b = c - 17 + 0xa;
  21718. // '0' - '9'
  21719. } else {
  21720. b = c;
  21721. }
  21722. assert(c >= 0 && b < mul, 'Invalid character');
  21723. r += b;
  21724. }
  21725. return r;
  21726. }
  21727. BN.prototype._parseBase = function _parseBase(number, base, start) {
  21728. // Initialize as zero
  21729. this.words = [0];
  21730. this.length = 1;
  21731. // Find length of limb in base
  21732. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  21733. limbLen++;
  21734. }
  21735. limbLen--;
  21736. limbPow = limbPow / base | 0;
  21737. var total = number.length - start;
  21738. var mod = total % limbLen;
  21739. var end = Math.min(total, total - mod) + start;
  21740. var word = 0;
  21741. for (var i = start; i < end; i += limbLen) {
  21742. word = parseBase(number, i, i + limbLen, base);
  21743. this.imuln(limbPow);
  21744. if (this.words[0] + word < 0x4000000) {
  21745. this.words[0] += word;
  21746. } else {
  21747. this._iaddn(word);
  21748. }
  21749. }
  21750. if (mod !== 0) {
  21751. var pow = 1;
  21752. word = parseBase(number, i, number.length, base);
  21753. for (i = 0; i < mod; i++) {
  21754. pow *= base;
  21755. }
  21756. this.imuln(pow);
  21757. if (this.words[0] + word < 0x4000000) {
  21758. this.words[0] += word;
  21759. } else {
  21760. this._iaddn(word);
  21761. }
  21762. }
  21763. this._strip();
  21764. };
  21765. BN.prototype.copy = function copy(dest) {
  21766. dest.words = new Array(this.length);
  21767. for (var i = 0; i < this.length; i++) {
  21768. dest.words[i] = this.words[i];
  21769. }
  21770. dest.length = this.length;
  21771. dest.negative = this.negative;
  21772. dest.red = this.red;
  21773. };
  21774. function move(dest, src) {
  21775. dest.words = src.words;
  21776. dest.length = src.length;
  21777. dest.negative = src.negative;
  21778. dest.red = src.red;
  21779. }
  21780. BN.prototype._move = function _move(dest) {
  21781. move(dest, this);
  21782. };
  21783. BN.prototype.clone = function clone() {
  21784. var r = new BN(null);
  21785. this.copy(r);
  21786. return r;
  21787. };
  21788. BN.prototype._expand = function _expand(size) {
  21789. while (this.length < size) {
  21790. this.words[this.length++] = 0;
  21791. }
  21792. return this;
  21793. };
  21794. // Remove leading `0` from `this`
  21795. BN.prototype._strip = function strip() {
  21796. while (this.length > 1 && this.words[this.length - 1] === 0) {
  21797. this.length--;
  21798. }
  21799. return this._normSign();
  21800. };
  21801. BN.prototype._normSign = function _normSign() {
  21802. // -0 = 0
  21803. if (this.length === 1 && this.words[0] === 0) {
  21804. this.negative = 0;
  21805. }
  21806. return this;
  21807. };
  21808. // Check Symbol.for because not everywhere where Symbol defined
  21809. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility
  21810. if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') {
  21811. try {
  21812. BN.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspect;
  21813. } catch (e) {
  21814. BN.prototype.inspect = inspect;
  21815. }
  21816. } else {
  21817. BN.prototype.inspect = inspect;
  21818. }
  21819. function inspect() {
  21820. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  21821. }
  21822. /*
  21823. var zeros = [];
  21824. var groupSizes = [];
  21825. var groupBases = [];
  21826. var s = '';
  21827. var i = -1;
  21828. while (++i < BN.wordSize) {
  21829. zeros[i] = s;
  21830. s += '0';
  21831. }
  21832. groupSizes[0] = 0;
  21833. groupSizes[1] = 0;
  21834. groupBases[0] = 0;
  21835. groupBases[1] = 0;
  21836. var base = 2 - 1;
  21837. while (++base < 36 + 1) {
  21838. var groupSize = 0;
  21839. var groupBase = 1;
  21840. while (groupBase < (1 << BN.wordSize) / base) {
  21841. groupBase *= base;
  21842. groupSize += 1;
  21843. }
  21844. groupSizes[base] = groupSize;
  21845. groupBases[base] = groupBase;
  21846. }
  21847. */
  21848. var zeros = ['', '0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '000000000', '0000000000', '00000000000', '000000000000', '0000000000000', '00000000000000', '000000000000000', '0000000000000000', '00000000000000000', '000000000000000000', '0000000000000000000', '00000000000000000000', '000000000000000000000', '0000000000000000000000', '00000000000000000000000', '000000000000000000000000', '0000000000000000000000000'];
  21849. var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];
  21850. var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176];
  21851. BN.prototype.toString = function toString(base, padding) {
  21852. base = base || 10;
  21853. padding = padding | 0 || 1;
  21854. var out;
  21855. if (base === 16 || base === 'hex') {
  21856. out = '';
  21857. var off = 0;
  21858. var carry = 0;
  21859. for (var i = 0; i < this.length; i++) {
  21860. var w = this.words[i];
  21861. var word = ((w << off | carry) & 0xffffff).toString(16);
  21862. carry = w >>> 24 - off & 0xffffff;
  21863. off += 2;
  21864. if (off >= 26) {
  21865. off -= 26;
  21866. i--;
  21867. }
  21868. if (carry !== 0 || i !== this.length - 1) {
  21869. out = zeros[6 - word.length] + word + out;
  21870. } else {
  21871. out = word + out;
  21872. }
  21873. }
  21874. if (carry !== 0) {
  21875. out = carry.toString(16) + out;
  21876. }
  21877. while (out.length % padding !== 0) {
  21878. out = '0' + out;
  21879. }
  21880. if (this.negative !== 0) {
  21881. out = '-' + out;
  21882. }
  21883. return out;
  21884. }
  21885. if (base === (base | 0) && base >= 2 && base <= 36) {
  21886. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  21887. var groupSize = groupSizes[base];
  21888. // var groupBase = Math.pow(base, groupSize);
  21889. var groupBase = groupBases[base];
  21890. out = '';
  21891. var c = this.clone();
  21892. c.negative = 0;
  21893. while (!c.isZero()) {
  21894. var r = c.modrn(groupBase).toString(base);
  21895. c = c.idivn(groupBase);
  21896. if (!c.isZero()) {
  21897. out = zeros[groupSize - r.length] + r + out;
  21898. } else {
  21899. out = r + out;
  21900. }
  21901. }
  21902. if (this.isZero()) {
  21903. out = '0' + out;
  21904. }
  21905. while (out.length % padding !== 0) {
  21906. out = '0' + out;
  21907. }
  21908. if (this.negative !== 0) {
  21909. out = '-' + out;
  21910. }
  21911. return out;
  21912. }
  21913. assert(false, 'Base should be between 2 and 36');
  21914. };
  21915. BN.prototype.toNumber = function toNumber() {
  21916. var ret = this.words[0];
  21917. if (this.length === 2) {
  21918. ret += this.words[1] * 0x4000000;
  21919. } else if (this.length === 3 && this.words[2] === 0x01) {
  21920. // NOTE: at this stage it is known that the top bit is set
  21921. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  21922. } else if (this.length > 2) {
  21923. assert(false, 'Number can only safely store up to 53 bits');
  21924. }
  21925. return this.negative !== 0 ? -ret : ret;
  21926. };
  21927. BN.prototype.toJSON = function toJSON() {
  21928. return this.toString(16, 2);
  21929. };
  21930. if (Buffer) {
  21931. BN.prototype.toBuffer = function toBuffer(endian, length) {
  21932. return this.toArrayLike(Buffer, endian, length);
  21933. };
  21934. }
  21935. BN.prototype.toArray = function toArray(endian, length) {
  21936. return this.toArrayLike(Array, endian, length);
  21937. };
  21938. var allocate = function allocate(ArrayType, size) {
  21939. if (ArrayType.allocUnsafe) {
  21940. return ArrayType.allocUnsafe(size);
  21941. }
  21942. return new ArrayType(size);
  21943. };
  21944. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  21945. this._strip();
  21946. var byteLength = this.byteLength();
  21947. var reqLength = length || Math.max(1, byteLength);
  21948. assert(byteLength <= reqLength, 'byte array longer than desired length');
  21949. assert(reqLength > 0, 'Requested array length <= 0');
  21950. var res = allocate(ArrayType, reqLength);
  21951. var postfix = endian === 'le' ? 'LE' : 'BE';
  21952. this['_toArrayLike' + postfix](res, byteLength);
  21953. return res;
  21954. };
  21955. BN.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
  21956. var position = 0;
  21957. var carry = 0;
  21958. for (var i = 0, shift = 0; i < this.length; i++) {
  21959. var word = this.words[i] << shift | carry;
  21960. res[position++] = word & 0xff;
  21961. if (position < res.length) {
  21962. res[position++] = word >> 8 & 0xff;
  21963. }
  21964. if (position < res.length) {
  21965. res[position++] = word >> 16 & 0xff;
  21966. }
  21967. if (shift === 6) {
  21968. if (position < res.length) {
  21969. res[position++] = word >> 24 & 0xff;
  21970. }
  21971. carry = 0;
  21972. shift = 0;
  21973. } else {
  21974. carry = word >>> 24;
  21975. shift += 2;
  21976. }
  21977. }
  21978. if (position < res.length) {
  21979. res[position++] = carry;
  21980. while (position < res.length) {
  21981. res[position++] = 0;
  21982. }
  21983. }
  21984. };
  21985. BN.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
  21986. var position = res.length - 1;
  21987. var carry = 0;
  21988. for (var i = 0, shift = 0; i < this.length; i++) {
  21989. var word = this.words[i] << shift | carry;
  21990. res[position--] = word & 0xff;
  21991. if (position >= 0) {
  21992. res[position--] = word >> 8 & 0xff;
  21993. }
  21994. if (position >= 0) {
  21995. res[position--] = word >> 16 & 0xff;
  21996. }
  21997. if (shift === 6) {
  21998. if (position >= 0) {
  21999. res[position--] = word >> 24 & 0xff;
  22000. }
  22001. carry = 0;
  22002. shift = 0;
  22003. } else {
  22004. carry = word >>> 24;
  22005. shift += 2;
  22006. }
  22007. }
  22008. if (position >= 0) {
  22009. res[position--] = carry;
  22010. while (position >= 0) {
  22011. res[position--] = 0;
  22012. }
  22013. }
  22014. };
  22015. if (Math.clz32) {
  22016. BN.prototype._countBits = function _countBits(w) {
  22017. return 32 - Math.clz32(w);
  22018. };
  22019. } else {
  22020. BN.prototype._countBits = function _countBits(w) {
  22021. var t = w;
  22022. var r = 0;
  22023. if (t >= 0x1000) {
  22024. r += 13;
  22025. t >>>= 13;
  22026. }
  22027. if (t >= 0x40) {
  22028. r += 7;
  22029. t >>>= 7;
  22030. }
  22031. if (t >= 0x8) {
  22032. r += 4;
  22033. t >>>= 4;
  22034. }
  22035. if (t >= 0x02) {
  22036. r += 2;
  22037. t >>>= 2;
  22038. }
  22039. return r + t;
  22040. };
  22041. }
  22042. BN.prototype._zeroBits = function _zeroBits(w) {
  22043. // Short-cut
  22044. if (w === 0) return 26;
  22045. var t = w;
  22046. var r = 0;
  22047. if ((t & 0x1fff) === 0) {
  22048. r += 13;
  22049. t >>>= 13;
  22050. }
  22051. if ((t & 0x7f) === 0) {
  22052. r += 7;
  22053. t >>>= 7;
  22054. }
  22055. if ((t & 0xf) === 0) {
  22056. r += 4;
  22057. t >>>= 4;
  22058. }
  22059. if ((t & 0x3) === 0) {
  22060. r += 2;
  22061. t >>>= 2;
  22062. }
  22063. if ((t & 0x1) === 0) {
  22064. r++;
  22065. }
  22066. return r;
  22067. };
  22068. // Return number of used bits in a BN
  22069. BN.prototype.bitLength = function bitLength() {
  22070. var w = this.words[this.length - 1];
  22071. var hi = this._countBits(w);
  22072. return (this.length - 1) * 26 + hi;
  22073. };
  22074. function toBitArray(num) {
  22075. var w = new Array(num.bitLength());
  22076. for (var bit = 0; bit < w.length; bit++) {
  22077. var off = bit / 26 | 0;
  22078. var wbit = bit % 26;
  22079. w[bit] = num.words[off] >>> wbit & 0x01;
  22080. }
  22081. return w;
  22082. }
  22083. // Number of trailing zero bits
  22084. BN.prototype.zeroBits = function zeroBits() {
  22085. if (this.isZero()) return 0;
  22086. var r = 0;
  22087. for (var i = 0; i < this.length; i++) {
  22088. var b = this._zeroBits(this.words[i]);
  22089. r += b;
  22090. if (b !== 26) break;
  22091. }
  22092. return r;
  22093. };
  22094. BN.prototype.byteLength = function byteLength() {
  22095. return Math.ceil(this.bitLength() / 8);
  22096. };
  22097. BN.prototype.toTwos = function toTwos(width) {
  22098. if (this.negative !== 0) {
  22099. return this.abs().inotn(width).iaddn(1);
  22100. }
  22101. return this.clone();
  22102. };
  22103. BN.prototype.fromTwos = function fromTwos(width) {
  22104. if (this.testn(width - 1)) {
  22105. return this.notn(width).iaddn(1).ineg();
  22106. }
  22107. return this.clone();
  22108. };
  22109. BN.prototype.isNeg = function isNeg() {
  22110. return this.negative !== 0;
  22111. };
  22112. // Return negative clone of `this`
  22113. BN.prototype.neg = function neg() {
  22114. return this.clone().ineg();
  22115. };
  22116. BN.prototype.ineg = function ineg() {
  22117. if (!this.isZero()) {
  22118. this.negative ^= 1;
  22119. }
  22120. return this;
  22121. };
  22122. // Or `num` with `this` in-place
  22123. BN.prototype.iuor = function iuor(num) {
  22124. while (this.length < num.length) {
  22125. this.words[this.length++] = 0;
  22126. }
  22127. for (var i = 0; i < num.length; i++) {
  22128. this.words[i] = this.words[i] | num.words[i];
  22129. }
  22130. return this._strip();
  22131. };
  22132. BN.prototype.ior = function ior(num) {
  22133. assert((this.negative | num.negative) === 0);
  22134. return this.iuor(num);
  22135. };
  22136. // Or `num` with `this`
  22137. BN.prototype.or = function or(num) {
  22138. if (this.length > num.length) return this.clone().ior(num);
  22139. return num.clone().ior(this);
  22140. };
  22141. BN.prototype.uor = function uor(num) {
  22142. if (this.length > num.length) return this.clone().iuor(num);
  22143. return num.clone().iuor(this);
  22144. };
  22145. // And `num` with `this` in-place
  22146. BN.prototype.iuand = function iuand(num) {
  22147. // b = min-length(num, this)
  22148. var b;
  22149. if (this.length > num.length) {
  22150. b = num;
  22151. } else {
  22152. b = this;
  22153. }
  22154. for (var i = 0; i < b.length; i++) {
  22155. this.words[i] = this.words[i] & num.words[i];
  22156. }
  22157. this.length = b.length;
  22158. return this._strip();
  22159. };
  22160. BN.prototype.iand = function iand(num) {
  22161. assert((this.negative | num.negative) === 0);
  22162. return this.iuand(num);
  22163. };
  22164. // And `num` with `this`
  22165. BN.prototype.and = function and(num) {
  22166. if (this.length > num.length) return this.clone().iand(num);
  22167. return num.clone().iand(this);
  22168. };
  22169. BN.prototype.uand = function uand(num) {
  22170. if (this.length > num.length) return this.clone().iuand(num);
  22171. return num.clone().iuand(this);
  22172. };
  22173. // Xor `num` with `this` in-place
  22174. BN.prototype.iuxor = function iuxor(num) {
  22175. // a.length > b.length
  22176. var a;
  22177. var b;
  22178. if (this.length > num.length) {
  22179. a = this;
  22180. b = num;
  22181. } else {
  22182. a = num;
  22183. b = this;
  22184. }
  22185. for (var i = 0; i < b.length; i++) {
  22186. this.words[i] = a.words[i] ^ b.words[i];
  22187. }
  22188. if (this !== a) {
  22189. for (; i < a.length; i++) {
  22190. this.words[i] = a.words[i];
  22191. }
  22192. }
  22193. this.length = a.length;
  22194. return this._strip();
  22195. };
  22196. BN.prototype.ixor = function ixor(num) {
  22197. assert((this.negative | num.negative) === 0);
  22198. return this.iuxor(num);
  22199. };
  22200. // Xor `num` with `this`
  22201. BN.prototype.xor = function xor(num) {
  22202. if (this.length > num.length) return this.clone().ixor(num);
  22203. return num.clone().ixor(this);
  22204. };
  22205. BN.prototype.uxor = function uxor(num) {
  22206. if (this.length > num.length) return this.clone().iuxor(num);
  22207. return num.clone().iuxor(this);
  22208. };
  22209. // Not ``this`` with ``width`` bitwidth
  22210. BN.prototype.inotn = function inotn(width) {
  22211. assert(typeof width === 'number' && width >= 0);
  22212. var bytesNeeded = Math.ceil(width / 26) | 0;
  22213. var bitsLeft = width % 26;
  22214. // Extend the buffer with leading zeroes
  22215. this._expand(bytesNeeded);
  22216. if (bitsLeft > 0) {
  22217. bytesNeeded--;
  22218. }
  22219. // Handle complete words
  22220. for (var i = 0; i < bytesNeeded; i++) {
  22221. this.words[i] = ~this.words[i] & 0x3ffffff;
  22222. }
  22223. // Handle the residue
  22224. if (bitsLeft > 0) {
  22225. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  22226. }
  22227. // And remove leading zeroes
  22228. return this._strip();
  22229. };
  22230. BN.prototype.notn = function notn(width) {
  22231. return this.clone().inotn(width);
  22232. };
  22233. // Set `bit` of `this`
  22234. BN.prototype.setn = function setn(bit, val) {
  22235. assert(typeof bit === 'number' && bit >= 0);
  22236. var off = bit / 26 | 0;
  22237. var wbit = bit % 26;
  22238. this._expand(off + 1);
  22239. if (val) {
  22240. this.words[off] = this.words[off] | 1 << wbit;
  22241. } else {
  22242. this.words[off] = this.words[off] & ~(1 << wbit);
  22243. }
  22244. return this._strip();
  22245. };
  22246. // Add `num` to `this` in-place
  22247. BN.prototype.iadd = function iadd(num) {
  22248. var r;
  22249. // negative + positive
  22250. if (this.negative !== 0 && num.negative === 0) {
  22251. this.negative = 0;
  22252. r = this.isub(num);
  22253. this.negative ^= 1;
  22254. return this._normSign();
  22255. // positive + negative
  22256. } else if (this.negative === 0 && num.negative !== 0) {
  22257. num.negative = 0;
  22258. r = this.isub(num);
  22259. num.negative = 1;
  22260. return r._normSign();
  22261. }
  22262. // a.length > b.length
  22263. var a, b;
  22264. if (this.length > num.length) {
  22265. a = this;
  22266. b = num;
  22267. } else {
  22268. a = num;
  22269. b = this;
  22270. }
  22271. var carry = 0;
  22272. for (var i = 0; i < b.length; i++) {
  22273. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  22274. this.words[i] = r & 0x3ffffff;
  22275. carry = r >>> 26;
  22276. }
  22277. for (; carry !== 0 && i < a.length; i++) {
  22278. r = (a.words[i] | 0) + carry;
  22279. this.words[i] = r & 0x3ffffff;
  22280. carry = r >>> 26;
  22281. }
  22282. this.length = a.length;
  22283. if (carry !== 0) {
  22284. this.words[this.length] = carry;
  22285. this.length++;
  22286. // Copy the rest of the words
  22287. } else if (a !== this) {
  22288. for (; i < a.length; i++) {
  22289. this.words[i] = a.words[i];
  22290. }
  22291. }
  22292. return this;
  22293. };
  22294. // Add `num` to `this`
  22295. BN.prototype.add = function add(num) {
  22296. var res;
  22297. if (num.negative !== 0 && this.negative === 0) {
  22298. num.negative = 0;
  22299. res = this.sub(num);
  22300. num.negative ^= 1;
  22301. return res;
  22302. } else if (num.negative === 0 && this.negative !== 0) {
  22303. this.negative = 0;
  22304. res = num.sub(this);
  22305. this.negative = 1;
  22306. return res;
  22307. }
  22308. if (this.length > num.length) return this.clone().iadd(num);
  22309. return num.clone().iadd(this);
  22310. };
  22311. // Subtract `num` from `this` in-place
  22312. BN.prototype.isub = function isub(num) {
  22313. // this - (-num) = this + num
  22314. if (num.negative !== 0) {
  22315. num.negative = 0;
  22316. var r = this.iadd(num);
  22317. num.negative = 1;
  22318. return r._normSign();
  22319. // -this - num = -(this + num)
  22320. } else if (this.negative !== 0) {
  22321. this.negative = 0;
  22322. this.iadd(num);
  22323. this.negative = 1;
  22324. return this._normSign();
  22325. }
  22326. // At this point both numbers are positive
  22327. var cmp = this.cmp(num);
  22328. // Optimization - zeroify
  22329. if (cmp === 0) {
  22330. this.negative = 0;
  22331. this.length = 1;
  22332. this.words[0] = 0;
  22333. return this;
  22334. }
  22335. // a > b
  22336. var a, b;
  22337. if (cmp > 0) {
  22338. a = this;
  22339. b = num;
  22340. } else {
  22341. a = num;
  22342. b = this;
  22343. }
  22344. var carry = 0;
  22345. for (var i = 0; i < b.length; i++) {
  22346. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  22347. carry = r >> 26;
  22348. this.words[i] = r & 0x3ffffff;
  22349. }
  22350. for (; carry !== 0 && i < a.length; i++) {
  22351. r = (a.words[i] | 0) + carry;
  22352. carry = r >> 26;
  22353. this.words[i] = r & 0x3ffffff;
  22354. }
  22355. // Copy rest of the words
  22356. if (carry === 0 && i < a.length && a !== this) {
  22357. for (; i < a.length; i++) {
  22358. this.words[i] = a.words[i];
  22359. }
  22360. }
  22361. this.length = Math.max(this.length, i);
  22362. if (a !== this) {
  22363. this.negative = 1;
  22364. }
  22365. return this._strip();
  22366. };
  22367. // Subtract `num` from `this`
  22368. BN.prototype.sub = function sub(num) {
  22369. return this.clone().isub(num);
  22370. };
  22371. function smallMulTo(self, num, out) {
  22372. out.negative = num.negative ^ self.negative;
  22373. var len = self.length + num.length | 0;
  22374. out.length = len;
  22375. len = len - 1 | 0;
  22376. // Peel one iteration (compiler can't do it, because of code complexity)
  22377. var a = self.words[0] | 0;
  22378. var b = num.words[0] | 0;
  22379. var r = a * b;
  22380. var lo = r & 0x3ffffff;
  22381. var carry = r / 0x4000000 | 0;
  22382. out.words[0] = lo;
  22383. for (var k = 1; k < len; k++) {
  22384. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  22385. // note that ncarry could be >= 0x3ffffff
  22386. var ncarry = carry >>> 26;
  22387. var rword = carry & 0x3ffffff;
  22388. var maxJ = Math.min(k, num.length - 1);
  22389. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  22390. var i = k - j | 0;
  22391. a = self.words[i] | 0;
  22392. b = num.words[j] | 0;
  22393. r = a * b + rword;
  22394. ncarry += r / 0x4000000 | 0;
  22395. rword = r & 0x3ffffff;
  22396. }
  22397. out.words[k] = rword | 0;
  22398. carry = ncarry | 0;
  22399. }
  22400. if (carry !== 0) {
  22401. out.words[k] = carry | 0;
  22402. } else {
  22403. out.length--;
  22404. }
  22405. return out._strip();
  22406. }
  22407. // TODO(indutny): it may be reasonable to omit it for users who don't need
  22408. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  22409. // multiplication (like elliptic secp256k1).
  22410. var comb10MulTo = function comb10MulTo(self, num, out) {
  22411. var a = self.words;
  22412. var b = num.words;
  22413. var o = out.words;
  22414. var c = 0;
  22415. var lo;
  22416. var mid;
  22417. var hi;
  22418. var a0 = a[0] | 0;
  22419. var al0 = a0 & 0x1fff;
  22420. var ah0 = a0 >>> 13;
  22421. var a1 = a[1] | 0;
  22422. var al1 = a1 & 0x1fff;
  22423. var ah1 = a1 >>> 13;
  22424. var a2 = a[2] | 0;
  22425. var al2 = a2 & 0x1fff;
  22426. var ah2 = a2 >>> 13;
  22427. var a3 = a[3] | 0;
  22428. var al3 = a3 & 0x1fff;
  22429. var ah3 = a3 >>> 13;
  22430. var a4 = a[4] | 0;
  22431. var al4 = a4 & 0x1fff;
  22432. var ah4 = a4 >>> 13;
  22433. var a5 = a[5] | 0;
  22434. var al5 = a5 & 0x1fff;
  22435. var ah5 = a5 >>> 13;
  22436. var a6 = a[6] | 0;
  22437. var al6 = a6 & 0x1fff;
  22438. var ah6 = a6 >>> 13;
  22439. var a7 = a[7] | 0;
  22440. var al7 = a7 & 0x1fff;
  22441. var ah7 = a7 >>> 13;
  22442. var a8 = a[8] | 0;
  22443. var al8 = a8 & 0x1fff;
  22444. var ah8 = a8 >>> 13;
  22445. var a9 = a[9] | 0;
  22446. var al9 = a9 & 0x1fff;
  22447. var ah9 = a9 >>> 13;
  22448. var b0 = b[0] | 0;
  22449. var bl0 = b0 & 0x1fff;
  22450. var bh0 = b0 >>> 13;
  22451. var b1 = b[1] | 0;
  22452. var bl1 = b1 & 0x1fff;
  22453. var bh1 = b1 >>> 13;
  22454. var b2 = b[2] | 0;
  22455. var bl2 = b2 & 0x1fff;
  22456. var bh2 = b2 >>> 13;
  22457. var b3 = b[3] | 0;
  22458. var bl3 = b3 & 0x1fff;
  22459. var bh3 = b3 >>> 13;
  22460. var b4 = b[4] | 0;
  22461. var bl4 = b4 & 0x1fff;
  22462. var bh4 = b4 >>> 13;
  22463. var b5 = b[5] | 0;
  22464. var bl5 = b5 & 0x1fff;
  22465. var bh5 = b5 >>> 13;
  22466. var b6 = b[6] | 0;
  22467. var bl6 = b6 & 0x1fff;
  22468. var bh6 = b6 >>> 13;
  22469. var b7 = b[7] | 0;
  22470. var bl7 = b7 & 0x1fff;
  22471. var bh7 = b7 >>> 13;
  22472. var b8 = b[8] | 0;
  22473. var bl8 = b8 & 0x1fff;
  22474. var bh8 = b8 >>> 13;
  22475. var b9 = b[9] | 0;
  22476. var bl9 = b9 & 0x1fff;
  22477. var bh9 = b9 >>> 13;
  22478. out.negative = self.negative ^ num.negative;
  22479. out.length = 19;
  22480. /* k = 0 */
  22481. lo = Math.imul(al0, bl0);
  22482. mid = Math.imul(al0, bh0);
  22483. mid = mid + Math.imul(ah0, bl0) | 0;
  22484. hi = Math.imul(ah0, bh0);
  22485. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22486. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  22487. w0 &= 0x3ffffff;
  22488. /* k = 1 */
  22489. lo = Math.imul(al1, bl0);
  22490. mid = Math.imul(al1, bh0);
  22491. mid = mid + Math.imul(ah1, bl0) | 0;
  22492. hi = Math.imul(ah1, bh0);
  22493. lo = lo + Math.imul(al0, bl1) | 0;
  22494. mid = mid + Math.imul(al0, bh1) | 0;
  22495. mid = mid + Math.imul(ah0, bl1) | 0;
  22496. hi = hi + Math.imul(ah0, bh1) | 0;
  22497. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22498. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  22499. w1 &= 0x3ffffff;
  22500. /* k = 2 */
  22501. lo = Math.imul(al2, bl0);
  22502. mid = Math.imul(al2, bh0);
  22503. mid = mid + Math.imul(ah2, bl0) | 0;
  22504. hi = Math.imul(ah2, bh0);
  22505. lo = lo + Math.imul(al1, bl1) | 0;
  22506. mid = mid + Math.imul(al1, bh1) | 0;
  22507. mid = mid + Math.imul(ah1, bl1) | 0;
  22508. hi = hi + Math.imul(ah1, bh1) | 0;
  22509. lo = lo + Math.imul(al0, bl2) | 0;
  22510. mid = mid + Math.imul(al0, bh2) | 0;
  22511. mid = mid + Math.imul(ah0, bl2) | 0;
  22512. hi = hi + Math.imul(ah0, bh2) | 0;
  22513. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22514. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  22515. w2 &= 0x3ffffff;
  22516. /* k = 3 */
  22517. lo = Math.imul(al3, bl0);
  22518. mid = Math.imul(al3, bh0);
  22519. mid = mid + Math.imul(ah3, bl0) | 0;
  22520. hi = Math.imul(ah3, bh0);
  22521. lo = lo + Math.imul(al2, bl1) | 0;
  22522. mid = mid + Math.imul(al2, bh1) | 0;
  22523. mid = mid + Math.imul(ah2, bl1) | 0;
  22524. hi = hi + Math.imul(ah2, bh1) | 0;
  22525. lo = lo + Math.imul(al1, bl2) | 0;
  22526. mid = mid + Math.imul(al1, bh2) | 0;
  22527. mid = mid + Math.imul(ah1, bl2) | 0;
  22528. hi = hi + Math.imul(ah1, bh2) | 0;
  22529. lo = lo + Math.imul(al0, bl3) | 0;
  22530. mid = mid + Math.imul(al0, bh3) | 0;
  22531. mid = mid + Math.imul(ah0, bl3) | 0;
  22532. hi = hi + Math.imul(ah0, bh3) | 0;
  22533. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22534. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  22535. w3 &= 0x3ffffff;
  22536. /* k = 4 */
  22537. lo = Math.imul(al4, bl0);
  22538. mid = Math.imul(al4, bh0);
  22539. mid = mid + Math.imul(ah4, bl0) | 0;
  22540. hi = Math.imul(ah4, bh0);
  22541. lo = lo + Math.imul(al3, bl1) | 0;
  22542. mid = mid + Math.imul(al3, bh1) | 0;
  22543. mid = mid + Math.imul(ah3, bl1) | 0;
  22544. hi = hi + Math.imul(ah3, bh1) | 0;
  22545. lo = lo + Math.imul(al2, bl2) | 0;
  22546. mid = mid + Math.imul(al2, bh2) | 0;
  22547. mid = mid + Math.imul(ah2, bl2) | 0;
  22548. hi = hi + Math.imul(ah2, bh2) | 0;
  22549. lo = lo + Math.imul(al1, bl3) | 0;
  22550. mid = mid + Math.imul(al1, bh3) | 0;
  22551. mid = mid + Math.imul(ah1, bl3) | 0;
  22552. hi = hi + Math.imul(ah1, bh3) | 0;
  22553. lo = lo + Math.imul(al0, bl4) | 0;
  22554. mid = mid + Math.imul(al0, bh4) | 0;
  22555. mid = mid + Math.imul(ah0, bl4) | 0;
  22556. hi = hi + Math.imul(ah0, bh4) | 0;
  22557. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22558. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  22559. w4 &= 0x3ffffff;
  22560. /* k = 5 */
  22561. lo = Math.imul(al5, bl0);
  22562. mid = Math.imul(al5, bh0);
  22563. mid = mid + Math.imul(ah5, bl0) | 0;
  22564. hi = Math.imul(ah5, bh0);
  22565. lo = lo + Math.imul(al4, bl1) | 0;
  22566. mid = mid + Math.imul(al4, bh1) | 0;
  22567. mid = mid + Math.imul(ah4, bl1) | 0;
  22568. hi = hi + Math.imul(ah4, bh1) | 0;
  22569. lo = lo + Math.imul(al3, bl2) | 0;
  22570. mid = mid + Math.imul(al3, bh2) | 0;
  22571. mid = mid + Math.imul(ah3, bl2) | 0;
  22572. hi = hi + Math.imul(ah3, bh2) | 0;
  22573. lo = lo + Math.imul(al2, bl3) | 0;
  22574. mid = mid + Math.imul(al2, bh3) | 0;
  22575. mid = mid + Math.imul(ah2, bl3) | 0;
  22576. hi = hi + Math.imul(ah2, bh3) | 0;
  22577. lo = lo + Math.imul(al1, bl4) | 0;
  22578. mid = mid + Math.imul(al1, bh4) | 0;
  22579. mid = mid + Math.imul(ah1, bl4) | 0;
  22580. hi = hi + Math.imul(ah1, bh4) | 0;
  22581. lo = lo + Math.imul(al0, bl5) | 0;
  22582. mid = mid + Math.imul(al0, bh5) | 0;
  22583. mid = mid + Math.imul(ah0, bl5) | 0;
  22584. hi = hi + Math.imul(ah0, bh5) | 0;
  22585. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22586. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  22587. w5 &= 0x3ffffff;
  22588. /* k = 6 */
  22589. lo = Math.imul(al6, bl0);
  22590. mid = Math.imul(al6, bh0);
  22591. mid = mid + Math.imul(ah6, bl0) | 0;
  22592. hi = Math.imul(ah6, bh0);
  22593. lo = lo + Math.imul(al5, bl1) | 0;
  22594. mid = mid + Math.imul(al5, bh1) | 0;
  22595. mid = mid + Math.imul(ah5, bl1) | 0;
  22596. hi = hi + Math.imul(ah5, bh1) | 0;
  22597. lo = lo + Math.imul(al4, bl2) | 0;
  22598. mid = mid + Math.imul(al4, bh2) | 0;
  22599. mid = mid + Math.imul(ah4, bl2) | 0;
  22600. hi = hi + Math.imul(ah4, bh2) | 0;
  22601. lo = lo + Math.imul(al3, bl3) | 0;
  22602. mid = mid + Math.imul(al3, bh3) | 0;
  22603. mid = mid + Math.imul(ah3, bl3) | 0;
  22604. hi = hi + Math.imul(ah3, bh3) | 0;
  22605. lo = lo + Math.imul(al2, bl4) | 0;
  22606. mid = mid + Math.imul(al2, bh4) | 0;
  22607. mid = mid + Math.imul(ah2, bl4) | 0;
  22608. hi = hi + Math.imul(ah2, bh4) | 0;
  22609. lo = lo + Math.imul(al1, bl5) | 0;
  22610. mid = mid + Math.imul(al1, bh5) | 0;
  22611. mid = mid + Math.imul(ah1, bl5) | 0;
  22612. hi = hi + Math.imul(ah1, bh5) | 0;
  22613. lo = lo + Math.imul(al0, bl6) | 0;
  22614. mid = mid + Math.imul(al0, bh6) | 0;
  22615. mid = mid + Math.imul(ah0, bl6) | 0;
  22616. hi = hi + Math.imul(ah0, bh6) | 0;
  22617. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22618. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  22619. w6 &= 0x3ffffff;
  22620. /* k = 7 */
  22621. lo = Math.imul(al7, bl0);
  22622. mid = Math.imul(al7, bh0);
  22623. mid = mid + Math.imul(ah7, bl0) | 0;
  22624. hi = Math.imul(ah7, bh0);
  22625. lo = lo + Math.imul(al6, bl1) | 0;
  22626. mid = mid + Math.imul(al6, bh1) | 0;
  22627. mid = mid + Math.imul(ah6, bl1) | 0;
  22628. hi = hi + Math.imul(ah6, bh1) | 0;
  22629. lo = lo + Math.imul(al5, bl2) | 0;
  22630. mid = mid + Math.imul(al5, bh2) | 0;
  22631. mid = mid + Math.imul(ah5, bl2) | 0;
  22632. hi = hi + Math.imul(ah5, bh2) | 0;
  22633. lo = lo + Math.imul(al4, bl3) | 0;
  22634. mid = mid + Math.imul(al4, bh3) | 0;
  22635. mid = mid + Math.imul(ah4, bl3) | 0;
  22636. hi = hi + Math.imul(ah4, bh3) | 0;
  22637. lo = lo + Math.imul(al3, bl4) | 0;
  22638. mid = mid + Math.imul(al3, bh4) | 0;
  22639. mid = mid + Math.imul(ah3, bl4) | 0;
  22640. hi = hi + Math.imul(ah3, bh4) | 0;
  22641. lo = lo + Math.imul(al2, bl5) | 0;
  22642. mid = mid + Math.imul(al2, bh5) | 0;
  22643. mid = mid + Math.imul(ah2, bl5) | 0;
  22644. hi = hi + Math.imul(ah2, bh5) | 0;
  22645. lo = lo + Math.imul(al1, bl6) | 0;
  22646. mid = mid + Math.imul(al1, bh6) | 0;
  22647. mid = mid + Math.imul(ah1, bl6) | 0;
  22648. hi = hi + Math.imul(ah1, bh6) | 0;
  22649. lo = lo + Math.imul(al0, bl7) | 0;
  22650. mid = mid + Math.imul(al0, bh7) | 0;
  22651. mid = mid + Math.imul(ah0, bl7) | 0;
  22652. hi = hi + Math.imul(ah0, bh7) | 0;
  22653. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22654. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  22655. w7 &= 0x3ffffff;
  22656. /* k = 8 */
  22657. lo = Math.imul(al8, bl0);
  22658. mid = Math.imul(al8, bh0);
  22659. mid = mid + Math.imul(ah8, bl0) | 0;
  22660. hi = Math.imul(ah8, bh0);
  22661. lo = lo + Math.imul(al7, bl1) | 0;
  22662. mid = mid + Math.imul(al7, bh1) | 0;
  22663. mid = mid + Math.imul(ah7, bl1) | 0;
  22664. hi = hi + Math.imul(ah7, bh1) | 0;
  22665. lo = lo + Math.imul(al6, bl2) | 0;
  22666. mid = mid + Math.imul(al6, bh2) | 0;
  22667. mid = mid + Math.imul(ah6, bl2) | 0;
  22668. hi = hi + Math.imul(ah6, bh2) | 0;
  22669. lo = lo + Math.imul(al5, bl3) | 0;
  22670. mid = mid + Math.imul(al5, bh3) | 0;
  22671. mid = mid + Math.imul(ah5, bl3) | 0;
  22672. hi = hi + Math.imul(ah5, bh3) | 0;
  22673. lo = lo + Math.imul(al4, bl4) | 0;
  22674. mid = mid + Math.imul(al4, bh4) | 0;
  22675. mid = mid + Math.imul(ah4, bl4) | 0;
  22676. hi = hi + Math.imul(ah4, bh4) | 0;
  22677. lo = lo + Math.imul(al3, bl5) | 0;
  22678. mid = mid + Math.imul(al3, bh5) | 0;
  22679. mid = mid + Math.imul(ah3, bl5) | 0;
  22680. hi = hi + Math.imul(ah3, bh5) | 0;
  22681. lo = lo + Math.imul(al2, bl6) | 0;
  22682. mid = mid + Math.imul(al2, bh6) | 0;
  22683. mid = mid + Math.imul(ah2, bl6) | 0;
  22684. hi = hi + Math.imul(ah2, bh6) | 0;
  22685. lo = lo + Math.imul(al1, bl7) | 0;
  22686. mid = mid + Math.imul(al1, bh7) | 0;
  22687. mid = mid + Math.imul(ah1, bl7) | 0;
  22688. hi = hi + Math.imul(ah1, bh7) | 0;
  22689. lo = lo + Math.imul(al0, bl8) | 0;
  22690. mid = mid + Math.imul(al0, bh8) | 0;
  22691. mid = mid + Math.imul(ah0, bl8) | 0;
  22692. hi = hi + Math.imul(ah0, bh8) | 0;
  22693. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22694. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  22695. w8 &= 0x3ffffff;
  22696. /* k = 9 */
  22697. lo = Math.imul(al9, bl0);
  22698. mid = Math.imul(al9, bh0);
  22699. mid = mid + Math.imul(ah9, bl0) | 0;
  22700. hi = Math.imul(ah9, bh0);
  22701. lo = lo + Math.imul(al8, bl1) | 0;
  22702. mid = mid + Math.imul(al8, bh1) | 0;
  22703. mid = mid + Math.imul(ah8, bl1) | 0;
  22704. hi = hi + Math.imul(ah8, bh1) | 0;
  22705. lo = lo + Math.imul(al7, bl2) | 0;
  22706. mid = mid + Math.imul(al7, bh2) | 0;
  22707. mid = mid + Math.imul(ah7, bl2) | 0;
  22708. hi = hi + Math.imul(ah7, bh2) | 0;
  22709. lo = lo + Math.imul(al6, bl3) | 0;
  22710. mid = mid + Math.imul(al6, bh3) | 0;
  22711. mid = mid + Math.imul(ah6, bl3) | 0;
  22712. hi = hi + Math.imul(ah6, bh3) | 0;
  22713. lo = lo + Math.imul(al5, bl4) | 0;
  22714. mid = mid + Math.imul(al5, bh4) | 0;
  22715. mid = mid + Math.imul(ah5, bl4) | 0;
  22716. hi = hi + Math.imul(ah5, bh4) | 0;
  22717. lo = lo + Math.imul(al4, bl5) | 0;
  22718. mid = mid + Math.imul(al4, bh5) | 0;
  22719. mid = mid + Math.imul(ah4, bl5) | 0;
  22720. hi = hi + Math.imul(ah4, bh5) | 0;
  22721. lo = lo + Math.imul(al3, bl6) | 0;
  22722. mid = mid + Math.imul(al3, bh6) | 0;
  22723. mid = mid + Math.imul(ah3, bl6) | 0;
  22724. hi = hi + Math.imul(ah3, bh6) | 0;
  22725. lo = lo + Math.imul(al2, bl7) | 0;
  22726. mid = mid + Math.imul(al2, bh7) | 0;
  22727. mid = mid + Math.imul(ah2, bl7) | 0;
  22728. hi = hi + Math.imul(ah2, bh7) | 0;
  22729. lo = lo + Math.imul(al1, bl8) | 0;
  22730. mid = mid + Math.imul(al1, bh8) | 0;
  22731. mid = mid + Math.imul(ah1, bl8) | 0;
  22732. hi = hi + Math.imul(ah1, bh8) | 0;
  22733. lo = lo + Math.imul(al0, bl9) | 0;
  22734. mid = mid + Math.imul(al0, bh9) | 0;
  22735. mid = mid + Math.imul(ah0, bl9) | 0;
  22736. hi = hi + Math.imul(ah0, bh9) | 0;
  22737. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22738. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  22739. w9 &= 0x3ffffff;
  22740. /* k = 10 */
  22741. lo = Math.imul(al9, bl1);
  22742. mid = Math.imul(al9, bh1);
  22743. mid = mid + Math.imul(ah9, bl1) | 0;
  22744. hi = Math.imul(ah9, bh1);
  22745. lo = lo + Math.imul(al8, bl2) | 0;
  22746. mid = mid + Math.imul(al8, bh2) | 0;
  22747. mid = mid + Math.imul(ah8, bl2) | 0;
  22748. hi = hi + Math.imul(ah8, bh2) | 0;
  22749. lo = lo + Math.imul(al7, bl3) | 0;
  22750. mid = mid + Math.imul(al7, bh3) | 0;
  22751. mid = mid + Math.imul(ah7, bl3) | 0;
  22752. hi = hi + Math.imul(ah7, bh3) | 0;
  22753. lo = lo + Math.imul(al6, bl4) | 0;
  22754. mid = mid + Math.imul(al6, bh4) | 0;
  22755. mid = mid + Math.imul(ah6, bl4) | 0;
  22756. hi = hi + Math.imul(ah6, bh4) | 0;
  22757. lo = lo + Math.imul(al5, bl5) | 0;
  22758. mid = mid + Math.imul(al5, bh5) | 0;
  22759. mid = mid + Math.imul(ah5, bl5) | 0;
  22760. hi = hi + Math.imul(ah5, bh5) | 0;
  22761. lo = lo + Math.imul(al4, bl6) | 0;
  22762. mid = mid + Math.imul(al4, bh6) | 0;
  22763. mid = mid + Math.imul(ah4, bl6) | 0;
  22764. hi = hi + Math.imul(ah4, bh6) | 0;
  22765. lo = lo + Math.imul(al3, bl7) | 0;
  22766. mid = mid + Math.imul(al3, bh7) | 0;
  22767. mid = mid + Math.imul(ah3, bl7) | 0;
  22768. hi = hi + Math.imul(ah3, bh7) | 0;
  22769. lo = lo + Math.imul(al2, bl8) | 0;
  22770. mid = mid + Math.imul(al2, bh8) | 0;
  22771. mid = mid + Math.imul(ah2, bl8) | 0;
  22772. hi = hi + Math.imul(ah2, bh8) | 0;
  22773. lo = lo + Math.imul(al1, bl9) | 0;
  22774. mid = mid + Math.imul(al1, bh9) | 0;
  22775. mid = mid + Math.imul(ah1, bl9) | 0;
  22776. hi = hi + Math.imul(ah1, bh9) | 0;
  22777. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22778. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  22779. w10 &= 0x3ffffff;
  22780. /* k = 11 */
  22781. lo = Math.imul(al9, bl2);
  22782. mid = Math.imul(al9, bh2);
  22783. mid = mid + Math.imul(ah9, bl2) | 0;
  22784. hi = Math.imul(ah9, bh2);
  22785. lo = lo + Math.imul(al8, bl3) | 0;
  22786. mid = mid + Math.imul(al8, bh3) | 0;
  22787. mid = mid + Math.imul(ah8, bl3) | 0;
  22788. hi = hi + Math.imul(ah8, bh3) | 0;
  22789. lo = lo + Math.imul(al7, bl4) | 0;
  22790. mid = mid + Math.imul(al7, bh4) | 0;
  22791. mid = mid + Math.imul(ah7, bl4) | 0;
  22792. hi = hi + Math.imul(ah7, bh4) | 0;
  22793. lo = lo + Math.imul(al6, bl5) | 0;
  22794. mid = mid + Math.imul(al6, bh5) | 0;
  22795. mid = mid + Math.imul(ah6, bl5) | 0;
  22796. hi = hi + Math.imul(ah6, bh5) | 0;
  22797. lo = lo + Math.imul(al5, bl6) | 0;
  22798. mid = mid + Math.imul(al5, bh6) | 0;
  22799. mid = mid + Math.imul(ah5, bl6) | 0;
  22800. hi = hi + Math.imul(ah5, bh6) | 0;
  22801. lo = lo + Math.imul(al4, bl7) | 0;
  22802. mid = mid + Math.imul(al4, bh7) | 0;
  22803. mid = mid + Math.imul(ah4, bl7) | 0;
  22804. hi = hi + Math.imul(ah4, bh7) | 0;
  22805. lo = lo + Math.imul(al3, bl8) | 0;
  22806. mid = mid + Math.imul(al3, bh8) | 0;
  22807. mid = mid + Math.imul(ah3, bl8) | 0;
  22808. hi = hi + Math.imul(ah3, bh8) | 0;
  22809. lo = lo + Math.imul(al2, bl9) | 0;
  22810. mid = mid + Math.imul(al2, bh9) | 0;
  22811. mid = mid + Math.imul(ah2, bl9) | 0;
  22812. hi = hi + Math.imul(ah2, bh9) | 0;
  22813. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22814. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  22815. w11 &= 0x3ffffff;
  22816. /* k = 12 */
  22817. lo = Math.imul(al9, bl3);
  22818. mid = Math.imul(al9, bh3);
  22819. mid = mid + Math.imul(ah9, bl3) | 0;
  22820. hi = Math.imul(ah9, bh3);
  22821. lo = lo + Math.imul(al8, bl4) | 0;
  22822. mid = mid + Math.imul(al8, bh4) | 0;
  22823. mid = mid + Math.imul(ah8, bl4) | 0;
  22824. hi = hi + Math.imul(ah8, bh4) | 0;
  22825. lo = lo + Math.imul(al7, bl5) | 0;
  22826. mid = mid + Math.imul(al7, bh5) | 0;
  22827. mid = mid + Math.imul(ah7, bl5) | 0;
  22828. hi = hi + Math.imul(ah7, bh5) | 0;
  22829. lo = lo + Math.imul(al6, bl6) | 0;
  22830. mid = mid + Math.imul(al6, bh6) | 0;
  22831. mid = mid + Math.imul(ah6, bl6) | 0;
  22832. hi = hi + Math.imul(ah6, bh6) | 0;
  22833. lo = lo + Math.imul(al5, bl7) | 0;
  22834. mid = mid + Math.imul(al5, bh7) | 0;
  22835. mid = mid + Math.imul(ah5, bl7) | 0;
  22836. hi = hi + Math.imul(ah5, bh7) | 0;
  22837. lo = lo + Math.imul(al4, bl8) | 0;
  22838. mid = mid + Math.imul(al4, bh8) | 0;
  22839. mid = mid + Math.imul(ah4, bl8) | 0;
  22840. hi = hi + Math.imul(ah4, bh8) | 0;
  22841. lo = lo + Math.imul(al3, bl9) | 0;
  22842. mid = mid + Math.imul(al3, bh9) | 0;
  22843. mid = mid + Math.imul(ah3, bl9) | 0;
  22844. hi = hi + Math.imul(ah3, bh9) | 0;
  22845. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22846. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  22847. w12 &= 0x3ffffff;
  22848. /* k = 13 */
  22849. lo = Math.imul(al9, bl4);
  22850. mid = Math.imul(al9, bh4);
  22851. mid = mid + Math.imul(ah9, bl4) | 0;
  22852. hi = Math.imul(ah9, bh4);
  22853. lo = lo + Math.imul(al8, bl5) | 0;
  22854. mid = mid + Math.imul(al8, bh5) | 0;
  22855. mid = mid + Math.imul(ah8, bl5) | 0;
  22856. hi = hi + Math.imul(ah8, bh5) | 0;
  22857. lo = lo + Math.imul(al7, bl6) | 0;
  22858. mid = mid + Math.imul(al7, bh6) | 0;
  22859. mid = mid + Math.imul(ah7, bl6) | 0;
  22860. hi = hi + Math.imul(ah7, bh6) | 0;
  22861. lo = lo + Math.imul(al6, bl7) | 0;
  22862. mid = mid + Math.imul(al6, bh7) | 0;
  22863. mid = mid + Math.imul(ah6, bl7) | 0;
  22864. hi = hi + Math.imul(ah6, bh7) | 0;
  22865. lo = lo + Math.imul(al5, bl8) | 0;
  22866. mid = mid + Math.imul(al5, bh8) | 0;
  22867. mid = mid + Math.imul(ah5, bl8) | 0;
  22868. hi = hi + Math.imul(ah5, bh8) | 0;
  22869. lo = lo + Math.imul(al4, bl9) | 0;
  22870. mid = mid + Math.imul(al4, bh9) | 0;
  22871. mid = mid + Math.imul(ah4, bl9) | 0;
  22872. hi = hi + Math.imul(ah4, bh9) | 0;
  22873. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22874. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  22875. w13 &= 0x3ffffff;
  22876. /* k = 14 */
  22877. lo = Math.imul(al9, bl5);
  22878. mid = Math.imul(al9, bh5);
  22879. mid = mid + Math.imul(ah9, bl5) | 0;
  22880. hi = Math.imul(ah9, bh5);
  22881. lo = lo + Math.imul(al8, bl6) | 0;
  22882. mid = mid + Math.imul(al8, bh6) | 0;
  22883. mid = mid + Math.imul(ah8, bl6) | 0;
  22884. hi = hi + Math.imul(ah8, bh6) | 0;
  22885. lo = lo + Math.imul(al7, bl7) | 0;
  22886. mid = mid + Math.imul(al7, bh7) | 0;
  22887. mid = mid + Math.imul(ah7, bl7) | 0;
  22888. hi = hi + Math.imul(ah7, bh7) | 0;
  22889. lo = lo + Math.imul(al6, bl8) | 0;
  22890. mid = mid + Math.imul(al6, bh8) | 0;
  22891. mid = mid + Math.imul(ah6, bl8) | 0;
  22892. hi = hi + Math.imul(ah6, bh8) | 0;
  22893. lo = lo + Math.imul(al5, bl9) | 0;
  22894. mid = mid + Math.imul(al5, bh9) | 0;
  22895. mid = mid + Math.imul(ah5, bl9) | 0;
  22896. hi = hi + Math.imul(ah5, bh9) | 0;
  22897. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22898. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  22899. w14 &= 0x3ffffff;
  22900. /* k = 15 */
  22901. lo = Math.imul(al9, bl6);
  22902. mid = Math.imul(al9, bh6);
  22903. mid = mid + Math.imul(ah9, bl6) | 0;
  22904. hi = Math.imul(ah9, bh6);
  22905. lo = lo + Math.imul(al8, bl7) | 0;
  22906. mid = mid + Math.imul(al8, bh7) | 0;
  22907. mid = mid + Math.imul(ah8, bl7) | 0;
  22908. hi = hi + Math.imul(ah8, bh7) | 0;
  22909. lo = lo + Math.imul(al7, bl8) | 0;
  22910. mid = mid + Math.imul(al7, bh8) | 0;
  22911. mid = mid + Math.imul(ah7, bl8) | 0;
  22912. hi = hi + Math.imul(ah7, bh8) | 0;
  22913. lo = lo + Math.imul(al6, bl9) | 0;
  22914. mid = mid + Math.imul(al6, bh9) | 0;
  22915. mid = mid + Math.imul(ah6, bl9) | 0;
  22916. hi = hi + Math.imul(ah6, bh9) | 0;
  22917. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22918. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  22919. w15 &= 0x3ffffff;
  22920. /* k = 16 */
  22921. lo = Math.imul(al9, bl7);
  22922. mid = Math.imul(al9, bh7);
  22923. mid = mid + Math.imul(ah9, bl7) | 0;
  22924. hi = Math.imul(ah9, bh7);
  22925. lo = lo + Math.imul(al8, bl8) | 0;
  22926. mid = mid + Math.imul(al8, bh8) | 0;
  22927. mid = mid + Math.imul(ah8, bl8) | 0;
  22928. hi = hi + Math.imul(ah8, bh8) | 0;
  22929. lo = lo + Math.imul(al7, bl9) | 0;
  22930. mid = mid + Math.imul(al7, bh9) | 0;
  22931. mid = mid + Math.imul(ah7, bl9) | 0;
  22932. hi = hi + Math.imul(ah7, bh9) | 0;
  22933. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22934. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  22935. w16 &= 0x3ffffff;
  22936. /* k = 17 */
  22937. lo = Math.imul(al9, bl8);
  22938. mid = Math.imul(al9, bh8);
  22939. mid = mid + Math.imul(ah9, bl8) | 0;
  22940. hi = Math.imul(ah9, bh8);
  22941. lo = lo + Math.imul(al8, bl9) | 0;
  22942. mid = mid + Math.imul(al8, bh9) | 0;
  22943. mid = mid + Math.imul(ah8, bl9) | 0;
  22944. hi = hi + Math.imul(ah8, bh9) | 0;
  22945. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22946. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  22947. w17 &= 0x3ffffff;
  22948. /* k = 18 */
  22949. lo = Math.imul(al9, bl9);
  22950. mid = Math.imul(al9, bh9);
  22951. mid = mid + Math.imul(ah9, bl9) | 0;
  22952. hi = Math.imul(ah9, bh9);
  22953. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  22954. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  22955. w18 &= 0x3ffffff;
  22956. o[0] = w0;
  22957. o[1] = w1;
  22958. o[2] = w2;
  22959. o[3] = w3;
  22960. o[4] = w4;
  22961. o[5] = w5;
  22962. o[6] = w6;
  22963. o[7] = w7;
  22964. o[8] = w8;
  22965. o[9] = w9;
  22966. o[10] = w10;
  22967. o[11] = w11;
  22968. o[12] = w12;
  22969. o[13] = w13;
  22970. o[14] = w14;
  22971. o[15] = w15;
  22972. o[16] = w16;
  22973. o[17] = w17;
  22974. o[18] = w18;
  22975. if (c !== 0) {
  22976. o[19] = c;
  22977. out.length++;
  22978. }
  22979. return out;
  22980. };
  22981. // Polyfill comb
  22982. if (!Math.imul) {
  22983. comb10MulTo = smallMulTo;
  22984. }
  22985. function bigMulTo(self, num, out) {
  22986. out.negative = num.negative ^ self.negative;
  22987. out.length = self.length + num.length;
  22988. var carry = 0;
  22989. var hncarry = 0;
  22990. for (var k = 0; k < out.length - 1; k++) {
  22991. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  22992. // note that ncarry could be >= 0x3ffffff
  22993. var ncarry = hncarry;
  22994. hncarry = 0;
  22995. var rword = carry & 0x3ffffff;
  22996. var maxJ = Math.min(k, num.length - 1);
  22997. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  22998. var i = k - j;
  22999. var a = self.words[i] | 0;
  23000. var b = num.words[j] | 0;
  23001. var r = a * b;
  23002. var lo = r & 0x3ffffff;
  23003. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  23004. lo = lo + rword | 0;
  23005. rword = lo & 0x3ffffff;
  23006. ncarry = ncarry + (lo >>> 26) | 0;
  23007. hncarry += ncarry >>> 26;
  23008. ncarry &= 0x3ffffff;
  23009. }
  23010. out.words[k] = rword;
  23011. carry = ncarry;
  23012. ncarry = hncarry;
  23013. }
  23014. if (carry !== 0) {
  23015. out.words[k] = carry;
  23016. } else {
  23017. out.length--;
  23018. }
  23019. return out._strip();
  23020. }
  23021. function jumboMulTo(self, num, out) {
  23022. // Temporary disable, see https://github.com/indutny/bn.js/issues/211
  23023. // var fftm = new FFTM();
  23024. // return fftm.mulp(self, num, out);
  23025. return bigMulTo(self, num, out);
  23026. }
  23027. BN.prototype.mulTo = function mulTo(num, out) {
  23028. var res;
  23029. var len = this.length + num.length;
  23030. if (this.length === 10 && num.length === 10) {
  23031. res = comb10MulTo(this, num, out);
  23032. } else if (len < 63) {
  23033. res = smallMulTo(this, num, out);
  23034. } else if (len < 1024) {
  23035. res = bigMulTo(this, num, out);
  23036. } else {
  23037. res = jumboMulTo(this, num, out);
  23038. }
  23039. return res;
  23040. };
  23041. // Cooley-Tukey algorithm for FFT
  23042. // slightly revisited to rely on looping instead of recursion
  23043. function FFTM(x, y) {
  23044. this.x = x;
  23045. this.y = y;
  23046. }
  23047. FFTM.prototype.makeRBT = function makeRBT(N) {
  23048. var t = new Array(N);
  23049. var l = BN.prototype._countBits(N) - 1;
  23050. for (var i = 0; i < N; i++) {
  23051. t[i] = this.revBin(i, l, N);
  23052. }
  23053. return t;
  23054. };
  23055. // Returns binary-reversed representation of `x`
  23056. FFTM.prototype.revBin = function revBin(x, l, N) {
  23057. if (x === 0 || x === N - 1) return x;
  23058. var rb = 0;
  23059. for (var i = 0; i < l; i++) {
  23060. rb |= (x & 1) << l - i - 1;
  23061. x >>= 1;
  23062. }
  23063. return rb;
  23064. };
  23065. // Performs "tweedling" phase, therefore 'emulating'
  23066. // behaviour of the recursive algorithm
  23067. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  23068. for (var i = 0; i < N; i++) {
  23069. rtws[i] = rws[rbt[i]];
  23070. itws[i] = iws[rbt[i]];
  23071. }
  23072. };
  23073. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  23074. this.permute(rbt, rws, iws, rtws, itws, N);
  23075. for (var s = 1; s < N; s <<= 1) {
  23076. var l = s << 1;
  23077. var rtwdf = Math.cos(2 * Math.PI / l);
  23078. var itwdf = Math.sin(2 * Math.PI / l);
  23079. for (var p = 0; p < N; p += l) {
  23080. var rtwdf_ = rtwdf;
  23081. var itwdf_ = itwdf;
  23082. for (var j = 0; j < s; j++) {
  23083. var re = rtws[p + j];
  23084. var ie = itws[p + j];
  23085. var ro = rtws[p + j + s];
  23086. var io = itws[p + j + s];
  23087. var rx = rtwdf_ * ro - itwdf_ * io;
  23088. io = rtwdf_ * io + itwdf_ * ro;
  23089. ro = rx;
  23090. rtws[p + j] = re + ro;
  23091. itws[p + j] = ie + io;
  23092. rtws[p + j + s] = re - ro;
  23093. itws[p + j + s] = ie - io;
  23094. /* jshint maxdepth : false */
  23095. if (j !== l) {
  23096. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  23097. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  23098. rtwdf_ = rx;
  23099. }
  23100. }
  23101. }
  23102. }
  23103. };
  23104. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  23105. var N = Math.max(m, n) | 1;
  23106. var odd = N & 1;
  23107. var i = 0;
  23108. for (N = N / 2 | 0; N; N = N >>> 1) {
  23109. i++;
  23110. }
  23111. return 1 << i + 1 + odd;
  23112. };
  23113. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  23114. if (N <= 1) return;
  23115. for (var i = 0; i < N / 2; i++) {
  23116. var t = rws[i];
  23117. rws[i] = rws[N - i - 1];
  23118. rws[N - i - 1] = t;
  23119. t = iws[i];
  23120. iws[i] = -iws[N - i - 1];
  23121. iws[N - i - 1] = -t;
  23122. }
  23123. };
  23124. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  23125. var carry = 0;
  23126. for (var i = 0; i < N / 2; i++) {
  23127. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  23128. ws[i] = w & 0x3ffffff;
  23129. if (w < 0x4000000) {
  23130. carry = 0;
  23131. } else {
  23132. carry = w / 0x4000000 | 0;
  23133. }
  23134. }
  23135. return ws;
  23136. };
  23137. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  23138. var carry = 0;
  23139. for (var i = 0; i < len; i++) {
  23140. carry = carry + (ws[i] | 0);
  23141. rws[2 * i] = carry & 0x1fff;
  23142. carry = carry >>> 13;
  23143. rws[2 * i + 1] = carry & 0x1fff;
  23144. carry = carry >>> 13;
  23145. }
  23146. // Pad with zeroes
  23147. for (i = 2 * len; i < N; ++i) {
  23148. rws[i] = 0;
  23149. }
  23150. assert(carry === 0);
  23151. assert((carry & ~0x1fff) === 0);
  23152. };
  23153. FFTM.prototype.stub = function stub(N) {
  23154. var ph = new Array(N);
  23155. for (var i = 0; i < N; i++) {
  23156. ph[i] = 0;
  23157. }
  23158. return ph;
  23159. };
  23160. FFTM.prototype.mulp = function mulp(x, y, out) {
  23161. var N = 2 * this.guessLen13b(x.length, y.length);
  23162. var rbt = this.makeRBT(N);
  23163. var _ = this.stub(N);
  23164. var rws = new Array(N);
  23165. var rwst = new Array(N);
  23166. var iwst = new Array(N);
  23167. var nrws = new Array(N);
  23168. var nrwst = new Array(N);
  23169. var niwst = new Array(N);
  23170. var rmws = out.words;
  23171. rmws.length = N;
  23172. this.convert13b(x.words, x.length, rws, N);
  23173. this.convert13b(y.words, y.length, nrws, N);
  23174. this.transform(rws, _, rwst, iwst, N, rbt);
  23175. this.transform(nrws, _, nrwst, niwst, N, rbt);
  23176. for (var i = 0; i < N; i++) {
  23177. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  23178. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  23179. rwst[i] = rx;
  23180. }
  23181. this.conjugate(rwst, iwst, N);
  23182. this.transform(rwst, iwst, rmws, _, N, rbt);
  23183. this.conjugate(rmws, _, N);
  23184. this.normalize13b(rmws, N);
  23185. out.negative = x.negative ^ y.negative;
  23186. out.length = x.length + y.length;
  23187. return out._strip();
  23188. };
  23189. // Multiply `this` by `num`
  23190. BN.prototype.mul = function mul(num) {
  23191. var out = new BN(null);
  23192. out.words = new Array(this.length + num.length);
  23193. return this.mulTo(num, out);
  23194. };
  23195. // Multiply employing FFT
  23196. BN.prototype.mulf = function mulf(num) {
  23197. var out = new BN(null);
  23198. out.words = new Array(this.length + num.length);
  23199. return jumboMulTo(this, num, out);
  23200. };
  23201. // In-place Multiplication
  23202. BN.prototype.imul = function imul(num) {
  23203. return this.clone().mulTo(num, this);
  23204. };
  23205. BN.prototype.imuln = function imuln(num) {
  23206. var isNegNum = num < 0;
  23207. if (isNegNum) num = -num;
  23208. assert(typeof num === 'number');
  23209. assert(num < 0x4000000);
  23210. // Carry
  23211. var carry = 0;
  23212. for (var i = 0; i < this.length; i++) {
  23213. var w = (this.words[i] | 0) * num;
  23214. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  23215. carry >>= 26;
  23216. carry += w / 0x4000000 | 0;
  23217. // NOTE: lo is 27bit maximum
  23218. carry += lo >>> 26;
  23219. this.words[i] = lo & 0x3ffffff;
  23220. }
  23221. if (carry !== 0) {
  23222. this.words[i] = carry;
  23223. this.length++;
  23224. }
  23225. return isNegNum ? this.ineg() : this;
  23226. };
  23227. BN.prototype.muln = function muln(num) {
  23228. return this.clone().imuln(num);
  23229. };
  23230. // `this` * `this`
  23231. BN.prototype.sqr = function sqr() {
  23232. return this.mul(this);
  23233. };
  23234. // `this` * `this` in-place
  23235. BN.prototype.isqr = function isqr() {
  23236. return this.imul(this.clone());
  23237. };
  23238. // Math.pow(`this`, `num`)
  23239. BN.prototype.pow = function pow(num) {
  23240. var w = toBitArray(num);
  23241. if (w.length === 0) return new BN(1);
  23242. // Skip leading zeroes
  23243. var res = this;
  23244. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  23245. if (w[i] !== 0) break;
  23246. }
  23247. if (++i < w.length) {
  23248. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  23249. if (w[i] === 0) continue;
  23250. res = res.mul(q);
  23251. }
  23252. }
  23253. return res;
  23254. };
  23255. // Shift-left in-place
  23256. BN.prototype.iushln = function iushln(bits) {
  23257. assert(typeof bits === 'number' && bits >= 0);
  23258. var r = bits % 26;
  23259. var s = (bits - r) / 26;
  23260. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  23261. var i;
  23262. if (r !== 0) {
  23263. var carry = 0;
  23264. for (i = 0; i < this.length; i++) {
  23265. var newCarry = this.words[i] & carryMask;
  23266. var c = (this.words[i] | 0) - newCarry << r;
  23267. this.words[i] = c | carry;
  23268. carry = newCarry >>> 26 - r;
  23269. }
  23270. if (carry) {
  23271. this.words[i] = carry;
  23272. this.length++;
  23273. }
  23274. }
  23275. if (s !== 0) {
  23276. for (i = this.length - 1; i >= 0; i--) {
  23277. this.words[i + s] = this.words[i];
  23278. }
  23279. for (i = 0; i < s; i++) {
  23280. this.words[i] = 0;
  23281. }
  23282. this.length += s;
  23283. }
  23284. return this._strip();
  23285. };
  23286. BN.prototype.ishln = function ishln(bits) {
  23287. // TODO(indutny): implement me
  23288. assert(this.negative === 0);
  23289. return this.iushln(bits);
  23290. };
  23291. // Shift-right in-place
  23292. // NOTE: `hint` is a lowest bit before trailing zeroes
  23293. // NOTE: if `extended` is present - it will be filled with destroyed bits
  23294. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  23295. assert(typeof bits === 'number' && bits >= 0);
  23296. var h;
  23297. if (hint) {
  23298. h = (hint - hint % 26) / 26;
  23299. } else {
  23300. h = 0;
  23301. }
  23302. var r = bits % 26;
  23303. var s = Math.min((bits - r) / 26, this.length);
  23304. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  23305. var maskedWords = extended;
  23306. h -= s;
  23307. h = Math.max(0, h);
  23308. // Extended mode, copy masked part
  23309. if (maskedWords) {
  23310. for (var i = 0; i < s; i++) {
  23311. maskedWords.words[i] = this.words[i];
  23312. }
  23313. maskedWords.length = s;
  23314. }
  23315. if (s === 0) {
  23316. // No-op, we should not move anything at all
  23317. } else if (this.length > s) {
  23318. this.length -= s;
  23319. for (i = 0; i < this.length; i++) {
  23320. this.words[i] = this.words[i + s];
  23321. }
  23322. } else {
  23323. this.words[0] = 0;
  23324. this.length = 1;
  23325. }
  23326. var carry = 0;
  23327. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  23328. var word = this.words[i] | 0;
  23329. this.words[i] = carry << 26 - r | word >>> r;
  23330. carry = word & mask;
  23331. }
  23332. // Push carried bits as a mask
  23333. if (maskedWords && carry !== 0) {
  23334. maskedWords.words[maskedWords.length++] = carry;
  23335. }
  23336. if (this.length === 0) {
  23337. this.words[0] = 0;
  23338. this.length = 1;
  23339. }
  23340. return this._strip();
  23341. };
  23342. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  23343. // TODO(indutny): implement me
  23344. assert(this.negative === 0);
  23345. return this.iushrn(bits, hint, extended);
  23346. };
  23347. // Shift-left
  23348. BN.prototype.shln = function shln(bits) {
  23349. return this.clone().ishln(bits);
  23350. };
  23351. BN.prototype.ushln = function ushln(bits) {
  23352. return this.clone().iushln(bits);
  23353. };
  23354. // Shift-right
  23355. BN.prototype.shrn = function shrn(bits) {
  23356. return this.clone().ishrn(bits);
  23357. };
  23358. BN.prototype.ushrn = function ushrn(bits) {
  23359. return this.clone().iushrn(bits);
  23360. };
  23361. // Test if n bit is set
  23362. BN.prototype.testn = function testn(bit) {
  23363. assert(typeof bit === 'number' && bit >= 0);
  23364. var r = bit % 26;
  23365. var s = (bit - r) / 26;
  23366. var q = 1 << r;
  23367. // Fast case: bit is much higher than all existing words
  23368. if (this.length <= s) return false;
  23369. // Check bit and return
  23370. var w = this.words[s];
  23371. return !!(w & q);
  23372. };
  23373. // Return only lowers bits of number (in-place)
  23374. BN.prototype.imaskn = function imaskn(bits) {
  23375. assert(typeof bits === 'number' && bits >= 0);
  23376. var r = bits % 26;
  23377. var s = (bits - r) / 26;
  23378. assert(this.negative === 0, 'imaskn works only with positive numbers');
  23379. if (this.length <= s) {
  23380. return this;
  23381. }
  23382. if (r !== 0) {
  23383. s++;
  23384. }
  23385. this.length = Math.min(s, this.length);
  23386. if (r !== 0) {
  23387. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  23388. this.words[this.length - 1] &= mask;
  23389. }
  23390. return this._strip();
  23391. };
  23392. // Return only lowers bits of number
  23393. BN.prototype.maskn = function maskn(bits) {
  23394. return this.clone().imaskn(bits);
  23395. };
  23396. // Add plain number `num` to `this`
  23397. BN.prototype.iaddn = function iaddn(num) {
  23398. assert(typeof num === 'number');
  23399. assert(num < 0x4000000);
  23400. if (num < 0) return this.isubn(-num);
  23401. // Possible sign change
  23402. if (this.negative !== 0) {
  23403. if (this.length === 1 && (this.words[0] | 0) <= num) {
  23404. this.words[0] = num - (this.words[0] | 0);
  23405. this.negative = 0;
  23406. return this;
  23407. }
  23408. this.negative = 0;
  23409. this.isubn(num);
  23410. this.negative = 1;
  23411. return this;
  23412. }
  23413. // Add without checks
  23414. return this._iaddn(num);
  23415. };
  23416. BN.prototype._iaddn = function _iaddn(num) {
  23417. this.words[0] += num;
  23418. // Carry
  23419. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  23420. this.words[i] -= 0x4000000;
  23421. if (i === this.length - 1) {
  23422. this.words[i + 1] = 1;
  23423. } else {
  23424. this.words[i + 1]++;
  23425. }
  23426. }
  23427. this.length = Math.max(this.length, i + 1);
  23428. return this;
  23429. };
  23430. // Subtract plain number `num` from `this`
  23431. BN.prototype.isubn = function isubn(num) {
  23432. assert(typeof num === 'number');
  23433. assert(num < 0x4000000);
  23434. if (num < 0) return this.iaddn(-num);
  23435. if (this.negative !== 0) {
  23436. this.negative = 0;
  23437. this.iaddn(num);
  23438. this.negative = 1;
  23439. return this;
  23440. }
  23441. this.words[0] -= num;
  23442. if (this.length === 1 && this.words[0] < 0) {
  23443. this.words[0] = -this.words[0];
  23444. this.negative = 1;
  23445. } else {
  23446. // Carry
  23447. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  23448. this.words[i] += 0x4000000;
  23449. this.words[i + 1] -= 1;
  23450. }
  23451. }
  23452. return this._strip();
  23453. };
  23454. BN.prototype.addn = function addn(num) {
  23455. return this.clone().iaddn(num);
  23456. };
  23457. BN.prototype.subn = function subn(num) {
  23458. return this.clone().isubn(num);
  23459. };
  23460. BN.prototype.iabs = function iabs() {
  23461. this.negative = 0;
  23462. return this;
  23463. };
  23464. BN.prototype.abs = function abs() {
  23465. return this.clone().iabs();
  23466. };
  23467. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  23468. var len = num.length + shift;
  23469. var i;
  23470. this._expand(len);
  23471. var w;
  23472. var carry = 0;
  23473. for (i = 0; i < num.length; i++) {
  23474. w = (this.words[i + shift] | 0) + carry;
  23475. var right = (num.words[i] | 0) * mul;
  23476. w -= right & 0x3ffffff;
  23477. carry = (w >> 26) - (right / 0x4000000 | 0);
  23478. this.words[i + shift] = w & 0x3ffffff;
  23479. }
  23480. for (; i < this.length - shift; i++) {
  23481. w = (this.words[i + shift] | 0) + carry;
  23482. carry = w >> 26;
  23483. this.words[i + shift] = w & 0x3ffffff;
  23484. }
  23485. if (carry === 0) return this._strip();
  23486. // Subtraction overflow
  23487. assert(carry === -1);
  23488. carry = 0;
  23489. for (i = 0; i < this.length; i++) {
  23490. w = -(this.words[i] | 0) + carry;
  23491. carry = w >> 26;
  23492. this.words[i] = w & 0x3ffffff;
  23493. }
  23494. this.negative = 1;
  23495. return this._strip();
  23496. };
  23497. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  23498. var shift = this.length - num.length;
  23499. var a = this.clone();
  23500. var b = num;
  23501. // Normalize
  23502. var bhi = b.words[b.length - 1] | 0;
  23503. var bhiBits = this._countBits(bhi);
  23504. shift = 26 - bhiBits;
  23505. if (shift !== 0) {
  23506. b = b.ushln(shift);
  23507. a.iushln(shift);
  23508. bhi = b.words[b.length - 1] | 0;
  23509. }
  23510. // Initialize quotient
  23511. var m = a.length - b.length;
  23512. var q;
  23513. if (mode !== 'mod') {
  23514. q = new BN(null);
  23515. q.length = m + 1;
  23516. q.words = new Array(q.length);
  23517. for (var i = 0; i < q.length; i++) {
  23518. q.words[i] = 0;
  23519. }
  23520. }
  23521. var diff = a.clone()._ishlnsubmul(b, 1, m);
  23522. if (diff.negative === 0) {
  23523. a = diff;
  23524. if (q) {
  23525. q.words[m] = 1;
  23526. }
  23527. }
  23528. for (var j = m - 1; j >= 0; j--) {
  23529. var qj = (a.words[b.length + j] | 0) * 0x4000000 + (a.words[b.length + j - 1] | 0);
  23530. // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  23531. // (0x7ffffff)
  23532. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  23533. a._ishlnsubmul(b, qj, j);
  23534. while (a.negative !== 0) {
  23535. qj--;
  23536. a.negative = 0;
  23537. a._ishlnsubmul(b, 1, j);
  23538. if (!a.isZero()) {
  23539. a.negative ^= 1;
  23540. }
  23541. }
  23542. if (q) {
  23543. q.words[j] = qj;
  23544. }
  23545. }
  23546. if (q) {
  23547. q._strip();
  23548. }
  23549. a._strip();
  23550. // Denormalize
  23551. if (mode !== 'div' && shift !== 0) {
  23552. a.iushrn(shift);
  23553. }
  23554. return {
  23555. div: q || null,
  23556. mod: a
  23557. };
  23558. };
  23559. // NOTE: 1) `mode` can be set to `mod` to request mod only,
  23560. // to `div` to request div only, or be absent to
  23561. // request both div & mod
  23562. // 2) `positive` is true if unsigned mod is requested
  23563. BN.prototype.divmod = function divmod(num, mode, positive) {
  23564. assert(!num.isZero());
  23565. if (this.isZero()) {
  23566. return {
  23567. div: new BN(0),
  23568. mod: new BN(0)
  23569. };
  23570. }
  23571. var div, mod, res;
  23572. if (this.negative !== 0 && num.negative === 0) {
  23573. res = this.neg().divmod(num, mode);
  23574. if (mode !== 'mod') {
  23575. div = res.div.neg();
  23576. }
  23577. if (mode !== 'div') {
  23578. mod = res.mod.neg();
  23579. if (positive && mod.negative !== 0) {
  23580. mod.iadd(num);
  23581. }
  23582. }
  23583. return {
  23584. div: div,
  23585. mod: mod
  23586. };
  23587. }
  23588. if (this.negative === 0 && num.negative !== 0) {
  23589. res = this.divmod(num.neg(), mode);
  23590. if (mode !== 'mod') {
  23591. div = res.div.neg();
  23592. }
  23593. return {
  23594. div: div,
  23595. mod: res.mod
  23596. };
  23597. }
  23598. if ((this.negative & num.negative) !== 0) {
  23599. res = this.neg().divmod(num.neg(), mode);
  23600. if (mode !== 'div') {
  23601. mod = res.mod.neg();
  23602. if (positive && mod.negative !== 0) {
  23603. mod.isub(num);
  23604. }
  23605. }
  23606. return {
  23607. div: res.div,
  23608. mod: mod
  23609. };
  23610. }
  23611. // Both numbers are positive at this point
  23612. // Strip both numbers to approximate shift value
  23613. if (num.length > this.length || this.cmp(num) < 0) {
  23614. return {
  23615. div: new BN(0),
  23616. mod: this
  23617. };
  23618. }
  23619. // Very short reduction
  23620. if (num.length === 1) {
  23621. if (mode === 'div') {
  23622. return {
  23623. div: this.divn(num.words[0]),
  23624. mod: null
  23625. };
  23626. }
  23627. if (mode === 'mod') {
  23628. return {
  23629. div: null,
  23630. mod: new BN(this.modrn(num.words[0]))
  23631. };
  23632. }
  23633. return {
  23634. div: this.divn(num.words[0]),
  23635. mod: new BN(this.modrn(num.words[0]))
  23636. };
  23637. }
  23638. return this._wordDiv(num, mode);
  23639. };
  23640. // Find `this` / `num`
  23641. BN.prototype.div = function div(num) {
  23642. return this.divmod(num, 'div', false).div;
  23643. };
  23644. // Find `this` % `num`
  23645. BN.prototype.mod = function mod(num) {
  23646. return this.divmod(num, 'mod', false).mod;
  23647. };
  23648. BN.prototype.umod = function umod(num) {
  23649. return this.divmod(num, 'mod', true).mod;
  23650. };
  23651. // Find Round(`this` / `num`)
  23652. BN.prototype.divRound = function divRound(num) {
  23653. var dm = this.divmod(num);
  23654. // Fast case - exact division
  23655. if (dm.mod.isZero()) return dm.div;
  23656. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  23657. var half = num.ushrn(1);
  23658. var r2 = num.andln(1);
  23659. var cmp = mod.cmp(half);
  23660. // Round down
  23661. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
  23662. // Round up
  23663. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  23664. };
  23665. BN.prototype.modrn = function modrn(num) {
  23666. var isNegNum = num < 0;
  23667. if (isNegNum) num = -num;
  23668. assert(num <= 0x3ffffff);
  23669. var p = (1 << 26) % num;
  23670. var acc = 0;
  23671. for (var i = this.length - 1; i >= 0; i--) {
  23672. acc = (p * acc + (this.words[i] | 0)) % num;
  23673. }
  23674. return isNegNum ? -acc : acc;
  23675. };
  23676. // WARNING: DEPRECATED
  23677. BN.prototype.modn = function modn(num) {
  23678. return this.modrn(num);
  23679. };
  23680. // In-place division by number
  23681. BN.prototype.idivn = function idivn(num) {
  23682. var isNegNum = num < 0;
  23683. if (isNegNum) num = -num;
  23684. assert(num <= 0x3ffffff);
  23685. var carry = 0;
  23686. for (var i = this.length - 1; i >= 0; i--) {
  23687. var w = (this.words[i] | 0) + carry * 0x4000000;
  23688. this.words[i] = w / num | 0;
  23689. carry = w % num;
  23690. }
  23691. this._strip();
  23692. return isNegNum ? this.ineg() : this;
  23693. };
  23694. BN.prototype.divn = function divn(num) {
  23695. return this.clone().idivn(num);
  23696. };
  23697. BN.prototype.egcd = function egcd(p) {
  23698. assert(p.negative === 0);
  23699. assert(!p.isZero());
  23700. var x = this;
  23701. var y = p.clone();
  23702. if (x.negative !== 0) {
  23703. x = x.umod(p);
  23704. } else {
  23705. x = x.clone();
  23706. }
  23707. // A * x + B * y = x
  23708. var A = new BN(1);
  23709. var B = new BN(0);
  23710. // C * x + D * y = y
  23711. var C = new BN(0);
  23712. var D = new BN(1);
  23713. var g = 0;
  23714. while (x.isEven() && y.isEven()) {
  23715. x.iushrn(1);
  23716. y.iushrn(1);
  23717. ++g;
  23718. }
  23719. var yp = y.clone();
  23720. var xp = x.clone();
  23721. while (!x.isZero()) {
  23722. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  23723. if (i > 0) {
  23724. x.iushrn(i);
  23725. while (i-- > 0) {
  23726. if (A.isOdd() || B.isOdd()) {
  23727. A.iadd(yp);
  23728. B.isub(xp);
  23729. }
  23730. A.iushrn(1);
  23731. B.iushrn(1);
  23732. }
  23733. }
  23734. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  23735. if (j > 0) {
  23736. y.iushrn(j);
  23737. while (j-- > 0) {
  23738. if (C.isOdd() || D.isOdd()) {
  23739. C.iadd(yp);
  23740. D.isub(xp);
  23741. }
  23742. C.iushrn(1);
  23743. D.iushrn(1);
  23744. }
  23745. }
  23746. if (x.cmp(y) >= 0) {
  23747. x.isub(y);
  23748. A.isub(C);
  23749. B.isub(D);
  23750. } else {
  23751. y.isub(x);
  23752. C.isub(A);
  23753. D.isub(B);
  23754. }
  23755. }
  23756. return {
  23757. a: C,
  23758. b: D,
  23759. gcd: y.iushln(g)
  23760. };
  23761. };
  23762. // This is reduced incarnation of the binary EEA
  23763. // above, designated to invert members of the
  23764. // _prime_ fields F(p) at a maximal speed
  23765. BN.prototype._invmp = function _invmp(p) {
  23766. assert(p.negative === 0);
  23767. assert(!p.isZero());
  23768. var a = this;
  23769. var b = p.clone();
  23770. if (a.negative !== 0) {
  23771. a = a.umod(p);
  23772. } else {
  23773. a = a.clone();
  23774. }
  23775. var x1 = new BN(1);
  23776. var x2 = new BN(0);
  23777. var delta = b.clone();
  23778. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  23779. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
  23780. if (i > 0) {
  23781. a.iushrn(i);
  23782. while (i-- > 0) {
  23783. if (x1.isOdd()) {
  23784. x1.iadd(delta);
  23785. }
  23786. x1.iushrn(1);
  23787. }
  23788. }
  23789. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
  23790. if (j > 0) {
  23791. b.iushrn(j);
  23792. while (j-- > 0) {
  23793. if (x2.isOdd()) {
  23794. x2.iadd(delta);
  23795. }
  23796. x2.iushrn(1);
  23797. }
  23798. }
  23799. if (a.cmp(b) >= 0) {
  23800. a.isub(b);
  23801. x1.isub(x2);
  23802. } else {
  23803. b.isub(a);
  23804. x2.isub(x1);
  23805. }
  23806. }
  23807. var res;
  23808. if (a.cmpn(1) === 0) {
  23809. res = x1;
  23810. } else {
  23811. res = x2;
  23812. }
  23813. if (res.cmpn(0) < 0) {
  23814. res.iadd(p);
  23815. }
  23816. return res;
  23817. };
  23818. BN.prototype.gcd = function gcd(num) {
  23819. if (this.isZero()) return num.abs();
  23820. if (num.isZero()) return this.abs();
  23821. var a = this.clone();
  23822. var b = num.clone();
  23823. a.negative = 0;
  23824. b.negative = 0;
  23825. // Remove common factor of two
  23826. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  23827. a.iushrn(1);
  23828. b.iushrn(1);
  23829. }
  23830. do {
  23831. while (a.isEven()) {
  23832. a.iushrn(1);
  23833. }
  23834. while (b.isEven()) {
  23835. b.iushrn(1);
  23836. }
  23837. var r = a.cmp(b);
  23838. if (r < 0) {
  23839. // Swap `a` and `b` to make `a` always bigger than `b`
  23840. var t = a;
  23841. a = b;
  23842. b = t;
  23843. } else if (r === 0 || b.cmpn(1) === 0) {
  23844. break;
  23845. }
  23846. a.isub(b);
  23847. } while (true);
  23848. return b.iushln(shift);
  23849. };
  23850. // Invert number in the field F(num)
  23851. BN.prototype.invm = function invm(num) {
  23852. return this.egcd(num).a.umod(num);
  23853. };
  23854. BN.prototype.isEven = function isEven() {
  23855. return (this.words[0] & 1) === 0;
  23856. };
  23857. BN.prototype.isOdd = function isOdd() {
  23858. return (this.words[0] & 1) === 1;
  23859. };
  23860. // And first word and num
  23861. BN.prototype.andln = function andln(num) {
  23862. return this.words[0] & num;
  23863. };
  23864. // Increment at the bit position in-line
  23865. BN.prototype.bincn = function bincn(bit) {
  23866. assert(typeof bit === 'number');
  23867. var r = bit % 26;
  23868. var s = (bit - r) / 26;
  23869. var q = 1 << r;
  23870. // Fast case: bit is much higher than all existing words
  23871. if (this.length <= s) {
  23872. this._expand(s + 1);
  23873. this.words[s] |= q;
  23874. return this;
  23875. }
  23876. // Add bit and propagate, if needed
  23877. var carry = q;
  23878. for (var i = s; carry !== 0 && i < this.length; i++) {
  23879. var w = this.words[i] | 0;
  23880. w += carry;
  23881. carry = w >>> 26;
  23882. w &= 0x3ffffff;
  23883. this.words[i] = w;
  23884. }
  23885. if (carry !== 0) {
  23886. this.words[i] = carry;
  23887. this.length++;
  23888. }
  23889. return this;
  23890. };
  23891. BN.prototype.isZero = function isZero() {
  23892. return this.length === 1 && this.words[0] === 0;
  23893. };
  23894. BN.prototype.cmpn = function cmpn(num) {
  23895. var negative = num < 0;
  23896. if (this.negative !== 0 && !negative) return -1;
  23897. if (this.negative === 0 && negative) return 1;
  23898. this._strip();
  23899. var res;
  23900. if (this.length > 1) {
  23901. res = 1;
  23902. } else {
  23903. if (negative) {
  23904. num = -num;
  23905. }
  23906. assert(num <= 0x3ffffff, 'Number is too big');
  23907. var w = this.words[0] | 0;
  23908. res = w === num ? 0 : w < num ? -1 : 1;
  23909. }
  23910. if (this.negative !== 0) return -res | 0;
  23911. return res;
  23912. };
  23913. // Compare two numbers and return:
  23914. // 1 - if `this` > `num`
  23915. // 0 - if `this` == `num`
  23916. // -1 - if `this` < `num`
  23917. BN.prototype.cmp = function cmp(num) {
  23918. if (this.negative !== 0 && num.negative === 0) return -1;
  23919. if (this.negative === 0 && num.negative !== 0) return 1;
  23920. var res = this.ucmp(num);
  23921. if (this.negative !== 0) return -res | 0;
  23922. return res;
  23923. };
  23924. // Unsigned comparison
  23925. BN.prototype.ucmp = function ucmp(num) {
  23926. // At this point both numbers have the same sign
  23927. if (this.length > num.length) return 1;
  23928. if (this.length < num.length) return -1;
  23929. var res = 0;
  23930. for (var i = this.length - 1; i >= 0; i--) {
  23931. var a = this.words[i] | 0;
  23932. var b = num.words[i] | 0;
  23933. if (a === b) continue;
  23934. if (a < b) {
  23935. res = -1;
  23936. } else if (a > b) {
  23937. res = 1;
  23938. }
  23939. break;
  23940. }
  23941. return res;
  23942. };
  23943. BN.prototype.gtn = function gtn(num) {
  23944. return this.cmpn(num) === 1;
  23945. };
  23946. BN.prototype.gt = function gt(num) {
  23947. return this.cmp(num) === 1;
  23948. };
  23949. BN.prototype.gten = function gten(num) {
  23950. return this.cmpn(num) >= 0;
  23951. };
  23952. BN.prototype.gte = function gte(num) {
  23953. return this.cmp(num) >= 0;
  23954. };
  23955. BN.prototype.ltn = function ltn(num) {
  23956. return this.cmpn(num) === -1;
  23957. };
  23958. BN.prototype.lt = function lt(num) {
  23959. return this.cmp(num) === -1;
  23960. };
  23961. BN.prototype.lten = function lten(num) {
  23962. return this.cmpn(num) <= 0;
  23963. };
  23964. BN.prototype.lte = function lte(num) {
  23965. return this.cmp(num) <= 0;
  23966. };
  23967. BN.prototype.eqn = function eqn(num) {
  23968. return this.cmpn(num) === 0;
  23969. };
  23970. BN.prototype.eq = function eq(num) {
  23971. return this.cmp(num) === 0;
  23972. };
  23973. //
  23974. // A reduce context, could be using montgomery or something better, depending
  23975. // on the `m` itself.
  23976. //
  23977. BN.red = function red(num) {
  23978. return new Red(num);
  23979. };
  23980. BN.prototype.toRed = function toRed(ctx) {
  23981. assert(!this.red, 'Already a number in reduction context');
  23982. assert(this.negative === 0, 'red works only with positives');
  23983. return ctx.convertTo(this)._forceRed(ctx);
  23984. };
  23985. BN.prototype.fromRed = function fromRed() {
  23986. assert(this.red, 'fromRed works only with numbers in reduction context');
  23987. return this.red.convertFrom(this);
  23988. };
  23989. BN.prototype._forceRed = function _forceRed(ctx) {
  23990. this.red = ctx;
  23991. return this;
  23992. };
  23993. BN.prototype.forceRed = function forceRed(ctx) {
  23994. assert(!this.red, 'Already a number in reduction context');
  23995. return this._forceRed(ctx);
  23996. };
  23997. BN.prototype.redAdd = function redAdd(num) {
  23998. assert(this.red, 'redAdd works only with red numbers');
  23999. return this.red.add(this, num);
  24000. };
  24001. BN.prototype.redIAdd = function redIAdd(num) {
  24002. assert(this.red, 'redIAdd works only with red numbers');
  24003. return this.red.iadd(this, num);
  24004. };
  24005. BN.prototype.redSub = function redSub(num) {
  24006. assert(this.red, 'redSub works only with red numbers');
  24007. return this.red.sub(this, num);
  24008. };
  24009. BN.prototype.redISub = function redISub(num) {
  24010. assert(this.red, 'redISub works only with red numbers');
  24011. return this.red.isub(this, num);
  24012. };
  24013. BN.prototype.redShl = function redShl(num) {
  24014. assert(this.red, 'redShl works only with red numbers');
  24015. return this.red.shl(this, num);
  24016. };
  24017. BN.prototype.redMul = function redMul(num) {
  24018. assert(this.red, 'redMul works only with red numbers');
  24019. this.red._verify2(this, num);
  24020. return this.red.mul(this, num);
  24021. };
  24022. BN.prototype.redIMul = function redIMul(num) {
  24023. assert(this.red, 'redMul works only with red numbers');
  24024. this.red._verify2(this, num);
  24025. return this.red.imul(this, num);
  24026. };
  24027. BN.prototype.redSqr = function redSqr() {
  24028. assert(this.red, 'redSqr works only with red numbers');
  24029. this.red._verify1(this);
  24030. return this.red.sqr(this);
  24031. };
  24032. BN.prototype.redISqr = function redISqr() {
  24033. assert(this.red, 'redISqr works only with red numbers');
  24034. this.red._verify1(this);
  24035. return this.red.isqr(this);
  24036. };
  24037. // Square root over p
  24038. BN.prototype.redSqrt = function redSqrt() {
  24039. assert(this.red, 'redSqrt works only with red numbers');
  24040. this.red._verify1(this);
  24041. return this.red.sqrt(this);
  24042. };
  24043. BN.prototype.redInvm = function redInvm() {
  24044. assert(this.red, 'redInvm works only with red numbers');
  24045. this.red._verify1(this);
  24046. return this.red.invm(this);
  24047. };
  24048. // Return negative clone of `this` % `red modulo`
  24049. BN.prototype.redNeg = function redNeg() {
  24050. assert(this.red, 'redNeg works only with red numbers');
  24051. this.red._verify1(this);
  24052. return this.red.neg(this);
  24053. };
  24054. BN.prototype.redPow = function redPow(num) {
  24055. assert(this.red && !num.red, 'redPow(normalNum)');
  24056. this.red._verify1(this);
  24057. return this.red.pow(this, num);
  24058. };
  24059. // Prime numbers with efficient reduction
  24060. var primes = {
  24061. k256: null,
  24062. p224: null,
  24063. p192: null,
  24064. p25519: null
  24065. };
  24066. // Pseudo-Mersenne prime
  24067. function MPrime(name, p) {
  24068. // P = 2 ^ N - K
  24069. this.name = name;
  24070. this.p = new BN(p, 16);
  24071. this.n = this.p.bitLength();
  24072. this.k = new BN(1).iushln(this.n).isub(this.p);
  24073. this.tmp = this._tmp();
  24074. }
  24075. MPrime.prototype._tmp = function _tmp() {
  24076. var tmp = new BN(null);
  24077. tmp.words = new Array(Math.ceil(this.n / 13));
  24078. return tmp;
  24079. };
  24080. MPrime.prototype.ireduce = function ireduce(num) {
  24081. // Assumes that `num` is less than `P^2`
  24082. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  24083. var r = num;
  24084. var rlen;
  24085. do {
  24086. this.split(r, this.tmp);
  24087. r = this.imulK(r);
  24088. r = r.iadd(this.tmp);
  24089. rlen = r.bitLength();
  24090. } while (rlen > this.n);
  24091. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  24092. if (cmp === 0) {
  24093. r.words[0] = 0;
  24094. r.length = 1;
  24095. } else if (cmp > 0) {
  24096. r.isub(this.p);
  24097. } else {
  24098. if (r.strip !== undefined) {
  24099. // r is a BN v4 instance
  24100. r.strip();
  24101. } else {
  24102. // r is a BN v5 instance
  24103. r._strip();
  24104. }
  24105. }
  24106. return r;
  24107. };
  24108. MPrime.prototype.split = function split(input, out) {
  24109. input.iushrn(this.n, 0, out);
  24110. };
  24111. MPrime.prototype.imulK = function imulK(num) {
  24112. return num.imul(this.k);
  24113. };
  24114. function K256() {
  24115. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  24116. }
  24117. inherits(K256, MPrime);
  24118. K256.prototype.split = function split(input, output) {
  24119. // 256 = 9 * 26 + 22
  24120. var mask = 0x3fffff;
  24121. var outLen = Math.min(input.length, 9);
  24122. for (var i = 0; i < outLen; i++) {
  24123. output.words[i] = input.words[i];
  24124. }
  24125. output.length = outLen;
  24126. if (input.length <= 9) {
  24127. input.words[0] = 0;
  24128. input.length = 1;
  24129. return;
  24130. }
  24131. // Shift by 9 limbs
  24132. var prev = input.words[9];
  24133. output.words[output.length++] = prev & mask;
  24134. for (i = 10; i < input.length; i++) {
  24135. var next = input.words[i] | 0;
  24136. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  24137. prev = next;
  24138. }
  24139. prev >>>= 22;
  24140. input.words[i - 10] = prev;
  24141. if (prev === 0 && input.length > 10) {
  24142. input.length -= 10;
  24143. } else {
  24144. input.length -= 9;
  24145. }
  24146. };
  24147. K256.prototype.imulK = function imulK(num) {
  24148. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  24149. num.words[num.length] = 0;
  24150. num.words[num.length + 1] = 0;
  24151. num.length += 2;
  24152. // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  24153. var lo = 0;
  24154. for (var i = 0; i < num.length; i++) {
  24155. var w = num.words[i] | 0;
  24156. lo += w * 0x3d1;
  24157. num.words[i] = lo & 0x3ffffff;
  24158. lo = w * 0x40 + (lo / 0x4000000 | 0);
  24159. }
  24160. // Fast length reduction
  24161. if (num.words[num.length - 1] === 0) {
  24162. num.length--;
  24163. if (num.words[num.length - 1] === 0) {
  24164. num.length--;
  24165. }
  24166. }
  24167. return num;
  24168. };
  24169. function P224() {
  24170. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  24171. }
  24172. inherits(P224, MPrime);
  24173. function P192() {
  24174. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  24175. }
  24176. inherits(P192, MPrime);
  24177. function P25519() {
  24178. // 2 ^ 255 - 19
  24179. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  24180. }
  24181. inherits(P25519, MPrime);
  24182. P25519.prototype.imulK = function imulK(num) {
  24183. // K = 0x13
  24184. var carry = 0;
  24185. for (var i = 0; i < num.length; i++) {
  24186. var hi = (num.words[i] | 0) * 0x13 + carry;
  24187. var lo = hi & 0x3ffffff;
  24188. hi >>>= 26;
  24189. num.words[i] = lo;
  24190. carry = hi;
  24191. }
  24192. if (carry !== 0) {
  24193. num.words[num.length++] = carry;
  24194. }
  24195. return num;
  24196. };
  24197. // Exported mostly for testing purposes, use plain name instead
  24198. BN._prime = function prime(name) {
  24199. // Cached version of prime
  24200. if (primes[name]) return primes[name];
  24201. var prime;
  24202. if (name === 'k256') {
  24203. prime = new K256();
  24204. } else if (name === 'p224') {
  24205. prime = new P224();
  24206. } else if (name === 'p192') {
  24207. prime = new P192();
  24208. } else if (name === 'p25519') {
  24209. prime = new P25519();
  24210. } else {
  24211. throw new Error('Unknown prime ' + name);
  24212. }
  24213. primes[name] = prime;
  24214. return prime;
  24215. };
  24216. //
  24217. // Base reduction engine
  24218. //
  24219. function Red(m) {
  24220. if (typeof m === 'string') {
  24221. var prime = BN._prime(m);
  24222. this.m = prime.p;
  24223. this.prime = prime;
  24224. } else {
  24225. assert(m.gtn(1), 'modulus must be greater than 1');
  24226. this.m = m;
  24227. this.prime = null;
  24228. }
  24229. }
  24230. Red.prototype._verify1 = function _verify1(a) {
  24231. assert(a.negative === 0, 'red works only with positives');
  24232. assert(a.red, 'red works only with red numbers');
  24233. };
  24234. Red.prototype._verify2 = function _verify2(a, b) {
  24235. assert((a.negative | b.negative) === 0, 'red works only with positives');
  24236. assert(a.red && a.red === b.red, 'red works only with red numbers');
  24237. };
  24238. Red.prototype.imod = function imod(a) {
  24239. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  24240. move(a, a.umod(this.m)._forceRed(this));
  24241. return a;
  24242. };
  24243. Red.prototype.neg = function neg(a) {
  24244. if (a.isZero()) {
  24245. return a.clone();
  24246. }
  24247. return this.m.sub(a)._forceRed(this);
  24248. };
  24249. Red.prototype.add = function add(a, b) {
  24250. this._verify2(a, b);
  24251. var res = a.add(b);
  24252. if (res.cmp(this.m) >= 0) {
  24253. res.isub(this.m);
  24254. }
  24255. return res._forceRed(this);
  24256. };
  24257. Red.prototype.iadd = function iadd(a, b) {
  24258. this._verify2(a, b);
  24259. var res = a.iadd(b);
  24260. if (res.cmp(this.m) >= 0) {
  24261. res.isub(this.m);
  24262. }
  24263. return res;
  24264. };
  24265. Red.prototype.sub = function sub(a, b) {
  24266. this._verify2(a, b);
  24267. var res = a.sub(b);
  24268. if (res.cmpn(0) < 0) {
  24269. res.iadd(this.m);
  24270. }
  24271. return res._forceRed(this);
  24272. };
  24273. Red.prototype.isub = function isub(a, b) {
  24274. this._verify2(a, b);
  24275. var res = a.isub(b);
  24276. if (res.cmpn(0) < 0) {
  24277. res.iadd(this.m);
  24278. }
  24279. return res;
  24280. };
  24281. Red.prototype.shl = function shl(a, num) {
  24282. this._verify1(a);
  24283. return this.imod(a.ushln(num));
  24284. };
  24285. Red.prototype.imul = function imul(a, b) {
  24286. this._verify2(a, b);
  24287. return this.imod(a.imul(b));
  24288. };
  24289. Red.prototype.mul = function mul(a, b) {
  24290. this._verify2(a, b);
  24291. return this.imod(a.mul(b));
  24292. };
  24293. Red.prototype.isqr = function isqr(a) {
  24294. return this.imul(a, a.clone());
  24295. };
  24296. Red.prototype.sqr = function sqr(a) {
  24297. return this.mul(a, a);
  24298. };
  24299. Red.prototype.sqrt = function sqrt(a) {
  24300. if (a.isZero()) return a.clone();
  24301. var mod3 = this.m.andln(3);
  24302. assert(mod3 % 2 === 1);
  24303. // Fast case
  24304. if (mod3 === 3) {
  24305. var pow = this.m.add(new BN(1)).iushrn(2);
  24306. return this.pow(a, pow);
  24307. }
  24308. // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  24309. //
  24310. // Find Q and S, that Q * 2 ^ S = (P - 1)
  24311. var q = this.m.subn(1);
  24312. var s = 0;
  24313. while (!q.isZero() && q.andln(1) === 0) {
  24314. s++;
  24315. q.iushrn(1);
  24316. }
  24317. assert(!q.isZero());
  24318. var one = new BN(1).toRed(this);
  24319. var nOne = one.redNeg();
  24320. // Find quadratic non-residue
  24321. // NOTE: Max is such because of generalized Riemann hypothesis.
  24322. var lpow = this.m.subn(1).iushrn(1);
  24323. var z = this.m.bitLength();
  24324. z = new BN(2 * z * z).toRed(this);
  24325. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  24326. z.redIAdd(nOne);
  24327. }
  24328. var c = this.pow(z, q);
  24329. var r = this.pow(a, q.addn(1).iushrn(1));
  24330. var t = this.pow(a, q);
  24331. var m = s;
  24332. while (t.cmp(one) !== 0) {
  24333. var tmp = t;
  24334. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  24335. tmp = tmp.redSqr();
  24336. }
  24337. assert(i < m);
  24338. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  24339. r = r.redMul(b);
  24340. c = b.redSqr();
  24341. t = t.redMul(c);
  24342. m = i;
  24343. }
  24344. return r;
  24345. };
  24346. Red.prototype.invm = function invm(a) {
  24347. var inv = a._invmp(this.m);
  24348. if (inv.negative !== 0) {
  24349. inv.negative = 0;
  24350. return this.imod(inv).redNeg();
  24351. } else {
  24352. return this.imod(inv);
  24353. }
  24354. };
  24355. Red.prototype.pow = function pow(a, num) {
  24356. if (num.isZero()) return new BN(1).toRed(this);
  24357. if (num.cmpn(1) === 0) return a.clone();
  24358. var windowSize = 4;
  24359. var wnd = new Array(1 << windowSize);
  24360. wnd[0] = new BN(1).toRed(this);
  24361. wnd[1] = a;
  24362. for (var i = 2; i < wnd.length; i++) {
  24363. wnd[i] = this.mul(wnd[i - 1], a);
  24364. }
  24365. var res = wnd[0];
  24366. var current = 0;
  24367. var currentLen = 0;
  24368. var start = num.bitLength() % 26;
  24369. if (start === 0) {
  24370. start = 26;
  24371. }
  24372. for (i = num.length - 1; i >= 0; i--) {
  24373. var word = num.words[i];
  24374. for (var j = start - 1; j >= 0; j--) {
  24375. var bit = word >> j & 1;
  24376. if (res !== wnd[0]) {
  24377. res = this.sqr(res);
  24378. }
  24379. if (bit === 0 && current === 0) {
  24380. currentLen = 0;
  24381. continue;
  24382. }
  24383. current <<= 1;
  24384. current |= bit;
  24385. currentLen++;
  24386. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  24387. res = this.mul(res, wnd[current]);
  24388. currentLen = 0;
  24389. current = 0;
  24390. }
  24391. start = 26;
  24392. }
  24393. return res;
  24394. };
  24395. Red.prototype.convertTo = function convertTo(num) {
  24396. var r = num.umod(this.m);
  24397. return r === num ? r.clone() : r;
  24398. };
  24399. Red.prototype.convertFrom = function convertFrom(num) {
  24400. var res = num.clone();
  24401. res.red = null;
  24402. return res;
  24403. };
  24404. //
  24405. // Montgomery method engine
  24406. //
  24407. BN.mont = function mont(num) {
  24408. return new Mont(num);
  24409. };
  24410. function Mont(m) {
  24411. Red.call(this, m);
  24412. this.shift = this.m.bitLength();
  24413. if (this.shift % 26 !== 0) {
  24414. this.shift += 26 - this.shift % 26;
  24415. }
  24416. this.r = new BN(1).iushln(this.shift);
  24417. this.r2 = this.imod(this.r.sqr());
  24418. this.rinv = this.r._invmp(this.m);
  24419. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  24420. this.minv = this.minv.umod(this.r);
  24421. this.minv = this.r.sub(this.minv);
  24422. }
  24423. inherits(Mont, Red);
  24424. Mont.prototype.convertTo = function convertTo(num) {
  24425. return this.imod(num.ushln(this.shift));
  24426. };
  24427. Mont.prototype.convertFrom = function convertFrom(num) {
  24428. var r = this.imod(num.mul(this.rinv));
  24429. r.red = null;
  24430. return r;
  24431. };
  24432. Mont.prototype.imul = function imul(a, b) {
  24433. if (a.isZero() || b.isZero()) {
  24434. a.words[0] = 0;
  24435. a.length = 1;
  24436. return a;
  24437. }
  24438. var t = a.imul(b);
  24439. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  24440. var u = t.isub(c).iushrn(this.shift);
  24441. var res = u;
  24442. if (u.cmp(this.m) >= 0) {
  24443. res = u.isub(this.m);
  24444. } else if (u.cmpn(0) < 0) {
  24445. res = u.iadd(this.m);
  24446. }
  24447. return res._forceRed(this);
  24448. };
  24449. Mont.prototype.mul = function mul(a, b) {
  24450. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  24451. var t = a.mul(b);
  24452. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  24453. var u = t.isub(c).iushrn(this.shift);
  24454. var res = u;
  24455. if (u.cmp(this.m) >= 0) {
  24456. res = u.isub(this.m);
  24457. } else if (u.cmpn(0) < 0) {
  24458. res = u.iadd(this.m);
  24459. }
  24460. return res._forceRed(this);
  24461. };
  24462. Mont.prototype.invm = function invm(a) {
  24463. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  24464. var res = this.imod(a._invmp(this.m).mul(this.r2));
  24465. return res._forceRed(this);
  24466. };
  24467. })(typeof module === 'undefined' || module, void 0);
  24468. },{"buffer":188}],187:[function(require,module,exports){
  24469. "use strict";
  24470. var r;
  24471. module.exports = function rand(len) {
  24472. if (!r) r = new Rand(null);
  24473. return r.generate(len);
  24474. };
  24475. function Rand(rand) {
  24476. this.rand = rand;
  24477. }
  24478. module.exports.Rand = Rand;
  24479. Rand.prototype.generate = function generate(len) {
  24480. return this._rand(len);
  24481. };
  24482. // Emulate crypto API using randy
  24483. Rand.prototype._rand = function _rand(n) {
  24484. if (this.rand.getBytes) return this.rand.getBytes(n);
  24485. var res = new Uint8Array(n);
  24486. for (var i = 0; i < res.length; i++) res[i] = this.rand.getByte();
  24487. return res;
  24488. };
  24489. if (typeof self === 'object') {
  24490. if (self.crypto && self.crypto.getRandomValues) {
  24491. // Modern browsers
  24492. Rand.prototype._rand = function _rand(n) {
  24493. var arr = new Uint8Array(n);
  24494. self.crypto.getRandomValues(arr);
  24495. return arr;
  24496. };
  24497. } else if (self.msCrypto && self.msCrypto.getRandomValues) {
  24498. // IE
  24499. Rand.prototype._rand = function _rand(n) {
  24500. var arr = new Uint8Array(n);
  24501. self.msCrypto.getRandomValues(arr);
  24502. return arr;
  24503. };
  24504. // Safari's WebWorkers do not have `crypto`
  24505. } else if (typeof window === 'object') {
  24506. // Old junk
  24507. Rand.prototype._rand = function () {
  24508. throw new Error('Not implemented yet');
  24509. };
  24510. }
  24511. } else {
  24512. // Node.js or Web worker with no crypto support
  24513. try {
  24514. var crypto = require('crypto');
  24515. if (typeof crypto.randomBytes !== 'function') throw new Error('Not supported');
  24516. Rand.prototype._rand = function _rand(n) {
  24517. return crypto.randomBytes(n);
  24518. };
  24519. } catch (e) {}
  24520. }
  24521. },{"crypto":188}],188:[function(require,module,exports){
  24522. "use strict";
  24523. },{}],189:[function(require,module,exports){
  24524. "use strict";
  24525. // based on the aes implimentation in triple sec
  24526. // https://github.com/keybase/triplesec
  24527. // which is in turn based on the one from crypto-js
  24528. // https://code.google.com/p/crypto-js/
  24529. var Buffer = require('safe-buffer').Buffer;
  24530. function asUInt32Array(buf) {
  24531. if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
  24532. var len = buf.length / 4 | 0;
  24533. var out = new Array(len);
  24534. for (var i = 0; i < len; i++) {
  24535. out[i] = buf.readUInt32BE(i * 4);
  24536. }
  24537. return out;
  24538. }
  24539. function scrubVec(v) {
  24540. for (var i = 0; i < v.length; v++) {
  24541. v[i] = 0;
  24542. }
  24543. }
  24544. function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) {
  24545. var SUB_MIX0 = SUB_MIX[0];
  24546. var SUB_MIX1 = SUB_MIX[1];
  24547. var SUB_MIX2 = SUB_MIX[2];
  24548. var SUB_MIX3 = SUB_MIX[3];
  24549. var s0 = M[0] ^ keySchedule[0];
  24550. var s1 = M[1] ^ keySchedule[1];
  24551. var s2 = M[2] ^ keySchedule[2];
  24552. var s3 = M[3] ^ keySchedule[3];
  24553. var t0, t1, t2, t3;
  24554. var ksRow = 4;
  24555. for (var round = 1; round < nRounds; round++) {
  24556. t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 0xff] ^ SUB_MIX2[s2 >>> 8 & 0xff] ^ SUB_MIX3[s3 & 0xff] ^ keySchedule[ksRow++];
  24557. t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 0xff] ^ SUB_MIX2[s3 >>> 8 & 0xff] ^ SUB_MIX3[s0 & 0xff] ^ keySchedule[ksRow++];
  24558. t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 0xff] ^ SUB_MIX2[s0 >>> 8 & 0xff] ^ SUB_MIX3[s1 & 0xff] ^ keySchedule[ksRow++];
  24559. t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 0xff] ^ SUB_MIX2[s1 >>> 8 & 0xff] ^ SUB_MIX3[s2 & 0xff] ^ keySchedule[ksRow++];
  24560. s0 = t0;
  24561. s1 = t1;
  24562. s2 = t2;
  24563. s3 = t3;
  24564. }
  24565. t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 0xff] << 16 | SBOX[s2 >>> 8 & 0xff] << 8 | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  24566. t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 0xff] << 16 | SBOX[s3 >>> 8 & 0xff] << 8 | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  24567. t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 0xff] << 16 | SBOX[s0 >>> 8 & 0xff] << 8 | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  24568. t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 0xff] << 16 | SBOX[s1 >>> 8 & 0xff] << 8 | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  24569. t0 = t0 >>> 0;
  24570. t1 = t1 >>> 0;
  24571. t2 = t2 >>> 0;
  24572. t3 = t3 >>> 0;
  24573. return [t0, t1, t2, t3];
  24574. }
  24575. // AES constants
  24576. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  24577. var G = function () {
  24578. // Compute double table
  24579. var d = new Array(256);
  24580. for (var j = 0; j < 256; j++) {
  24581. if (j < 128) {
  24582. d[j] = j << 1;
  24583. } else {
  24584. d[j] = j << 1 ^ 0x11b;
  24585. }
  24586. }
  24587. var SBOX = [];
  24588. var INV_SBOX = [];
  24589. var SUB_MIX = [[], [], [], []];
  24590. var INV_SUB_MIX = [[], [], [], []];
  24591. // Walk GF(2^8)
  24592. var x = 0;
  24593. var xi = 0;
  24594. for (var i = 0; i < 256; ++i) {
  24595. // Compute sbox
  24596. var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4;
  24597. sx = sx >>> 8 ^ sx & 0xff ^ 0x63;
  24598. SBOX[x] = sx;
  24599. INV_SBOX[sx] = x;
  24600. // Compute multiplication
  24601. var x2 = d[x];
  24602. var x4 = d[x2];
  24603. var x8 = d[x4];
  24604. // Compute sub bytes, mix columns tables
  24605. var t = d[sx] * 0x101 ^ sx * 0x1010100;
  24606. SUB_MIX[0][x] = t << 24 | t >>> 8;
  24607. SUB_MIX[1][x] = t << 16 | t >>> 16;
  24608. SUB_MIX[2][x] = t << 8 | t >>> 24;
  24609. SUB_MIX[3][x] = t;
  24610. // Compute inv sub bytes, inv mix columns tables
  24611. t = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  24612. INV_SUB_MIX[0][sx] = t << 24 | t >>> 8;
  24613. INV_SUB_MIX[1][sx] = t << 16 | t >>> 16;
  24614. INV_SUB_MIX[2][sx] = t << 8 | t >>> 24;
  24615. INV_SUB_MIX[3][sx] = t;
  24616. if (x === 0) {
  24617. x = xi = 1;
  24618. } else {
  24619. x = x2 ^ d[d[d[x8 ^ x2]]];
  24620. xi ^= d[d[xi]];
  24621. }
  24622. }
  24623. return {
  24624. SBOX: SBOX,
  24625. INV_SBOX: INV_SBOX,
  24626. SUB_MIX: SUB_MIX,
  24627. INV_SUB_MIX: INV_SUB_MIX
  24628. };
  24629. }();
  24630. function AES(key) {
  24631. this._key = asUInt32Array(key);
  24632. this._reset();
  24633. }
  24634. AES.blockSize = 4 * 4;
  24635. AES.keySize = 256 / 8;
  24636. AES.prototype.blockSize = AES.blockSize;
  24637. AES.prototype.keySize = AES.keySize;
  24638. AES.prototype._reset = function () {
  24639. var keyWords = this._key;
  24640. var keySize = keyWords.length;
  24641. var nRounds = keySize + 6;
  24642. var ksRows = (nRounds + 1) * 4;
  24643. var keySchedule = [];
  24644. for (var k = 0; k < keySize; k++) {
  24645. keySchedule[k] = keyWords[k];
  24646. }
  24647. for (k = keySize; k < ksRows; k++) {
  24648. var t = keySchedule[k - 1];
  24649. if (k % keySize === 0) {
  24650. t = t << 8 | t >>> 24;
  24651. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  24652. t ^= RCON[k / keySize | 0] << 24;
  24653. } else if (keySize > 6 && k % keySize === 4) {
  24654. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  24655. }
  24656. keySchedule[k] = keySchedule[k - keySize] ^ t;
  24657. }
  24658. var invKeySchedule = [];
  24659. for (var ik = 0; ik < ksRows; ik++) {
  24660. var ksR = ksRows - ik;
  24661. var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)];
  24662. if (ik < 4 || ksR <= 4) {
  24663. invKeySchedule[ik] = tt;
  24664. } else {
  24665. invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 0xff]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 0xff]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 0xff]];
  24666. }
  24667. }
  24668. this._nRounds = nRounds;
  24669. this._keySchedule = keySchedule;
  24670. this._invKeySchedule = invKeySchedule;
  24671. };
  24672. AES.prototype.encryptBlockRaw = function (M) {
  24673. M = asUInt32Array(M);
  24674. return cryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX, this._nRounds);
  24675. };
  24676. AES.prototype.encryptBlock = function (M) {
  24677. var out = this.encryptBlockRaw(M);
  24678. var buf = Buffer.allocUnsafe(16);
  24679. buf.writeUInt32BE(out[0], 0);
  24680. buf.writeUInt32BE(out[1], 4);
  24681. buf.writeUInt32BE(out[2], 8);
  24682. buf.writeUInt32BE(out[3], 12);
  24683. return buf;
  24684. };
  24685. AES.prototype.decryptBlock = function (M) {
  24686. M = asUInt32Array(M);
  24687. // swap
  24688. var m1 = M[1];
  24689. M[1] = M[3];
  24690. M[3] = m1;
  24691. var out = cryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, this._nRounds);
  24692. var buf = Buffer.allocUnsafe(16);
  24693. buf.writeUInt32BE(out[0], 0);
  24694. buf.writeUInt32BE(out[3], 4);
  24695. buf.writeUInt32BE(out[2], 8);
  24696. buf.writeUInt32BE(out[1], 12);
  24697. return buf;
  24698. };
  24699. AES.prototype.scrub = function () {
  24700. scrubVec(this._keySchedule);
  24701. scrubVec(this._invKeySchedule);
  24702. scrubVec(this._key);
  24703. };
  24704. module.exports.AES = AES;
  24705. },{"safe-buffer":494}],190:[function(require,module,exports){
  24706. "use strict";
  24707. var aes = require('./aes');
  24708. var Buffer = require('safe-buffer').Buffer;
  24709. var Transform = require('cipher-base');
  24710. var inherits = require('inherits');
  24711. var GHASH = require('./ghash');
  24712. var xor = require('buffer-xor');
  24713. var incr32 = require('./incr32');
  24714. function xorTest(a, b) {
  24715. var out = 0;
  24716. if (a.length !== b.length) out++;
  24717. var len = Math.min(a.length, b.length);
  24718. for (var i = 0; i < len; ++i) {
  24719. out += a[i] ^ b[i];
  24720. }
  24721. return out;
  24722. }
  24723. function calcIv(self, iv, ck) {
  24724. if (iv.length === 12) {
  24725. self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]);
  24726. return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]);
  24727. }
  24728. var ghash = new GHASH(ck);
  24729. var len = iv.length;
  24730. var toPad = len % 16;
  24731. ghash.update(iv);
  24732. if (toPad) {
  24733. toPad = 16 - toPad;
  24734. ghash.update(Buffer.alloc(toPad, 0));
  24735. }
  24736. ghash.update(Buffer.alloc(8, 0));
  24737. var ivBits = len * 8;
  24738. var tail = Buffer.alloc(8);
  24739. tail.writeUIntBE(ivBits, 0, 8);
  24740. ghash.update(tail);
  24741. self._finID = ghash.state;
  24742. var out = Buffer.from(self._finID);
  24743. incr32(out);
  24744. return out;
  24745. }
  24746. function StreamCipher(mode, key, iv, decrypt) {
  24747. Transform.call(this);
  24748. var h = Buffer.alloc(4, 0);
  24749. this._cipher = new aes.AES(key);
  24750. var ck = this._cipher.encryptBlock(h);
  24751. this._ghash = new GHASH(ck);
  24752. iv = calcIv(this, iv, ck);
  24753. this._prev = Buffer.from(iv);
  24754. this._cache = Buffer.allocUnsafe(0);
  24755. this._secCache = Buffer.allocUnsafe(0);
  24756. this._decrypt = decrypt;
  24757. this._alen = 0;
  24758. this._len = 0;
  24759. this._mode = mode;
  24760. this._authTag = null;
  24761. this._called = false;
  24762. }
  24763. inherits(StreamCipher, Transform);
  24764. StreamCipher.prototype._update = function (chunk) {
  24765. if (!this._called && this._alen) {
  24766. var rump = 16 - this._alen % 16;
  24767. if (rump < 16) {
  24768. rump = Buffer.alloc(rump, 0);
  24769. this._ghash.update(rump);
  24770. }
  24771. }
  24772. this._called = true;
  24773. var out = this._mode.encrypt(this, chunk);
  24774. if (this._decrypt) {
  24775. this._ghash.update(chunk);
  24776. } else {
  24777. this._ghash.update(out);
  24778. }
  24779. this._len += chunk.length;
  24780. return out;
  24781. };
  24782. StreamCipher.prototype._final = function () {
  24783. if (this._decrypt && !this._authTag) throw new Error('Unsupported state or unable to authenticate data');
  24784. var tag = xor(this._ghash.final(this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID));
  24785. if (this._decrypt && xorTest(tag, this._authTag)) throw new Error('Unsupported state or unable to authenticate data');
  24786. this._authTag = tag;
  24787. this._cipher.scrub();
  24788. };
  24789. StreamCipher.prototype.getAuthTag = function getAuthTag() {
  24790. if (this._decrypt || !Buffer.isBuffer(this._authTag)) throw new Error('Attempting to get auth tag in unsupported state');
  24791. return this._authTag;
  24792. };
  24793. StreamCipher.prototype.setAuthTag = function setAuthTag(tag) {
  24794. if (!this._decrypt) throw new Error('Attempting to set auth tag in unsupported state');
  24795. this._authTag = tag;
  24796. };
  24797. StreamCipher.prototype.setAAD = function setAAD(buf) {
  24798. if (this._called) throw new Error('Attempting to set AAD in unsupported state');
  24799. this._ghash.update(buf);
  24800. this._alen += buf.length;
  24801. };
  24802. module.exports = StreamCipher;
  24803. },{"./aes":189,"./ghash":194,"./incr32":195,"buffer-xor":219,"cipher-base":221,"inherits":440,"safe-buffer":494}],191:[function(require,module,exports){
  24804. "use strict";
  24805. var ciphers = require('./encrypter');
  24806. var deciphers = require('./decrypter');
  24807. var modes = require('./modes/list.json');
  24808. function getCiphers() {
  24809. return Object.keys(modes);
  24810. }
  24811. exports.createCipher = exports.Cipher = ciphers.createCipher;
  24812. exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv;
  24813. exports.createDecipher = exports.Decipher = deciphers.createDecipher;
  24814. exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv;
  24815. exports.listCiphers = exports.getCiphers = getCiphers;
  24816. },{"./decrypter":192,"./encrypter":193,"./modes/list.json":203}],192:[function(require,module,exports){
  24817. "use strict";
  24818. var AuthCipher = require('./authCipher');
  24819. var Buffer = require('safe-buffer').Buffer;
  24820. var MODES = require('./modes');
  24821. var StreamCipher = require('./streamCipher');
  24822. var Transform = require('cipher-base');
  24823. var aes = require('./aes');
  24824. var ebtk = require('evp_bytestokey');
  24825. var inherits = require('inherits');
  24826. function Decipher(mode, key, iv) {
  24827. Transform.call(this);
  24828. this._cache = new Splitter();
  24829. this._last = void 0;
  24830. this._cipher = new aes.AES(key);
  24831. this._prev = Buffer.from(iv);
  24832. this._mode = mode;
  24833. this._autopadding = true;
  24834. }
  24835. inherits(Decipher, Transform);
  24836. Decipher.prototype._update = function (data) {
  24837. this._cache.add(data);
  24838. var chunk;
  24839. var thing;
  24840. var out = [];
  24841. while (chunk = this._cache.get(this._autopadding)) {
  24842. thing = this._mode.decrypt(this, chunk);
  24843. out.push(thing);
  24844. }
  24845. return Buffer.concat(out);
  24846. };
  24847. Decipher.prototype._final = function () {
  24848. var chunk = this._cache.flush();
  24849. if (this._autopadding) {
  24850. return unpad(this._mode.decrypt(this, chunk));
  24851. } else if (chunk) {
  24852. throw new Error('data not multiple of block length');
  24853. }
  24854. };
  24855. Decipher.prototype.setAutoPadding = function (setTo) {
  24856. this._autopadding = !!setTo;
  24857. return this;
  24858. };
  24859. function Splitter() {
  24860. this.cache = Buffer.allocUnsafe(0);
  24861. }
  24862. Splitter.prototype.add = function (data) {
  24863. this.cache = Buffer.concat([this.cache, data]);
  24864. };
  24865. Splitter.prototype.get = function (autoPadding) {
  24866. var out;
  24867. if (autoPadding) {
  24868. if (this.cache.length > 16) {
  24869. out = this.cache.slice(0, 16);
  24870. this.cache = this.cache.slice(16);
  24871. return out;
  24872. }
  24873. } else {
  24874. if (this.cache.length >= 16) {
  24875. out = this.cache.slice(0, 16);
  24876. this.cache = this.cache.slice(16);
  24877. return out;
  24878. }
  24879. }
  24880. return null;
  24881. };
  24882. Splitter.prototype.flush = function () {
  24883. if (this.cache.length) return this.cache;
  24884. };
  24885. function unpad(last) {
  24886. var padded = last[15];
  24887. if (padded < 1 || padded > 16) {
  24888. throw new Error('unable to decrypt data');
  24889. }
  24890. var i = -1;
  24891. while (++i < padded) {
  24892. if (last[i + (16 - padded)] !== padded) {
  24893. throw new Error('unable to decrypt data');
  24894. }
  24895. }
  24896. if (padded === 16) return;
  24897. return last.slice(0, 16 - padded);
  24898. }
  24899. function createDecipheriv(suite, password, iv) {
  24900. var config = MODES[suite.toLowerCase()];
  24901. if (!config) throw new TypeError('invalid suite type');
  24902. if (typeof iv === 'string') iv = Buffer.from(iv);
  24903. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  24904. if (typeof password === 'string') password = Buffer.from(password);
  24905. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  24906. if (config.type === 'stream') {
  24907. return new StreamCipher(config.module, password, iv, true);
  24908. } else if (config.type === 'auth') {
  24909. return new AuthCipher(config.module, password, iv, true);
  24910. }
  24911. return new Decipher(config.module, password, iv);
  24912. }
  24913. function createDecipher(suite, password) {
  24914. var config = MODES[suite.toLowerCase()];
  24915. if (!config) throw new TypeError('invalid suite type');
  24916. var keys = ebtk(password, false, config.key, config.iv);
  24917. return createDecipheriv(suite, keys.key, keys.iv);
  24918. }
  24919. exports.createDecipher = createDecipher;
  24920. exports.createDecipheriv = createDecipheriv;
  24921. },{"./aes":189,"./authCipher":190,"./modes":202,"./streamCipher":205,"cipher-base":221,"evp_bytestokey":423,"inherits":440,"safe-buffer":494}],193:[function(require,module,exports){
  24922. "use strict";
  24923. var MODES = require('./modes');
  24924. var AuthCipher = require('./authCipher');
  24925. var Buffer = require('safe-buffer').Buffer;
  24926. var StreamCipher = require('./streamCipher');
  24927. var Transform = require('cipher-base');
  24928. var aes = require('./aes');
  24929. var ebtk = require('evp_bytestokey');
  24930. var inherits = require('inherits');
  24931. function Cipher(mode, key, iv) {
  24932. Transform.call(this);
  24933. this._cache = new Splitter();
  24934. this._cipher = new aes.AES(key);
  24935. this._prev = Buffer.from(iv);
  24936. this._mode = mode;
  24937. this._autopadding = true;
  24938. }
  24939. inherits(Cipher, Transform);
  24940. Cipher.prototype._update = function (data) {
  24941. this._cache.add(data);
  24942. var chunk;
  24943. var thing;
  24944. var out = [];
  24945. while (chunk = this._cache.get()) {
  24946. thing = this._mode.encrypt(this, chunk);
  24947. out.push(thing);
  24948. }
  24949. return Buffer.concat(out);
  24950. };
  24951. var PADDING = Buffer.alloc(16, 0x10);
  24952. Cipher.prototype._final = function () {
  24953. var chunk = this._cache.flush();
  24954. if (this._autopadding) {
  24955. chunk = this._mode.encrypt(this, chunk);
  24956. this._cipher.scrub();
  24957. return chunk;
  24958. }
  24959. if (!chunk.equals(PADDING)) {
  24960. this._cipher.scrub();
  24961. throw new Error('data not multiple of block length');
  24962. }
  24963. };
  24964. Cipher.prototype.setAutoPadding = function (setTo) {
  24965. this._autopadding = !!setTo;
  24966. return this;
  24967. };
  24968. function Splitter() {
  24969. this.cache = Buffer.allocUnsafe(0);
  24970. }
  24971. Splitter.prototype.add = function (data) {
  24972. this.cache = Buffer.concat([this.cache, data]);
  24973. };
  24974. Splitter.prototype.get = function () {
  24975. if (this.cache.length > 15) {
  24976. var out = this.cache.slice(0, 16);
  24977. this.cache = this.cache.slice(16);
  24978. return out;
  24979. }
  24980. return null;
  24981. };
  24982. Splitter.prototype.flush = function () {
  24983. var len = 16 - this.cache.length;
  24984. var padBuff = Buffer.allocUnsafe(len);
  24985. var i = -1;
  24986. while (++i < len) {
  24987. padBuff.writeUInt8(len, i);
  24988. }
  24989. return Buffer.concat([this.cache, padBuff]);
  24990. };
  24991. function createCipheriv(suite, password, iv) {
  24992. var config = MODES[suite.toLowerCase()];
  24993. if (!config) throw new TypeError('invalid suite type');
  24994. if (typeof password === 'string') password = Buffer.from(password);
  24995. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  24996. if (typeof iv === 'string') iv = Buffer.from(iv);
  24997. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  24998. if (config.type === 'stream') {
  24999. return new StreamCipher(config.module, password, iv);
  25000. } else if (config.type === 'auth') {
  25001. return new AuthCipher(config.module, password, iv);
  25002. }
  25003. return new Cipher(config.module, password, iv);
  25004. }
  25005. function createCipher(suite, password) {
  25006. var config = MODES[suite.toLowerCase()];
  25007. if (!config) throw new TypeError('invalid suite type');
  25008. var keys = ebtk(password, false, config.key, config.iv);
  25009. return createCipheriv(suite, keys.key, keys.iv);
  25010. }
  25011. exports.createCipheriv = createCipheriv;
  25012. exports.createCipher = createCipher;
  25013. },{"./aes":189,"./authCipher":190,"./modes":202,"./streamCipher":205,"cipher-base":221,"evp_bytestokey":423,"inherits":440,"safe-buffer":494}],194:[function(require,module,exports){
  25014. "use strict";
  25015. var Buffer = require('safe-buffer').Buffer;
  25016. var ZEROES = Buffer.alloc(16, 0);
  25017. function toArray(buf) {
  25018. return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)];
  25019. }
  25020. function fromArray(out) {
  25021. var buf = Buffer.allocUnsafe(16);
  25022. buf.writeUInt32BE(out[0] >>> 0, 0);
  25023. buf.writeUInt32BE(out[1] >>> 0, 4);
  25024. buf.writeUInt32BE(out[2] >>> 0, 8);
  25025. buf.writeUInt32BE(out[3] >>> 0, 12);
  25026. return buf;
  25027. }
  25028. function GHASH(key) {
  25029. this.h = key;
  25030. this.state = Buffer.alloc(16, 0);
  25031. this.cache = Buffer.allocUnsafe(0);
  25032. }
  25033. // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
  25034. // by Juho Vähä-Herttua
  25035. GHASH.prototype.ghash = function (block) {
  25036. var i = -1;
  25037. while (++i < block.length) {
  25038. this.state[i] ^= block[i];
  25039. }
  25040. this._multiply();
  25041. };
  25042. GHASH.prototype._multiply = function () {
  25043. var Vi = toArray(this.h);
  25044. var Zi = [0, 0, 0, 0];
  25045. var j, xi, lsbVi;
  25046. var i = -1;
  25047. while (++i < 128) {
  25048. xi = (this.state[~~(i / 8)] & 1 << 7 - i % 8) !== 0;
  25049. if (xi) {
  25050. // Z_i+1 = Z_i ^ V_i
  25051. Zi[0] ^= Vi[0];
  25052. Zi[1] ^= Vi[1];
  25053. Zi[2] ^= Vi[2];
  25054. Zi[3] ^= Vi[3];
  25055. }
  25056. // Store the value of LSB(V_i)
  25057. lsbVi = (Vi[3] & 1) !== 0;
  25058. // V_i+1 = V_i >> 1
  25059. for (j = 3; j > 0; j--) {
  25060. Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31;
  25061. }
  25062. Vi[0] = Vi[0] >>> 1;
  25063. // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
  25064. if (lsbVi) {
  25065. Vi[0] = Vi[0] ^ 0xe1 << 24;
  25066. }
  25067. }
  25068. this.state = fromArray(Zi);
  25069. };
  25070. GHASH.prototype.update = function (buf) {
  25071. this.cache = Buffer.concat([this.cache, buf]);
  25072. var chunk;
  25073. while (this.cache.length >= 16) {
  25074. chunk = this.cache.slice(0, 16);
  25075. this.cache = this.cache.slice(16);
  25076. this.ghash(chunk);
  25077. }
  25078. };
  25079. GHASH.prototype.final = function (abl, bl) {
  25080. if (this.cache.length) {
  25081. this.ghash(Buffer.concat([this.cache, ZEROES], 16));
  25082. }
  25083. this.ghash(fromArray([0, abl, 0, bl]));
  25084. return this.state;
  25085. };
  25086. module.exports = GHASH;
  25087. },{"safe-buffer":494}],195:[function(require,module,exports){
  25088. "use strict";
  25089. function incr32(iv) {
  25090. var len = iv.length;
  25091. var item;
  25092. while (len--) {
  25093. item = iv.readUInt8(len);
  25094. if (item === 255) {
  25095. iv.writeUInt8(0, len);
  25096. } else {
  25097. item++;
  25098. iv.writeUInt8(item, len);
  25099. break;
  25100. }
  25101. }
  25102. }
  25103. module.exports = incr32;
  25104. },{}],196:[function(require,module,exports){
  25105. "use strict";
  25106. var xor = require('buffer-xor');
  25107. exports.encrypt = function (self, block) {
  25108. var data = xor(block, self._prev);
  25109. self._prev = self._cipher.encryptBlock(data);
  25110. return self._prev;
  25111. };
  25112. exports.decrypt = function (self, block) {
  25113. var pad = self._prev;
  25114. self._prev = block;
  25115. var out = self._cipher.decryptBlock(block);
  25116. return xor(out, pad);
  25117. };
  25118. },{"buffer-xor":219}],197:[function(require,module,exports){
  25119. "use strict";
  25120. var Buffer = require('safe-buffer').Buffer;
  25121. var xor = require('buffer-xor');
  25122. function encryptStart(self, data, decrypt) {
  25123. var len = data.length;
  25124. var out = xor(data, self._cache);
  25125. self._cache = self._cache.slice(len);
  25126. self._prev = Buffer.concat([self._prev, decrypt ? data : out]);
  25127. return out;
  25128. }
  25129. exports.encrypt = function (self, data, decrypt) {
  25130. var out = Buffer.allocUnsafe(0);
  25131. var len;
  25132. while (data.length) {
  25133. if (self._cache.length === 0) {
  25134. self._cache = self._cipher.encryptBlock(self._prev);
  25135. self._prev = Buffer.allocUnsafe(0);
  25136. }
  25137. if (self._cache.length <= data.length) {
  25138. len = self._cache.length;
  25139. out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]);
  25140. data = data.slice(len);
  25141. } else {
  25142. out = Buffer.concat([out, encryptStart(self, data, decrypt)]);
  25143. break;
  25144. }
  25145. }
  25146. return out;
  25147. };
  25148. },{"buffer-xor":219,"safe-buffer":494}],198:[function(require,module,exports){
  25149. "use strict";
  25150. var Buffer = require('safe-buffer').Buffer;
  25151. function encryptByte(self, byteParam, decrypt) {
  25152. var pad;
  25153. var i = -1;
  25154. var len = 8;
  25155. var out = 0;
  25156. var bit, value;
  25157. while (++i < len) {
  25158. pad = self._cipher.encryptBlock(self._prev);
  25159. bit = byteParam & 1 << 7 - i ? 0x80 : 0;
  25160. value = pad[0] ^ bit;
  25161. out += (value & 0x80) >> i % 8;
  25162. self._prev = shiftIn(self._prev, decrypt ? bit : value);
  25163. }
  25164. return out;
  25165. }
  25166. function shiftIn(buffer, value) {
  25167. var len = buffer.length;
  25168. var i = -1;
  25169. var out = Buffer.allocUnsafe(buffer.length);
  25170. buffer = Buffer.concat([buffer, Buffer.from([value])]);
  25171. while (++i < len) {
  25172. out[i] = buffer[i] << 1 | buffer[i + 1] >> 7;
  25173. }
  25174. return out;
  25175. }
  25176. exports.encrypt = function (self, chunk, decrypt) {
  25177. var len = chunk.length;
  25178. var out = Buffer.allocUnsafe(len);
  25179. var i = -1;
  25180. while (++i < len) {
  25181. out[i] = encryptByte(self, chunk[i], decrypt);
  25182. }
  25183. return out;
  25184. };
  25185. },{"safe-buffer":494}],199:[function(require,module,exports){
  25186. "use strict";
  25187. var Buffer = require('safe-buffer').Buffer;
  25188. function encryptByte(self, byteParam, decrypt) {
  25189. var pad = self._cipher.encryptBlock(self._prev);
  25190. var out = pad[0] ^ byteParam;
  25191. self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]);
  25192. return out;
  25193. }
  25194. exports.encrypt = function (self, chunk, decrypt) {
  25195. var len = chunk.length;
  25196. var out = Buffer.allocUnsafe(len);
  25197. var i = -1;
  25198. while (++i < len) {
  25199. out[i] = encryptByte(self, chunk[i], decrypt);
  25200. }
  25201. return out;
  25202. };
  25203. },{"safe-buffer":494}],200:[function(require,module,exports){
  25204. "use strict";
  25205. var xor = require('buffer-xor');
  25206. var Buffer = require('safe-buffer').Buffer;
  25207. var incr32 = require('../incr32');
  25208. function getBlock(self) {
  25209. var out = self._cipher.encryptBlockRaw(self._prev);
  25210. incr32(self._prev);
  25211. return out;
  25212. }
  25213. var blockSize = 16;
  25214. exports.encrypt = function (self, chunk) {
  25215. var chunkNum = Math.ceil(chunk.length / blockSize);
  25216. var start = self._cache.length;
  25217. self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]);
  25218. for (var i = 0; i < chunkNum; i++) {
  25219. var out = getBlock(self);
  25220. var offset = start + i * blockSize;
  25221. self._cache.writeUInt32BE(out[0], offset + 0);
  25222. self._cache.writeUInt32BE(out[1], offset + 4);
  25223. self._cache.writeUInt32BE(out[2], offset + 8);
  25224. self._cache.writeUInt32BE(out[3], offset + 12);
  25225. }
  25226. var pad = self._cache.slice(0, chunk.length);
  25227. self._cache = self._cache.slice(chunk.length);
  25228. return xor(chunk, pad);
  25229. };
  25230. },{"../incr32":195,"buffer-xor":219,"safe-buffer":494}],201:[function(require,module,exports){
  25231. "use strict";
  25232. exports.encrypt = function (self, block) {
  25233. return self._cipher.encryptBlock(block);
  25234. };
  25235. exports.decrypt = function (self, block) {
  25236. return self._cipher.decryptBlock(block);
  25237. };
  25238. },{}],202:[function(require,module,exports){
  25239. "use strict";
  25240. var modeModules = {
  25241. ECB: require('./ecb'),
  25242. CBC: require('./cbc'),
  25243. CFB: require('./cfb'),
  25244. CFB8: require('./cfb8'),
  25245. CFB1: require('./cfb1'),
  25246. OFB: require('./ofb'),
  25247. CTR: require('./ctr'),
  25248. GCM: require('./ctr')
  25249. };
  25250. var modes = require('./list.json');
  25251. for (var key in modes) {
  25252. modes[key].module = modeModules[modes[key].mode];
  25253. }
  25254. module.exports = modes;
  25255. },{"./cbc":196,"./cfb":197,"./cfb1":198,"./cfb8":199,"./ctr":200,"./ecb":201,"./list.json":203,"./ofb":204}],203:[function(require,module,exports){
  25256. module.exports={
  25257. "aes-128-ecb": {
  25258. "cipher": "AES",
  25259. "key": 128,
  25260. "iv": 0,
  25261. "mode": "ECB",
  25262. "type": "block"
  25263. },
  25264. "aes-192-ecb": {
  25265. "cipher": "AES",
  25266. "key": 192,
  25267. "iv": 0,
  25268. "mode": "ECB",
  25269. "type": "block"
  25270. },
  25271. "aes-256-ecb": {
  25272. "cipher": "AES",
  25273. "key": 256,
  25274. "iv": 0,
  25275. "mode": "ECB",
  25276. "type": "block"
  25277. },
  25278. "aes-128-cbc": {
  25279. "cipher": "AES",
  25280. "key": 128,
  25281. "iv": 16,
  25282. "mode": "CBC",
  25283. "type": "block"
  25284. },
  25285. "aes-192-cbc": {
  25286. "cipher": "AES",
  25287. "key": 192,
  25288. "iv": 16,
  25289. "mode": "CBC",
  25290. "type": "block"
  25291. },
  25292. "aes-256-cbc": {
  25293. "cipher": "AES",
  25294. "key": 256,
  25295. "iv": 16,
  25296. "mode": "CBC",
  25297. "type": "block"
  25298. },
  25299. "aes128": {
  25300. "cipher": "AES",
  25301. "key": 128,
  25302. "iv": 16,
  25303. "mode": "CBC",
  25304. "type": "block"
  25305. },
  25306. "aes192": {
  25307. "cipher": "AES",
  25308. "key": 192,
  25309. "iv": 16,
  25310. "mode": "CBC",
  25311. "type": "block"
  25312. },
  25313. "aes256": {
  25314. "cipher": "AES",
  25315. "key": 256,
  25316. "iv": 16,
  25317. "mode": "CBC",
  25318. "type": "block"
  25319. },
  25320. "aes-128-cfb": {
  25321. "cipher": "AES",
  25322. "key": 128,
  25323. "iv": 16,
  25324. "mode": "CFB",
  25325. "type": "stream"
  25326. },
  25327. "aes-192-cfb": {
  25328. "cipher": "AES",
  25329. "key": 192,
  25330. "iv": 16,
  25331. "mode": "CFB",
  25332. "type": "stream"
  25333. },
  25334. "aes-256-cfb": {
  25335. "cipher": "AES",
  25336. "key": 256,
  25337. "iv": 16,
  25338. "mode": "CFB",
  25339. "type": "stream"
  25340. },
  25341. "aes-128-cfb8": {
  25342. "cipher": "AES",
  25343. "key": 128,
  25344. "iv": 16,
  25345. "mode": "CFB8",
  25346. "type": "stream"
  25347. },
  25348. "aes-192-cfb8": {
  25349. "cipher": "AES",
  25350. "key": 192,
  25351. "iv": 16,
  25352. "mode": "CFB8",
  25353. "type": "stream"
  25354. },
  25355. "aes-256-cfb8": {
  25356. "cipher": "AES",
  25357. "key": 256,
  25358. "iv": 16,
  25359. "mode": "CFB8",
  25360. "type": "stream"
  25361. },
  25362. "aes-128-cfb1": {
  25363. "cipher": "AES",
  25364. "key": 128,
  25365. "iv": 16,
  25366. "mode": "CFB1",
  25367. "type": "stream"
  25368. },
  25369. "aes-192-cfb1": {
  25370. "cipher": "AES",
  25371. "key": 192,
  25372. "iv": 16,
  25373. "mode": "CFB1",
  25374. "type": "stream"
  25375. },
  25376. "aes-256-cfb1": {
  25377. "cipher": "AES",
  25378. "key": 256,
  25379. "iv": 16,
  25380. "mode": "CFB1",
  25381. "type": "stream"
  25382. },
  25383. "aes-128-ofb": {
  25384. "cipher": "AES",
  25385. "key": 128,
  25386. "iv": 16,
  25387. "mode": "OFB",
  25388. "type": "stream"
  25389. },
  25390. "aes-192-ofb": {
  25391. "cipher": "AES",
  25392. "key": 192,
  25393. "iv": 16,
  25394. "mode": "OFB",
  25395. "type": "stream"
  25396. },
  25397. "aes-256-ofb": {
  25398. "cipher": "AES",
  25399. "key": 256,
  25400. "iv": 16,
  25401. "mode": "OFB",
  25402. "type": "stream"
  25403. },
  25404. "aes-128-ctr": {
  25405. "cipher": "AES",
  25406. "key": 128,
  25407. "iv": 16,
  25408. "mode": "CTR",
  25409. "type": "stream"
  25410. },
  25411. "aes-192-ctr": {
  25412. "cipher": "AES",
  25413. "key": 192,
  25414. "iv": 16,
  25415. "mode": "CTR",
  25416. "type": "stream"
  25417. },
  25418. "aes-256-ctr": {
  25419. "cipher": "AES",
  25420. "key": 256,
  25421. "iv": 16,
  25422. "mode": "CTR",
  25423. "type": "stream"
  25424. },
  25425. "aes-128-gcm": {
  25426. "cipher": "AES",
  25427. "key": 128,
  25428. "iv": 12,
  25429. "mode": "GCM",
  25430. "type": "auth"
  25431. },
  25432. "aes-192-gcm": {
  25433. "cipher": "AES",
  25434. "key": 192,
  25435. "iv": 12,
  25436. "mode": "GCM",
  25437. "type": "auth"
  25438. },
  25439. "aes-256-gcm": {
  25440. "cipher": "AES",
  25441. "key": 256,
  25442. "iv": 12,
  25443. "mode": "GCM",
  25444. "type": "auth"
  25445. }
  25446. }
  25447. },{}],204:[function(require,module,exports){
  25448. (function (Buffer){(function (){
  25449. "use strict";
  25450. var xor = require('buffer-xor');
  25451. function getBlock(self) {
  25452. self._prev = self._cipher.encryptBlock(self._prev);
  25453. return self._prev;
  25454. }
  25455. exports.encrypt = function (self, chunk) {
  25456. while (self._cache.length < chunk.length) {
  25457. self._cache = Buffer.concat([self._cache, getBlock(self)]);
  25458. }
  25459. var pad = self._cache.slice(0, chunk.length);
  25460. self._cache = self._cache.slice(chunk.length);
  25461. return xor(chunk, pad);
  25462. };
  25463. }).call(this)}).call(this,require("buffer").Buffer)
  25464. },{"buffer":220,"buffer-xor":219}],205:[function(require,module,exports){
  25465. "use strict";
  25466. var aes = require('./aes');
  25467. var Buffer = require('safe-buffer').Buffer;
  25468. var Transform = require('cipher-base');
  25469. var inherits = require('inherits');
  25470. function StreamCipher(mode, key, iv, decrypt) {
  25471. Transform.call(this);
  25472. this._cipher = new aes.AES(key);
  25473. this._prev = Buffer.from(iv);
  25474. this._cache = Buffer.allocUnsafe(0);
  25475. this._secCache = Buffer.allocUnsafe(0);
  25476. this._decrypt = decrypt;
  25477. this._mode = mode;
  25478. }
  25479. inherits(StreamCipher, Transform);
  25480. StreamCipher.prototype._update = function (chunk) {
  25481. return this._mode.encrypt(this, chunk, this._decrypt);
  25482. };
  25483. StreamCipher.prototype._final = function () {
  25484. this._cipher.scrub();
  25485. };
  25486. module.exports = StreamCipher;
  25487. },{"./aes":189,"cipher-base":221,"inherits":440,"safe-buffer":494}],206:[function(require,module,exports){
  25488. "use strict";
  25489. var DES = require('browserify-des');
  25490. var aes = require('browserify-aes/browser');
  25491. var aesModes = require('browserify-aes/modes');
  25492. var desModes = require('browserify-des/modes');
  25493. var ebtk = require('evp_bytestokey');
  25494. function createCipher(suite, password) {
  25495. suite = suite.toLowerCase();
  25496. var keyLen, ivLen;
  25497. if (aesModes[suite]) {
  25498. keyLen = aesModes[suite].key;
  25499. ivLen = aesModes[suite].iv;
  25500. } else if (desModes[suite]) {
  25501. keyLen = desModes[suite].key * 8;
  25502. ivLen = desModes[suite].iv;
  25503. } else {
  25504. throw new TypeError('invalid suite type');
  25505. }
  25506. var keys = ebtk(password, false, keyLen, ivLen);
  25507. return createCipheriv(suite, keys.key, keys.iv);
  25508. }
  25509. function createDecipher(suite, password) {
  25510. suite = suite.toLowerCase();
  25511. var keyLen, ivLen;
  25512. if (aesModes[suite]) {
  25513. keyLen = aesModes[suite].key;
  25514. ivLen = aesModes[suite].iv;
  25515. } else if (desModes[suite]) {
  25516. keyLen = desModes[suite].key * 8;
  25517. ivLen = desModes[suite].iv;
  25518. } else {
  25519. throw new TypeError('invalid suite type');
  25520. }
  25521. var keys = ebtk(password, false, keyLen, ivLen);
  25522. return createDecipheriv(suite, keys.key, keys.iv);
  25523. }
  25524. function createCipheriv(suite, key, iv) {
  25525. suite = suite.toLowerCase();
  25526. if (aesModes[suite]) return aes.createCipheriv(suite, key, iv);
  25527. if (desModes[suite]) return new DES({
  25528. key: key,
  25529. iv: iv,
  25530. mode: suite
  25531. });
  25532. throw new TypeError('invalid suite type');
  25533. }
  25534. function createDecipheriv(suite, key, iv) {
  25535. suite = suite.toLowerCase();
  25536. if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv);
  25537. if (desModes[suite]) return new DES({
  25538. key: key,
  25539. iv: iv,
  25540. mode: suite,
  25541. decrypt: true
  25542. });
  25543. throw new TypeError('invalid suite type');
  25544. }
  25545. function getCiphers() {
  25546. return Object.keys(desModes).concat(aes.getCiphers());
  25547. }
  25548. exports.createCipher = exports.Cipher = createCipher;
  25549. exports.createCipheriv = exports.Cipheriv = createCipheriv;
  25550. exports.createDecipher = exports.Decipher = createDecipher;
  25551. exports.createDecipheriv = exports.Decipheriv = createDecipheriv;
  25552. exports.listCiphers = exports.getCiphers = getCiphers;
  25553. },{"browserify-aes/browser":191,"browserify-aes/modes":202,"browserify-des":207,"browserify-des/modes":208,"evp_bytestokey":423}],207:[function(require,module,exports){
  25554. "use strict";
  25555. var CipherBase = require('cipher-base');
  25556. var des = require('des.js');
  25557. var inherits = require('inherits');
  25558. var Buffer = require('safe-buffer').Buffer;
  25559. var modes = {
  25560. 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  25561. 'des-ede3': des.EDE,
  25562. 'des-ede-cbc': des.CBC.instantiate(des.EDE),
  25563. 'des-ede': des.EDE,
  25564. 'des-cbc': des.CBC.instantiate(des.DES),
  25565. 'des-ecb': des.DES
  25566. };
  25567. modes.des = modes['des-cbc'];
  25568. modes.des3 = modes['des-ede3-cbc'];
  25569. module.exports = DES;
  25570. inherits(DES, CipherBase);
  25571. function DES(opts) {
  25572. CipherBase.call(this);
  25573. var modeName = opts.mode.toLowerCase();
  25574. var mode = modes[modeName];
  25575. var type;
  25576. if (opts.decrypt) {
  25577. type = 'decrypt';
  25578. } else {
  25579. type = 'encrypt';
  25580. }
  25581. var key = opts.key;
  25582. if (!Buffer.isBuffer(key)) {
  25583. key = Buffer.from(key);
  25584. }
  25585. if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
  25586. key = Buffer.concat([key, key.slice(0, 8)]);
  25587. }
  25588. var iv = opts.iv;
  25589. if (!Buffer.isBuffer(iv)) {
  25590. iv = Buffer.from(iv);
  25591. }
  25592. this._des = mode.create({
  25593. key: key,
  25594. iv: iv,
  25595. type: type
  25596. });
  25597. }
  25598. DES.prototype._update = function (data) {
  25599. return Buffer.from(this._des.update(data));
  25600. };
  25601. DES.prototype._final = function () {
  25602. return Buffer.from(this._des.final());
  25603. };
  25604. },{"cipher-base":221,"des.js":394,"inherits":440,"safe-buffer":494}],208:[function(require,module,exports){
  25605. "use strict";
  25606. exports['des-ecb'] = {
  25607. key: 8,
  25608. iv: 0
  25609. };
  25610. exports['des-cbc'] = exports.des = {
  25611. key: 8,
  25612. iv: 8
  25613. };
  25614. exports['des-ede3-cbc'] = exports.des3 = {
  25615. key: 24,
  25616. iv: 8
  25617. };
  25618. exports['des-ede3'] = {
  25619. key: 24,
  25620. iv: 0
  25621. };
  25622. exports['des-ede-cbc'] = {
  25623. key: 16,
  25624. iv: 8
  25625. };
  25626. exports['des-ede'] = {
  25627. key: 16,
  25628. iv: 0
  25629. };
  25630. },{}],209:[function(require,module,exports){
  25631. (function (Buffer){(function (){
  25632. "use strict";
  25633. var BN = require('bn.js');
  25634. var randomBytes = require('randombytes');
  25635. function blind(priv) {
  25636. var r = getr(priv);
  25637. var blinder = r.toRed(BN.mont(priv.modulus)).redPow(new BN(priv.publicExponent)).fromRed();
  25638. return {
  25639. blinder: blinder,
  25640. unblinder: r.invm(priv.modulus)
  25641. };
  25642. }
  25643. function getr(priv) {
  25644. var len = priv.modulus.byteLength();
  25645. var r;
  25646. do {
  25647. r = new BN(randomBytes(len));
  25648. } while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2));
  25649. return r;
  25650. }
  25651. function crt(msg, priv) {
  25652. var blinds = blind(priv);
  25653. var len = priv.modulus.byteLength();
  25654. var blinded = new BN(msg).mul(blinds.blinder).umod(priv.modulus);
  25655. var c1 = blinded.toRed(BN.mont(priv.prime1));
  25656. var c2 = blinded.toRed(BN.mont(priv.prime2));
  25657. var qinv = priv.coefficient;
  25658. var p = priv.prime1;
  25659. var q = priv.prime2;
  25660. var m1 = c1.redPow(priv.exponent1).fromRed();
  25661. var m2 = c2.redPow(priv.exponent2).fromRed();
  25662. var h = m1.isub(m2).imul(qinv).umod(p).imul(q);
  25663. return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer, 'be', len);
  25664. }
  25665. crt.getr = getr;
  25666. module.exports = crt;
  25667. }).call(this)}).call(this,require("buffer").Buffer)
  25668. },{"bn.js":186,"buffer":220,"randombytes":475}],210:[function(require,module,exports){
  25669. "use strict";
  25670. module.exports = require('./browser/algorithms.json');
  25671. },{"./browser/algorithms.json":211}],211:[function(require,module,exports){
  25672. module.exports={
  25673. "sha224WithRSAEncryption": {
  25674. "sign": "rsa",
  25675. "hash": "sha224",
  25676. "id": "302d300d06096086480165030402040500041c"
  25677. },
  25678. "RSA-SHA224": {
  25679. "sign": "ecdsa/rsa",
  25680. "hash": "sha224",
  25681. "id": "302d300d06096086480165030402040500041c"
  25682. },
  25683. "sha256WithRSAEncryption": {
  25684. "sign": "rsa",
  25685. "hash": "sha256",
  25686. "id": "3031300d060960864801650304020105000420"
  25687. },
  25688. "RSA-SHA256": {
  25689. "sign": "ecdsa/rsa",
  25690. "hash": "sha256",
  25691. "id": "3031300d060960864801650304020105000420"
  25692. },
  25693. "sha384WithRSAEncryption": {
  25694. "sign": "rsa",
  25695. "hash": "sha384",
  25696. "id": "3041300d060960864801650304020205000430"
  25697. },
  25698. "RSA-SHA384": {
  25699. "sign": "ecdsa/rsa",
  25700. "hash": "sha384",
  25701. "id": "3041300d060960864801650304020205000430"
  25702. },
  25703. "sha512WithRSAEncryption": {
  25704. "sign": "rsa",
  25705. "hash": "sha512",
  25706. "id": "3051300d060960864801650304020305000440"
  25707. },
  25708. "RSA-SHA512": {
  25709. "sign": "ecdsa/rsa",
  25710. "hash": "sha512",
  25711. "id": "3051300d060960864801650304020305000440"
  25712. },
  25713. "RSA-SHA1": {
  25714. "sign": "rsa",
  25715. "hash": "sha1",
  25716. "id": "3021300906052b0e03021a05000414"
  25717. },
  25718. "ecdsa-with-SHA1": {
  25719. "sign": "ecdsa",
  25720. "hash": "sha1",
  25721. "id": ""
  25722. },
  25723. "sha256": {
  25724. "sign": "ecdsa",
  25725. "hash": "sha256",
  25726. "id": ""
  25727. },
  25728. "sha224": {
  25729. "sign": "ecdsa",
  25730. "hash": "sha224",
  25731. "id": ""
  25732. },
  25733. "sha384": {
  25734. "sign": "ecdsa",
  25735. "hash": "sha384",
  25736. "id": ""
  25737. },
  25738. "sha512": {
  25739. "sign": "ecdsa",
  25740. "hash": "sha512",
  25741. "id": ""
  25742. },
  25743. "DSA-SHA": {
  25744. "sign": "dsa",
  25745. "hash": "sha1",
  25746. "id": ""
  25747. },
  25748. "DSA-SHA1": {
  25749. "sign": "dsa",
  25750. "hash": "sha1",
  25751. "id": ""
  25752. },
  25753. "DSA": {
  25754. "sign": "dsa",
  25755. "hash": "sha1",
  25756. "id": ""
  25757. },
  25758. "DSA-WITH-SHA224": {
  25759. "sign": "dsa",
  25760. "hash": "sha224",
  25761. "id": ""
  25762. },
  25763. "DSA-SHA224": {
  25764. "sign": "dsa",
  25765. "hash": "sha224",
  25766. "id": ""
  25767. },
  25768. "DSA-WITH-SHA256": {
  25769. "sign": "dsa",
  25770. "hash": "sha256",
  25771. "id": ""
  25772. },
  25773. "DSA-SHA256": {
  25774. "sign": "dsa",
  25775. "hash": "sha256",
  25776. "id": ""
  25777. },
  25778. "DSA-WITH-SHA384": {
  25779. "sign": "dsa",
  25780. "hash": "sha384",
  25781. "id": ""
  25782. },
  25783. "DSA-SHA384": {
  25784. "sign": "dsa",
  25785. "hash": "sha384",
  25786. "id": ""
  25787. },
  25788. "DSA-WITH-SHA512": {
  25789. "sign": "dsa",
  25790. "hash": "sha512",
  25791. "id": ""
  25792. },
  25793. "DSA-SHA512": {
  25794. "sign": "dsa",
  25795. "hash": "sha512",
  25796. "id": ""
  25797. },
  25798. "DSA-RIPEMD160": {
  25799. "sign": "dsa",
  25800. "hash": "rmd160",
  25801. "id": ""
  25802. },
  25803. "ripemd160WithRSA": {
  25804. "sign": "rsa",
  25805. "hash": "rmd160",
  25806. "id": "3021300906052b2403020105000414"
  25807. },
  25808. "RSA-RIPEMD160": {
  25809. "sign": "rsa",
  25810. "hash": "rmd160",
  25811. "id": "3021300906052b2403020105000414"
  25812. },
  25813. "md5WithRSAEncryption": {
  25814. "sign": "rsa",
  25815. "hash": "md5",
  25816. "id": "3020300c06082a864886f70d020505000410"
  25817. },
  25818. "RSA-MD5": {
  25819. "sign": "rsa",
  25820. "hash": "md5",
  25821. "id": "3020300c06082a864886f70d020505000410"
  25822. }
  25823. }
  25824. },{}],212:[function(require,module,exports){
  25825. module.exports={
  25826. "1.3.132.0.10": "secp256k1",
  25827. "1.3.132.0.33": "p224",
  25828. "1.2.840.10045.3.1.1": "p192",
  25829. "1.2.840.10045.3.1.7": "p256",
  25830. "1.3.132.0.34": "p384",
  25831. "1.3.132.0.35": "p521"
  25832. }
  25833. },{}],213:[function(require,module,exports){
  25834. "use strict";
  25835. var Buffer = require('safe-buffer').Buffer;
  25836. var createHash = require('create-hash');
  25837. var stream = require('readable-stream');
  25838. var inherits = require('inherits');
  25839. var sign = require('./sign');
  25840. var verify = require('./verify');
  25841. var algorithms = require('./algorithms.json');
  25842. Object.keys(algorithms).forEach(function (key) {
  25843. algorithms[key].id = Buffer.from(algorithms[key].id, 'hex');
  25844. algorithms[key.toLowerCase()] = algorithms[key];
  25845. });
  25846. function Sign(algorithm) {
  25847. stream.Writable.call(this);
  25848. var data = algorithms[algorithm];
  25849. if (!data) throw new Error('Unknown message digest');
  25850. this._hashType = data.hash;
  25851. this._hash = createHash(data.hash);
  25852. this._tag = data.id;
  25853. this._signType = data.sign;
  25854. }
  25855. inherits(Sign, stream.Writable);
  25856. Sign.prototype._write = function _write(data, _, done) {
  25857. this._hash.update(data);
  25858. done();
  25859. };
  25860. Sign.prototype.update = function update(data, enc) {
  25861. if (typeof data === 'string') data = Buffer.from(data, enc);
  25862. this._hash.update(data);
  25863. return this;
  25864. };
  25865. Sign.prototype.sign = function signMethod(key, enc) {
  25866. this.end();
  25867. var hash = this._hash.digest();
  25868. var sig = sign(hash, key, this._hashType, this._signType, this._tag);
  25869. return enc ? sig.toString(enc) : sig;
  25870. };
  25871. function Verify(algorithm) {
  25872. stream.Writable.call(this);
  25873. var data = algorithms[algorithm];
  25874. if (!data) throw new Error('Unknown message digest');
  25875. this._hash = createHash(data.hash);
  25876. this._tag = data.id;
  25877. this._signType = data.sign;
  25878. }
  25879. inherits(Verify, stream.Writable);
  25880. Verify.prototype._write = function _write(data, _, done) {
  25881. this._hash.update(data);
  25882. done();
  25883. };
  25884. Verify.prototype.update = function update(data, enc) {
  25885. if (typeof data === 'string') data = Buffer.from(data, enc);
  25886. this._hash.update(data);
  25887. return this;
  25888. };
  25889. Verify.prototype.verify = function verifyMethod(key, sig, enc) {
  25890. if (typeof sig === 'string') sig = Buffer.from(sig, enc);
  25891. this.end();
  25892. var hash = this._hash.digest();
  25893. return verify(sig, hash, key, this._signType, this._tag);
  25894. };
  25895. function createSign(algorithm) {
  25896. return new Sign(algorithm);
  25897. }
  25898. function createVerify(algorithm) {
  25899. return new Verify(algorithm);
  25900. }
  25901. module.exports = {
  25902. Sign: createSign,
  25903. Verify: createVerify,
  25904. createSign: createSign,
  25905. createVerify: createVerify
  25906. };
  25907. },{"./algorithms.json":211,"./sign":214,"./verify":215,"create-hash":386,"inherits":440,"readable-stream":491,"safe-buffer":494}],214:[function(require,module,exports){
  25908. "use strict";
  25909. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  25910. var Buffer = require('safe-buffer').Buffer;
  25911. var createHmac = require('create-hmac');
  25912. var crt = require('browserify-rsa');
  25913. var EC = require('elliptic').ec;
  25914. var BN = require('bn.js');
  25915. var parseKeys = require('parse-asn1');
  25916. var curves = require('./curves.json');
  25917. function sign(hash, key, hashType, signType, tag) {
  25918. var priv = parseKeys(key);
  25919. if (priv.curve) {
  25920. // rsa keys can be interpreted as ecdsa ones in openssl
  25921. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  25922. return ecSign(hash, priv);
  25923. } else if (priv.type === 'dsa') {
  25924. if (signType !== 'dsa') throw new Error('wrong private key type');
  25925. return dsaSign(hash, priv, hashType);
  25926. } else {
  25927. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  25928. }
  25929. hash = Buffer.concat([tag, hash]);
  25930. var len = priv.modulus.byteLength();
  25931. var pad = [0, 1];
  25932. while (hash.length + pad.length + 1 < len) pad.push(0xff);
  25933. pad.push(0x00);
  25934. var i = -1;
  25935. while (++i < hash.length) pad.push(hash[i]);
  25936. var out = crt(pad, priv);
  25937. return out;
  25938. }
  25939. function ecSign(hash, priv) {
  25940. var curveId = curves[priv.curve.join('.')];
  25941. if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'));
  25942. var curve = new EC(curveId);
  25943. var key = curve.keyFromPrivate(priv.privateKey);
  25944. var out = key.sign(hash);
  25945. return Buffer.from(out.toDER());
  25946. }
  25947. function dsaSign(hash, priv, algo) {
  25948. var x = priv.params.priv_key;
  25949. var p = priv.params.p;
  25950. var q = priv.params.q;
  25951. var g = priv.params.g;
  25952. var r = new BN(0);
  25953. var k;
  25954. var H = bits2int(hash, q).mod(q);
  25955. var s = false;
  25956. var kv = getKey(x, q, hash, algo);
  25957. while (s === false) {
  25958. k = makeKey(q, kv, algo);
  25959. r = makeR(g, k, p, q);
  25960. s = k.invm(q).imul(H.add(x.mul(r))).mod(q);
  25961. if (s.cmpn(0) === 0) {
  25962. s = false;
  25963. r = new BN(0);
  25964. }
  25965. }
  25966. return toDER(r, s);
  25967. }
  25968. function toDER(r, s) {
  25969. r = r.toArray();
  25970. s = s.toArray();
  25971. // Pad values
  25972. if (r[0] & 0x80) r = [0].concat(r);
  25973. if (s[0] & 0x80) s = [0].concat(s);
  25974. var total = r.length + s.length + 4;
  25975. var res = [0x30, total, 0x02, r.length];
  25976. res = res.concat(r, [0x02, s.length], s);
  25977. return Buffer.from(res);
  25978. }
  25979. function getKey(x, q, hash, algo) {
  25980. x = Buffer.from(x.toArray());
  25981. if (x.length < q.byteLength()) {
  25982. var zeros = Buffer.alloc(q.byteLength() - x.length);
  25983. x = Buffer.concat([zeros, x]);
  25984. }
  25985. var hlen = hash.length;
  25986. var hbits = bits2octets(hash, q);
  25987. var v = Buffer.alloc(hlen);
  25988. v.fill(1);
  25989. var k = Buffer.alloc(hlen);
  25990. k = createHmac(algo, k).update(v).update(Buffer.from([0])).update(x).update(hbits).digest();
  25991. v = createHmac(algo, k).update(v).digest();
  25992. k = createHmac(algo, k).update(v).update(Buffer.from([1])).update(x).update(hbits).digest();
  25993. v = createHmac(algo, k).update(v).digest();
  25994. return {
  25995. k: k,
  25996. v: v
  25997. };
  25998. }
  25999. function bits2int(obits, q) {
  26000. var bits = new BN(obits);
  26001. var shift = (obits.length << 3) - q.bitLength();
  26002. if (shift > 0) bits.ishrn(shift);
  26003. return bits;
  26004. }
  26005. function bits2octets(bits, q) {
  26006. bits = bits2int(bits, q);
  26007. bits = bits.mod(q);
  26008. var out = Buffer.from(bits.toArray());
  26009. if (out.length < q.byteLength()) {
  26010. var zeros = Buffer.alloc(q.byteLength() - out.length);
  26011. out = Buffer.concat([zeros, out]);
  26012. }
  26013. return out;
  26014. }
  26015. function makeKey(q, kv, algo) {
  26016. var t;
  26017. var k;
  26018. do {
  26019. t = Buffer.alloc(0);
  26020. while (t.length * 8 < q.bitLength()) {
  26021. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  26022. t = Buffer.concat([t, kv.v]);
  26023. }
  26024. k = bits2int(t, q);
  26025. kv.k = createHmac(algo, kv.k).update(kv.v).update(Buffer.from([0])).digest();
  26026. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  26027. } while (k.cmp(q) !== -1);
  26028. return k;
  26029. }
  26030. function makeR(g, k, p, q) {
  26031. return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q);
  26032. }
  26033. module.exports = sign;
  26034. module.exports.getKey = getKey;
  26035. module.exports.makeKey = makeKey;
  26036. },{"./curves.json":212,"bn.js":186,"browserify-rsa":209,"create-hmac":388,"elliptic":405,"parse-asn1":459,"safe-buffer":494}],215:[function(require,module,exports){
  26037. "use strict";
  26038. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  26039. var Buffer = require('safe-buffer').Buffer;
  26040. var BN = require('bn.js');
  26041. var EC = require('elliptic').ec;
  26042. var parseKeys = require('parse-asn1');
  26043. var curves = require('./curves.json');
  26044. function verify(sig, hash, key, signType, tag) {
  26045. var pub = parseKeys(key);
  26046. if (pub.type === 'ec') {
  26047. // rsa keys can be interpreted as ecdsa ones in openssl
  26048. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  26049. return ecVerify(sig, hash, pub);
  26050. } else if (pub.type === 'dsa') {
  26051. if (signType !== 'dsa') throw new Error('wrong public key type');
  26052. return dsaVerify(sig, hash, pub);
  26053. } else {
  26054. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  26055. }
  26056. hash = Buffer.concat([tag, hash]);
  26057. var len = pub.modulus.byteLength();
  26058. var pad = [1];
  26059. var padNum = 0;
  26060. while (hash.length + pad.length + 2 < len) {
  26061. pad.push(0xff);
  26062. padNum++;
  26063. }
  26064. pad.push(0x00);
  26065. var i = -1;
  26066. while (++i < hash.length) {
  26067. pad.push(hash[i]);
  26068. }
  26069. pad = Buffer.from(pad);
  26070. var red = BN.mont(pub.modulus);
  26071. sig = new BN(sig).toRed(red);
  26072. sig = sig.redPow(new BN(pub.publicExponent));
  26073. sig = Buffer.from(sig.fromRed().toArray());
  26074. var out = padNum < 8 ? 1 : 0;
  26075. len = Math.min(sig.length, pad.length);
  26076. if (sig.length !== pad.length) out = 1;
  26077. i = -1;
  26078. while (++i < len) out |= sig[i] ^ pad[i];
  26079. return out === 0;
  26080. }
  26081. function ecVerify(sig, hash, pub) {
  26082. var curveId = curves[pub.data.algorithm.curve.join('.')];
  26083. if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'));
  26084. var curve = new EC(curveId);
  26085. var pubkey = pub.data.subjectPrivateKey.data;
  26086. return curve.verify(hash, sig, pubkey);
  26087. }
  26088. function dsaVerify(sig, hash, pub) {
  26089. var p = pub.data.p;
  26090. var q = pub.data.q;
  26091. var g = pub.data.g;
  26092. var y = pub.data.pub_key;
  26093. var unpacked = parseKeys.signature.decode(sig, 'der');
  26094. var s = unpacked.s;
  26095. var r = unpacked.r;
  26096. checkValue(s, q);
  26097. checkValue(r, q);
  26098. var montp = BN.mont(p);
  26099. var w = s.invm(q);
  26100. var v = g.toRed(montp).redPow(new BN(hash).mul(w).mod(q)).fromRed().mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed()).mod(p).mod(q);
  26101. return v.cmp(r) === 0;
  26102. }
  26103. function checkValue(b, q) {
  26104. if (b.cmpn(0) <= 0) throw new Error('invalid sig');
  26105. if (b.cmp(q) >= q) throw new Error('invalid sig');
  26106. }
  26107. module.exports = verify;
  26108. },{"./curves.json":212,"bn.js":186,"elliptic":405,"parse-asn1":459,"safe-buffer":494}],216:[function(require,module,exports){
  26109. "use strict";
  26110. },{}],217:[function(require,module,exports){
  26111. "use strict";
  26112. /* eslint-disable node/no-deprecated-api */
  26113. var buffer = require('buffer');
  26114. var Buffer = buffer.Buffer;
  26115. // alternative to using Object.keys for old browsers
  26116. function copyProps(src, dst) {
  26117. for (var key in src) {
  26118. dst[key] = src[key];
  26119. }
  26120. }
  26121. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  26122. module.exports = buffer;
  26123. } else {
  26124. // Copy properties from require('buffer')
  26125. copyProps(buffer, exports);
  26126. exports.Buffer = SafeBuffer;
  26127. }
  26128. function SafeBuffer(arg, encodingOrOffset, length) {
  26129. return Buffer(arg, encodingOrOffset, length);
  26130. }
  26131. // Copy static methods from Buffer
  26132. copyProps(Buffer, SafeBuffer);
  26133. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  26134. if (typeof arg === 'number') {
  26135. throw new TypeError('Argument must not be a number');
  26136. }
  26137. return Buffer(arg, encodingOrOffset, length);
  26138. };
  26139. SafeBuffer.alloc = function (size, fill, encoding) {
  26140. if (typeof size !== 'number') {
  26141. throw new TypeError('Argument must be a number');
  26142. }
  26143. var buf = Buffer(size);
  26144. if (fill !== undefined) {
  26145. if (typeof encoding === 'string') {
  26146. buf.fill(fill, encoding);
  26147. } else {
  26148. buf.fill(fill);
  26149. }
  26150. } else {
  26151. buf.fill(0);
  26152. }
  26153. return buf;
  26154. };
  26155. SafeBuffer.allocUnsafe = function (size) {
  26156. if (typeof size !== 'number') {
  26157. throw new TypeError('Argument must be a number');
  26158. }
  26159. return Buffer(size);
  26160. };
  26161. SafeBuffer.allocUnsafeSlow = function (size) {
  26162. if (typeof size !== 'number') {
  26163. throw new TypeError('Argument must be a number');
  26164. }
  26165. return buffer.SlowBuffer(size);
  26166. };
  26167. },{"buffer":220}],218:[function(require,module,exports){
  26168. // Copyright Joyent, Inc. and other Node contributors.
  26169. //
  26170. // Permission is hereby granted, free of charge, to any person obtaining a
  26171. // copy of this software and associated documentation files (the
  26172. // "Software"), to deal in the Software without restriction, including
  26173. // without limitation the rights to use, copy, modify, merge, publish,
  26174. // distribute, sublicense, and/or sell copies of the Software, and to permit
  26175. // persons to whom the Software is furnished to do so, subject to the
  26176. // following conditions:
  26177. //
  26178. // The above copyright notice and this permission notice shall be included
  26179. // in all copies or substantial portions of the Software.
  26180. //
  26181. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  26182. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26183. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  26184. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  26185. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  26186. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  26187. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  26188. 'use strict';
  26189. /*<replacement>*/
  26190. var Buffer = require('safe-buffer').Buffer;
  26191. /*</replacement>*/
  26192. var isEncoding = Buffer.isEncoding || function (encoding) {
  26193. encoding = '' + encoding;
  26194. switch (encoding && encoding.toLowerCase()) {
  26195. case 'hex':
  26196. case 'utf8':
  26197. case 'utf-8':
  26198. case 'ascii':
  26199. case 'binary':
  26200. case 'base64':
  26201. case 'ucs2':
  26202. case 'ucs-2':
  26203. case 'utf16le':
  26204. case 'utf-16le':
  26205. case 'raw':
  26206. return true;
  26207. default:
  26208. return false;
  26209. }
  26210. };
  26211. function _normalizeEncoding(enc) {
  26212. if (!enc) return 'utf8';
  26213. var retried;
  26214. while (true) {
  26215. switch (enc) {
  26216. case 'utf8':
  26217. case 'utf-8':
  26218. return 'utf8';
  26219. case 'ucs2':
  26220. case 'ucs-2':
  26221. case 'utf16le':
  26222. case 'utf-16le':
  26223. return 'utf16le';
  26224. case 'latin1':
  26225. case 'binary':
  26226. return 'latin1';
  26227. case 'base64':
  26228. case 'ascii':
  26229. case 'hex':
  26230. return enc;
  26231. default:
  26232. if (retried) return; // undefined
  26233. enc = ('' + enc).toLowerCase();
  26234. retried = true;
  26235. }
  26236. }
  26237. }
  26238. ;
  26239. // Do not cache `Buffer.isEncoding` when checking encoding names as some
  26240. // modules monkey-patch it to support additional encodings
  26241. function normalizeEncoding(enc) {
  26242. var nenc = _normalizeEncoding(enc);
  26243. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  26244. return nenc || enc;
  26245. }
  26246. // StringDecoder provides an interface for efficiently splitting a series of
  26247. // buffers into a series of JS strings without breaking apart multi-byte
  26248. // characters.
  26249. exports.StringDecoder = StringDecoder;
  26250. function StringDecoder(encoding) {
  26251. this.encoding = normalizeEncoding(encoding);
  26252. var nb;
  26253. switch (this.encoding) {
  26254. case 'utf16le':
  26255. this.text = utf16Text;
  26256. this.end = utf16End;
  26257. nb = 4;
  26258. break;
  26259. case 'utf8':
  26260. this.fillLast = utf8FillLast;
  26261. nb = 4;
  26262. break;
  26263. case 'base64':
  26264. this.text = base64Text;
  26265. this.end = base64End;
  26266. nb = 3;
  26267. break;
  26268. default:
  26269. this.write = simpleWrite;
  26270. this.end = simpleEnd;
  26271. return;
  26272. }
  26273. this.lastNeed = 0;
  26274. this.lastTotal = 0;
  26275. this.lastChar = Buffer.allocUnsafe(nb);
  26276. }
  26277. StringDecoder.prototype.write = function (buf) {
  26278. if (buf.length === 0) return '';
  26279. var r;
  26280. var i;
  26281. if (this.lastNeed) {
  26282. r = this.fillLast(buf);
  26283. if (r === undefined) return '';
  26284. i = this.lastNeed;
  26285. this.lastNeed = 0;
  26286. } else {
  26287. i = 0;
  26288. }
  26289. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  26290. return r || '';
  26291. };
  26292. StringDecoder.prototype.end = utf8End;
  26293. // Returns only complete characters in a Buffer
  26294. StringDecoder.prototype.text = utf8Text;
  26295. // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  26296. StringDecoder.prototype.fillLast = function (buf) {
  26297. if (this.lastNeed <= buf.length) {
  26298. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  26299. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  26300. }
  26301. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  26302. this.lastNeed -= buf.length;
  26303. };
  26304. // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  26305. // continuation byte. If an invalid byte is detected, -2 is returned.
  26306. function utf8CheckByte(byte) {
  26307. if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
  26308. return byte >> 6 === 0x02 ? -1 : -2;
  26309. }
  26310. // Checks at most 3 bytes at the end of a Buffer in order to detect an
  26311. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  26312. // needed to complete the UTF-8 character (if applicable) are returned.
  26313. function utf8CheckIncomplete(self, buf, i) {
  26314. var j = buf.length - 1;
  26315. if (j < i) return 0;
  26316. var nb = utf8CheckByte(buf[j]);
  26317. if (nb >= 0) {
  26318. if (nb > 0) self.lastNeed = nb - 1;
  26319. return nb;
  26320. }
  26321. if (--j < i || nb === -2) return 0;
  26322. nb = utf8CheckByte(buf[j]);
  26323. if (nb >= 0) {
  26324. if (nb > 0) self.lastNeed = nb - 2;
  26325. return nb;
  26326. }
  26327. if (--j < i || nb === -2) return 0;
  26328. nb = utf8CheckByte(buf[j]);
  26329. if (nb >= 0) {
  26330. if (nb > 0) {
  26331. if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  26332. }
  26333. return nb;
  26334. }
  26335. return 0;
  26336. }
  26337. // Validates as many continuation bytes for a multi-byte UTF-8 character as
  26338. // needed or are available. If we see a non-continuation byte where we expect
  26339. // one, we "replace" the validated continuation bytes we've seen so far with
  26340. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  26341. // behavior. The continuation byte check is included three times in the case
  26342. // where all of the continuation bytes for a character exist in the same buffer.
  26343. // It is also done this way as a slight performance increase instead of using a
  26344. // loop.
  26345. function utf8CheckExtraBytes(self, buf, p) {
  26346. if ((buf[0] & 0xC0) !== 0x80) {
  26347. self.lastNeed = 0;
  26348. return '\ufffd';
  26349. }
  26350. if (self.lastNeed > 1 && buf.length > 1) {
  26351. if ((buf[1] & 0xC0) !== 0x80) {
  26352. self.lastNeed = 1;
  26353. return '\ufffd';
  26354. }
  26355. if (self.lastNeed > 2 && buf.length > 2) {
  26356. if ((buf[2] & 0xC0) !== 0x80) {
  26357. self.lastNeed = 2;
  26358. return '\ufffd';
  26359. }
  26360. }
  26361. }
  26362. }
  26363. // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  26364. function utf8FillLast(buf) {
  26365. var p = this.lastTotal - this.lastNeed;
  26366. var r = utf8CheckExtraBytes(this, buf, p);
  26367. if (r !== undefined) return r;
  26368. if (this.lastNeed <= buf.length) {
  26369. buf.copy(this.lastChar, p, 0, this.lastNeed);
  26370. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  26371. }
  26372. buf.copy(this.lastChar, p, 0, buf.length);
  26373. this.lastNeed -= buf.length;
  26374. }
  26375. // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  26376. // partial character, the character's bytes are buffered until the required
  26377. // number of bytes are available.
  26378. function utf8Text(buf, i) {
  26379. var total = utf8CheckIncomplete(this, buf, i);
  26380. if (!this.lastNeed) return buf.toString('utf8', i);
  26381. this.lastTotal = total;
  26382. var end = buf.length - (total - this.lastNeed);
  26383. buf.copy(this.lastChar, 0, end);
  26384. return buf.toString('utf8', i, end);
  26385. }
  26386. // For UTF-8, a replacement character is added when ending on a partial
  26387. // character.
  26388. function utf8End(buf) {
  26389. var r = buf && buf.length ? this.write(buf) : '';
  26390. if (this.lastNeed) return r + '\ufffd';
  26391. return r;
  26392. }
  26393. // UTF-16LE typically needs two bytes per character, but even if we have an even
  26394. // number of bytes available, we need to check if we end on a leading/high
  26395. // surrogate. In that case, we need to wait for the next two bytes in order to
  26396. // decode the last character properly.
  26397. function utf16Text(buf, i) {
  26398. if ((buf.length - i) % 2 === 0) {
  26399. var r = buf.toString('utf16le', i);
  26400. if (r) {
  26401. var c = r.charCodeAt(r.length - 1);
  26402. if (c >= 0xD800 && c <= 0xDBFF) {
  26403. this.lastNeed = 2;
  26404. this.lastTotal = 4;
  26405. this.lastChar[0] = buf[buf.length - 2];
  26406. this.lastChar[1] = buf[buf.length - 1];
  26407. return r.slice(0, -1);
  26408. }
  26409. }
  26410. return r;
  26411. }
  26412. this.lastNeed = 1;
  26413. this.lastTotal = 2;
  26414. this.lastChar[0] = buf[buf.length - 1];
  26415. return buf.toString('utf16le', i, buf.length - 1);
  26416. }
  26417. // For UTF-16LE we do not explicitly append special replacement characters if we
  26418. // end on a partial character, we simply let v8 handle that.
  26419. function utf16End(buf) {
  26420. var r = buf && buf.length ? this.write(buf) : '';
  26421. if (this.lastNeed) {
  26422. var end = this.lastTotal - this.lastNeed;
  26423. return r + this.lastChar.toString('utf16le', 0, end);
  26424. }
  26425. return r;
  26426. }
  26427. function base64Text(buf, i) {
  26428. var n = (buf.length - i) % 3;
  26429. if (n === 0) return buf.toString('base64', i);
  26430. this.lastNeed = 3 - n;
  26431. this.lastTotal = 3;
  26432. if (n === 1) {
  26433. this.lastChar[0] = buf[buf.length - 1];
  26434. } else {
  26435. this.lastChar[0] = buf[buf.length - 2];
  26436. this.lastChar[1] = buf[buf.length - 1];
  26437. }
  26438. return buf.toString('base64', i, buf.length - n);
  26439. }
  26440. function base64End(buf) {
  26441. var r = buf && buf.length ? this.write(buf) : '';
  26442. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  26443. return r;
  26444. }
  26445. // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  26446. function simpleWrite(buf) {
  26447. return buf.toString(this.encoding);
  26448. }
  26449. function simpleEnd(buf) {
  26450. return buf && buf.length ? this.write(buf) : '';
  26451. }
  26452. },{"safe-buffer":217}],219:[function(require,module,exports){
  26453. (function (Buffer){(function (){
  26454. "use strict";
  26455. module.exports = function xor(a, b) {
  26456. var length = Math.min(a.length, b.length);
  26457. var buffer = new Buffer(length);
  26458. for (var i = 0; i < length; ++i) {
  26459. buffer[i] = a[i] ^ b[i];
  26460. }
  26461. return buffer;
  26462. };
  26463. }).call(this)}).call(this,require("buffer").Buffer)
  26464. },{"buffer":220}],220:[function(require,module,exports){
  26465. (function (Buffer){(function (){
  26466. /*!
  26467. * The buffer module from node.js, for the browser.
  26468. *
  26469. * @author Feross Aboukhadijeh <https://feross.org>
  26470. * @license MIT
  26471. */
  26472. /* eslint-disable no-proto */
  26473. 'use strict';
  26474. var base64 = require('base64-js');
  26475. var ieee754 = require('ieee754');
  26476. exports.Buffer = Buffer;
  26477. exports.SlowBuffer = SlowBuffer;
  26478. exports.INSPECT_MAX_BYTES = 50;
  26479. var K_MAX_LENGTH = 0x7fffffff;
  26480. exports.kMaxLength = K_MAX_LENGTH;
  26481. /**
  26482. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  26483. * === true Use Uint8Array implementation (fastest)
  26484. * === false Print warning and recommend using `buffer` v4.x which has an Object
  26485. * implementation (most compatible, even IE6)
  26486. *
  26487. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  26488. * Opera 11.6+, iOS 4.2+.
  26489. *
  26490. * We report that the browser does not support typed arrays if the are not subclassable
  26491. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  26492. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  26493. * for __proto__ and has a buggy typed array implementation.
  26494. */
  26495. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  26496. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') {
  26497. console.error('This browser lacks typed array (Uint8Array) support which is required by ' + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.');
  26498. }
  26499. function typedArraySupport() {
  26500. // Can typed array instances can be augmented?
  26501. try {
  26502. var arr = new Uint8Array(1);
  26503. arr.__proto__ = {
  26504. __proto__: Uint8Array.prototype,
  26505. foo: function () {
  26506. return 42;
  26507. }
  26508. };
  26509. return arr.foo() === 42;
  26510. } catch (e) {
  26511. return false;
  26512. }
  26513. }
  26514. Object.defineProperty(Buffer.prototype, 'parent', {
  26515. enumerable: true,
  26516. get: function () {
  26517. if (!Buffer.isBuffer(this)) return undefined;
  26518. return this.buffer;
  26519. }
  26520. });
  26521. Object.defineProperty(Buffer.prototype, 'offset', {
  26522. enumerable: true,
  26523. get: function () {
  26524. if (!Buffer.isBuffer(this)) return undefined;
  26525. return this.byteOffset;
  26526. }
  26527. });
  26528. function createBuffer(length) {
  26529. if (length > K_MAX_LENGTH) {
  26530. throw new RangeError('The value "' + length + '" is invalid for option "size"');
  26531. }
  26532. // Return an augmented `Uint8Array` instance
  26533. var buf = new Uint8Array(length);
  26534. buf.__proto__ = Buffer.prototype;
  26535. return buf;
  26536. }
  26537. /**
  26538. * The Buffer constructor returns instances of `Uint8Array` that have their
  26539. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  26540. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  26541. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  26542. * returns a single octet.
  26543. *
  26544. * The `Uint8Array` prototype remains unmodified.
  26545. */
  26546. function Buffer(arg, encodingOrOffset, length) {
  26547. // Common case.
  26548. if (typeof arg === 'number') {
  26549. if (typeof encodingOrOffset === 'string') {
  26550. throw new TypeError('The "string" argument must be of type string. Received type number');
  26551. }
  26552. return allocUnsafe(arg);
  26553. }
  26554. return from(arg, encodingOrOffset, length);
  26555. }
  26556. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  26557. if (typeof Symbol !== 'undefined' && Symbol.species != null && Buffer[Symbol.species] === Buffer) {
  26558. Object.defineProperty(Buffer, Symbol.species, {
  26559. value: null,
  26560. configurable: true,
  26561. enumerable: false,
  26562. writable: false
  26563. });
  26564. }
  26565. Buffer.poolSize = 8192; // not used by this implementation
  26566. function from(value, encodingOrOffset, length) {
  26567. if (typeof value === 'string') {
  26568. return fromString(value, encodingOrOffset);
  26569. }
  26570. if (ArrayBuffer.isView(value)) {
  26571. return fromArrayLike(value);
  26572. }
  26573. if (value == null) {
  26574. throw TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + typeof value);
  26575. }
  26576. if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
  26577. return fromArrayBuffer(value, encodingOrOffset, length);
  26578. }
  26579. if (typeof value === 'number') {
  26580. throw new TypeError('The "value" argument must not be of type number. Received type number');
  26581. }
  26582. var valueOf = value.valueOf && value.valueOf();
  26583. if (valueOf != null && valueOf !== value) {
  26584. return Buffer.from(valueOf, encodingOrOffset, length);
  26585. }
  26586. var b = fromObject(value);
  26587. if (b) return b;
  26588. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') {
  26589. return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
  26590. }
  26591. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + typeof value);
  26592. }
  26593. /**
  26594. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  26595. * if value is a number.
  26596. * Buffer.from(str[, encoding])
  26597. * Buffer.from(array)
  26598. * Buffer.from(buffer)
  26599. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  26600. **/
  26601. Buffer.from = function (value, encodingOrOffset, length) {
  26602. return from(value, encodingOrOffset, length);
  26603. };
  26604. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  26605. // https://github.com/feross/buffer/pull/148
  26606. Buffer.prototype.__proto__ = Uint8Array.prototype;
  26607. Buffer.__proto__ = Uint8Array;
  26608. function assertSize(size) {
  26609. if (typeof size !== 'number') {
  26610. throw new TypeError('"size" argument must be of type number');
  26611. } else if (size < 0) {
  26612. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  26613. }
  26614. }
  26615. function alloc(size, fill, encoding) {
  26616. assertSize(size);
  26617. if (size <= 0) {
  26618. return createBuffer(size);
  26619. }
  26620. if (fill !== undefined) {
  26621. // Only pay attention to encoding if it's a string. This
  26622. // prevents accidentally sending in a number that would
  26623. // be interpretted as a start offset.
  26624. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
  26625. }
  26626. return createBuffer(size);
  26627. }
  26628. /**
  26629. * Creates a new filled Buffer instance.
  26630. * alloc(size[, fill[, encoding]])
  26631. **/
  26632. Buffer.alloc = function (size, fill, encoding) {
  26633. return alloc(size, fill, encoding);
  26634. };
  26635. function allocUnsafe(size) {
  26636. assertSize(size);
  26637. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  26638. }
  26639. /**
  26640. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  26641. * */
  26642. Buffer.allocUnsafe = function (size) {
  26643. return allocUnsafe(size);
  26644. };
  26645. /**
  26646. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  26647. */
  26648. Buffer.allocUnsafeSlow = function (size) {
  26649. return allocUnsafe(size);
  26650. };
  26651. function fromString(string, encoding) {
  26652. if (typeof encoding !== 'string' || encoding === '') {
  26653. encoding = 'utf8';
  26654. }
  26655. if (!Buffer.isEncoding(encoding)) {
  26656. throw new TypeError('Unknown encoding: ' + encoding);
  26657. }
  26658. var length = byteLength(string, encoding) | 0;
  26659. var buf = createBuffer(length);
  26660. var actual = buf.write(string, encoding);
  26661. if (actual !== length) {
  26662. // Writing a hex string, for example, that contains invalid characters will
  26663. // cause everything after the first invalid character to be ignored. (e.g.
  26664. // 'abxxcd' will be treated as 'ab')
  26665. buf = buf.slice(0, actual);
  26666. }
  26667. return buf;
  26668. }
  26669. function fromArrayLike(array) {
  26670. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  26671. var buf = createBuffer(length);
  26672. for (var i = 0; i < length; i += 1) {
  26673. buf[i] = array[i] & 255;
  26674. }
  26675. return buf;
  26676. }
  26677. function fromArrayBuffer(array, byteOffset, length) {
  26678. if (byteOffset < 0 || array.byteLength < byteOffset) {
  26679. throw new RangeError('"offset" is outside of buffer bounds');
  26680. }
  26681. if (array.byteLength < byteOffset + (length || 0)) {
  26682. throw new RangeError('"length" is outside of buffer bounds');
  26683. }
  26684. var buf;
  26685. if (byteOffset === undefined && length === undefined) {
  26686. buf = new Uint8Array(array);
  26687. } else if (length === undefined) {
  26688. buf = new Uint8Array(array, byteOffset);
  26689. } else {
  26690. buf = new Uint8Array(array, byteOffset, length);
  26691. }
  26692. // Return an augmented `Uint8Array` instance
  26693. buf.__proto__ = Buffer.prototype;
  26694. return buf;
  26695. }
  26696. function fromObject(obj) {
  26697. if (Buffer.isBuffer(obj)) {
  26698. var len = checked(obj.length) | 0;
  26699. var buf = createBuffer(len);
  26700. if (buf.length === 0) {
  26701. return buf;
  26702. }
  26703. obj.copy(buf, 0, 0, len);
  26704. return buf;
  26705. }
  26706. if (obj.length !== undefined) {
  26707. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  26708. return createBuffer(0);
  26709. }
  26710. return fromArrayLike(obj);
  26711. }
  26712. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  26713. return fromArrayLike(obj.data);
  26714. }
  26715. }
  26716. function checked(length) {
  26717. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  26718. // length is NaN (which is otherwise coerced to zero.)
  26719. if (length >= K_MAX_LENGTH) {
  26720. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
  26721. }
  26722. return length | 0;
  26723. }
  26724. function SlowBuffer(length) {
  26725. if (+length != length) {
  26726. // eslint-disable-line eqeqeq
  26727. length = 0;
  26728. }
  26729. return Buffer.alloc(+length);
  26730. }
  26731. Buffer.isBuffer = function isBuffer(b) {
  26732. return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
  26733. };
  26734. Buffer.compare = function compare(a, b) {
  26735. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
  26736. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
  26737. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  26738. throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
  26739. }
  26740. if (a === b) return 0;
  26741. var x = a.length;
  26742. var y = b.length;
  26743. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  26744. if (a[i] !== b[i]) {
  26745. x = a[i];
  26746. y = b[i];
  26747. break;
  26748. }
  26749. }
  26750. if (x < y) return -1;
  26751. if (y < x) return 1;
  26752. return 0;
  26753. };
  26754. Buffer.isEncoding = function isEncoding(encoding) {
  26755. switch (String(encoding).toLowerCase()) {
  26756. case 'hex':
  26757. case 'utf8':
  26758. case 'utf-8':
  26759. case 'ascii':
  26760. case 'latin1':
  26761. case 'binary':
  26762. case 'base64':
  26763. case 'ucs2':
  26764. case 'ucs-2':
  26765. case 'utf16le':
  26766. case 'utf-16le':
  26767. return true;
  26768. default:
  26769. return false;
  26770. }
  26771. };
  26772. Buffer.concat = function concat(list, length) {
  26773. if (!Array.isArray(list)) {
  26774. throw new TypeError('"list" argument must be an Array of Buffers');
  26775. }
  26776. if (list.length === 0) {
  26777. return Buffer.alloc(0);
  26778. }
  26779. var i;
  26780. if (length === undefined) {
  26781. length = 0;
  26782. for (i = 0; i < list.length; ++i) {
  26783. length += list[i].length;
  26784. }
  26785. }
  26786. var buffer = Buffer.allocUnsafe(length);
  26787. var pos = 0;
  26788. for (i = 0; i < list.length; ++i) {
  26789. var buf = list[i];
  26790. if (isInstance(buf, Uint8Array)) {
  26791. buf = Buffer.from(buf);
  26792. }
  26793. if (!Buffer.isBuffer(buf)) {
  26794. throw new TypeError('"list" argument must be an Array of Buffers');
  26795. }
  26796. buf.copy(buffer, pos);
  26797. pos += buf.length;
  26798. }
  26799. return buffer;
  26800. };
  26801. function byteLength(string, encoding) {
  26802. if (Buffer.isBuffer(string)) {
  26803. return string.length;
  26804. }
  26805. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  26806. return string.byteLength;
  26807. }
  26808. if (typeof string !== 'string') {
  26809. throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + typeof string);
  26810. }
  26811. var len = string.length;
  26812. var mustMatch = arguments.length > 2 && arguments[2] === true;
  26813. if (!mustMatch && len === 0) return 0;
  26814. // Use a for loop to avoid recursion
  26815. var loweredCase = false;
  26816. for (;;) {
  26817. switch (encoding) {
  26818. case 'ascii':
  26819. case 'latin1':
  26820. case 'binary':
  26821. return len;
  26822. case 'utf8':
  26823. case 'utf-8':
  26824. return utf8ToBytes(string).length;
  26825. case 'ucs2':
  26826. case 'ucs-2':
  26827. case 'utf16le':
  26828. case 'utf-16le':
  26829. return len * 2;
  26830. case 'hex':
  26831. return len >>> 1;
  26832. case 'base64':
  26833. return base64ToBytes(string).length;
  26834. default:
  26835. if (loweredCase) {
  26836. return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
  26837. }
  26838. encoding = ('' + encoding).toLowerCase();
  26839. loweredCase = true;
  26840. }
  26841. }
  26842. }
  26843. Buffer.byteLength = byteLength;
  26844. function slowToString(encoding, start, end) {
  26845. var loweredCase = false;
  26846. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  26847. // property of a typed array.
  26848. // This behaves neither like String nor Uint8Array in that we set start/end
  26849. // to their upper/lower bounds if the value passed is out of range.
  26850. // undefined is handled specially as per ECMA-262 6th Edition,
  26851. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  26852. if (start === undefined || start < 0) {
  26853. start = 0;
  26854. }
  26855. // Return early if start > this.length. Done here to prevent potential uint32
  26856. // coercion fail below.
  26857. if (start > this.length) {
  26858. return '';
  26859. }
  26860. if (end === undefined || end > this.length) {
  26861. end = this.length;
  26862. }
  26863. if (end <= 0) {
  26864. return '';
  26865. }
  26866. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  26867. end >>>= 0;
  26868. start >>>= 0;
  26869. if (end <= start) {
  26870. return '';
  26871. }
  26872. if (!encoding) encoding = 'utf8';
  26873. while (true) {
  26874. switch (encoding) {
  26875. case 'hex':
  26876. return hexSlice(this, start, end);
  26877. case 'utf8':
  26878. case 'utf-8':
  26879. return utf8Slice(this, start, end);
  26880. case 'ascii':
  26881. return asciiSlice(this, start, end);
  26882. case 'latin1':
  26883. case 'binary':
  26884. return latin1Slice(this, start, end);
  26885. case 'base64':
  26886. return base64Slice(this, start, end);
  26887. case 'ucs2':
  26888. case 'ucs-2':
  26889. case 'utf16le':
  26890. case 'utf-16le':
  26891. return utf16leSlice(this, start, end);
  26892. default:
  26893. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  26894. encoding = (encoding + '').toLowerCase();
  26895. loweredCase = true;
  26896. }
  26897. }
  26898. }
  26899. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  26900. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  26901. // reliably in a browserify context because there could be multiple different
  26902. // copies of the 'buffer' package in use. This method works even for Buffer
  26903. // instances that were created from another copy of the `buffer` package.
  26904. // See: https://github.com/feross/buffer/issues/154
  26905. Buffer.prototype._isBuffer = true;
  26906. function swap(b, n, m) {
  26907. var i = b[n];
  26908. b[n] = b[m];
  26909. b[m] = i;
  26910. }
  26911. Buffer.prototype.swap16 = function swap16() {
  26912. var len = this.length;
  26913. if (len % 2 !== 0) {
  26914. throw new RangeError('Buffer size must be a multiple of 16-bits');
  26915. }
  26916. for (var i = 0; i < len; i += 2) {
  26917. swap(this, i, i + 1);
  26918. }
  26919. return this;
  26920. };
  26921. Buffer.prototype.swap32 = function swap32() {
  26922. var len = this.length;
  26923. if (len % 4 !== 0) {
  26924. throw new RangeError('Buffer size must be a multiple of 32-bits');
  26925. }
  26926. for (var i = 0; i < len; i += 4) {
  26927. swap(this, i, i + 3);
  26928. swap(this, i + 1, i + 2);
  26929. }
  26930. return this;
  26931. };
  26932. Buffer.prototype.swap64 = function swap64() {
  26933. var len = this.length;
  26934. if (len % 8 !== 0) {
  26935. throw new RangeError('Buffer size must be a multiple of 64-bits');
  26936. }
  26937. for (var i = 0; i < len; i += 8) {
  26938. swap(this, i, i + 7);
  26939. swap(this, i + 1, i + 6);
  26940. swap(this, i + 2, i + 5);
  26941. swap(this, i + 3, i + 4);
  26942. }
  26943. return this;
  26944. };
  26945. Buffer.prototype.toString = function toString() {
  26946. var length = this.length;
  26947. if (length === 0) return '';
  26948. if (arguments.length === 0) return utf8Slice(this, 0, length);
  26949. return slowToString.apply(this, arguments);
  26950. };
  26951. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  26952. Buffer.prototype.equals = function equals(b) {
  26953. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  26954. if (this === b) return true;
  26955. return Buffer.compare(this, b) === 0;
  26956. };
  26957. Buffer.prototype.inspect = function inspect() {
  26958. var str = '';
  26959. var max = exports.INSPECT_MAX_BYTES;
  26960. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
  26961. if (this.length > max) str += ' ... ';
  26962. return '<Buffer ' + str + '>';
  26963. };
  26964. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  26965. if (isInstance(target, Uint8Array)) {
  26966. target = Buffer.from(target, target.offset, target.byteLength);
  26967. }
  26968. if (!Buffer.isBuffer(target)) {
  26969. throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + typeof target);
  26970. }
  26971. if (start === undefined) {
  26972. start = 0;
  26973. }
  26974. if (end === undefined) {
  26975. end = target ? target.length : 0;
  26976. }
  26977. if (thisStart === undefined) {
  26978. thisStart = 0;
  26979. }
  26980. if (thisEnd === undefined) {
  26981. thisEnd = this.length;
  26982. }
  26983. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  26984. throw new RangeError('out of range index');
  26985. }
  26986. if (thisStart >= thisEnd && start >= end) {
  26987. return 0;
  26988. }
  26989. if (thisStart >= thisEnd) {
  26990. return -1;
  26991. }
  26992. if (start >= end) {
  26993. return 1;
  26994. }
  26995. start >>>= 0;
  26996. end >>>= 0;
  26997. thisStart >>>= 0;
  26998. thisEnd >>>= 0;
  26999. if (this === target) return 0;
  27000. var x = thisEnd - thisStart;
  27001. var y = end - start;
  27002. var len = Math.min(x, y);
  27003. var thisCopy = this.slice(thisStart, thisEnd);
  27004. var targetCopy = target.slice(start, end);
  27005. for (var i = 0; i < len; ++i) {
  27006. if (thisCopy[i] !== targetCopy[i]) {
  27007. x = thisCopy[i];
  27008. y = targetCopy[i];
  27009. break;
  27010. }
  27011. }
  27012. if (x < y) return -1;
  27013. if (y < x) return 1;
  27014. return 0;
  27015. };
  27016. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  27017. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  27018. //
  27019. // Arguments:
  27020. // - buffer - a Buffer to search
  27021. // - val - a string, Buffer, or number
  27022. // - byteOffset - an index into `buffer`; will be clamped to an int32
  27023. // - encoding - an optional encoding, relevant is val is a string
  27024. // - dir - true for indexOf, false for lastIndexOf
  27025. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  27026. // Empty buffer means no match
  27027. if (buffer.length === 0) return -1;
  27028. // Normalize byteOffset
  27029. if (typeof byteOffset === 'string') {
  27030. encoding = byteOffset;
  27031. byteOffset = 0;
  27032. } else if (byteOffset > 0x7fffffff) {
  27033. byteOffset = 0x7fffffff;
  27034. } else if (byteOffset < -0x80000000) {
  27035. byteOffset = -0x80000000;
  27036. }
  27037. byteOffset = +byteOffset; // Coerce to Number.
  27038. if (numberIsNaN(byteOffset)) {
  27039. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  27040. byteOffset = dir ? 0 : buffer.length - 1;
  27041. }
  27042. // Normalize byteOffset: negative offsets start from the end of the buffer
  27043. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  27044. if (byteOffset >= buffer.length) {
  27045. if (dir) return -1;else byteOffset = buffer.length - 1;
  27046. } else if (byteOffset < 0) {
  27047. if (dir) byteOffset = 0;else return -1;
  27048. }
  27049. // Normalize val
  27050. if (typeof val === 'string') {
  27051. val = Buffer.from(val, encoding);
  27052. }
  27053. // Finally, search either indexOf (if dir is true) or lastIndexOf
  27054. if (Buffer.isBuffer(val)) {
  27055. // Special case: looking for empty string/buffer always fails
  27056. if (val.length === 0) {
  27057. return -1;
  27058. }
  27059. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  27060. } else if (typeof val === 'number') {
  27061. val = val & 0xFF; // Search for a byte value [0-255]
  27062. if (typeof Uint8Array.prototype.indexOf === 'function') {
  27063. if (dir) {
  27064. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  27065. } else {
  27066. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  27067. }
  27068. }
  27069. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  27070. }
  27071. throw new TypeError('val must be string, number or Buffer');
  27072. }
  27073. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  27074. var indexSize = 1;
  27075. var arrLength = arr.length;
  27076. var valLength = val.length;
  27077. if (encoding !== undefined) {
  27078. encoding = String(encoding).toLowerCase();
  27079. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  27080. if (arr.length < 2 || val.length < 2) {
  27081. return -1;
  27082. }
  27083. indexSize = 2;
  27084. arrLength /= 2;
  27085. valLength /= 2;
  27086. byteOffset /= 2;
  27087. }
  27088. }
  27089. function read(buf, i) {
  27090. if (indexSize === 1) {
  27091. return buf[i];
  27092. } else {
  27093. return buf.readUInt16BE(i * indexSize);
  27094. }
  27095. }
  27096. var i;
  27097. if (dir) {
  27098. var foundIndex = -1;
  27099. for (i = byteOffset; i < arrLength; i++) {
  27100. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  27101. if (foundIndex === -1) foundIndex = i;
  27102. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  27103. } else {
  27104. if (foundIndex !== -1) i -= i - foundIndex;
  27105. foundIndex = -1;
  27106. }
  27107. }
  27108. } else {
  27109. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  27110. for (i = byteOffset; i >= 0; i--) {
  27111. var found = true;
  27112. for (var j = 0; j < valLength; j++) {
  27113. if (read(arr, i + j) !== read(val, j)) {
  27114. found = false;
  27115. break;
  27116. }
  27117. }
  27118. if (found) return i;
  27119. }
  27120. }
  27121. return -1;
  27122. }
  27123. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  27124. return this.indexOf(val, byteOffset, encoding) !== -1;
  27125. };
  27126. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  27127. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  27128. };
  27129. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  27130. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  27131. };
  27132. function hexWrite(buf, string, offset, length) {
  27133. offset = Number(offset) || 0;
  27134. var remaining = buf.length - offset;
  27135. if (!length) {
  27136. length = remaining;
  27137. } else {
  27138. length = Number(length);
  27139. if (length > remaining) {
  27140. length = remaining;
  27141. }
  27142. }
  27143. var strLen = string.length;
  27144. if (length > strLen / 2) {
  27145. length = strLen / 2;
  27146. }
  27147. for (var i = 0; i < length; ++i) {
  27148. var parsed = parseInt(string.substr(i * 2, 2), 16);
  27149. if (numberIsNaN(parsed)) return i;
  27150. buf[offset + i] = parsed;
  27151. }
  27152. return i;
  27153. }
  27154. function utf8Write(buf, string, offset, length) {
  27155. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  27156. }
  27157. function asciiWrite(buf, string, offset, length) {
  27158. return blitBuffer(asciiToBytes(string), buf, offset, length);
  27159. }
  27160. function latin1Write(buf, string, offset, length) {
  27161. return asciiWrite(buf, string, offset, length);
  27162. }
  27163. function base64Write(buf, string, offset, length) {
  27164. return blitBuffer(base64ToBytes(string), buf, offset, length);
  27165. }
  27166. function ucs2Write(buf, string, offset, length) {
  27167. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  27168. }
  27169. Buffer.prototype.write = function write(string, offset, length, encoding) {
  27170. // Buffer#write(string)
  27171. if (offset === undefined) {
  27172. encoding = 'utf8';
  27173. length = this.length;
  27174. offset = 0;
  27175. // Buffer#write(string, encoding)
  27176. } else if (length === undefined && typeof offset === 'string') {
  27177. encoding = offset;
  27178. length = this.length;
  27179. offset = 0;
  27180. // Buffer#write(string, offset[, length][, encoding])
  27181. } else if (isFinite(offset)) {
  27182. offset = offset >>> 0;
  27183. if (isFinite(length)) {
  27184. length = length >>> 0;
  27185. if (encoding === undefined) encoding = 'utf8';
  27186. } else {
  27187. encoding = length;
  27188. length = undefined;
  27189. }
  27190. } else {
  27191. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  27192. }
  27193. var remaining = this.length - offset;
  27194. if (length === undefined || length > remaining) length = remaining;
  27195. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  27196. throw new RangeError('Attempt to write outside buffer bounds');
  27197. }
  27198. if (!encoding) encoding = 'utf8';
  27199. var loweredCase = false;
  27200. for (;;) {
  27201. switch (encoding) {
  27202. case 'hex':
  27203. return hexWrite(this, string, offset, length);
  27204. case 'utf8':
  27205. case 'utf-8':
  27206. return utf8Write(this, string, offset, length);
  27207. case 'ascii':
  27208. return asciiWrite(this, string, offset, length);
  27209. case 'latin1':
  27210. case 'binary':
  27211. return latin1Write(this, string, offset, length);
  27212. case 'base64':
  27213. // Warning: maxLength not taken into account in base64Write
  27214. return base64Write(this, string, offset, length);
  27215. case 'ucs2':
  27216. case 'ucs-2':
  27217. case 'utf16le':
  27218. case 'utf-16le':
  27219. return ucs2Write(this, string, offset, length);
  27220. default:
  27221. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  27222. encoding = ('' + encoding).toLowerCase();
  27223. loweredCase = true;
  27224. }
  27225. }
  27226. };
  27227. Buffer.prototype.toJSON = function toJSON() {
  27228. return {
  27229. type: 'Buffer',
  27230. data: Array.prototype.slice.call(this._arr || this, 0)
  27231. };
  27232. };
  27233. function base64Slice(buf, start, end) {
  27234. if (start === 0 && end === buf.length) {
  27235. return base64.fromByteArray(buf);
  27236. } else {
  27237. return base64.fromByteArray(buf.slice(start, end));
  27238. }
  27239. }
  27240. function utf8Slice(buf, start, end) {
  27241. end = Math.min(buf.length, end);
  27242. var res = [];
  27243. var i = start;
  27244. while (i < end) {
  27245. var firstByte = buf[i];
  27246. var codePoint = null;
  27247. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  27248. if (i + bytesPerSequence <= end) {
  27249. var secondByte, thirdByte, fourthByte, tempCodePoint;
  27250. switch (bytesPerSequence) {
  27251. case 1:
  27252. if (firstByte < 0x80) {
  27253. codePoint = firstByte;
  27254. }
  27255. break;
  27256. case 2:
  27257. secondByte = buf[i + 1];
  27258. if ((secondByte & 0xC0) === 0x80) {
  27259. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  27260. if (tempCodePoint > 0x7F) {
  27261. codePoint = tempCodePoint;
  27262. }
  27263. }
  27264. break;
  27265. case 3:
  27266. secondByte = buf[i + 1];
  27267. thirdByte = buf[i + 2];
  27268. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  27269. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  27270. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  27271. codePoint = tempCodePoint;
  27272. }
  27273. }
  27274. break;
  27275. case 4:
  27276. secondByte = buf[i + 1];
  27277. thirdByte = buf[i + 2];
  27278. fourthByte = buf[i + 3];
  27279. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  27280. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  27281. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  27282. codePoint = tempCodePoint;
  27283. }
  27284. }
  27285. }
  27286. }
  27287. if (codePoint === null) {
  27288. // we did not generate a valid codePoint so insert a
  27289. // replacement char (U+FFFD) and advance only 1 byte
  27290. codePoint = 0xFFFD;
  27291. bytesPerSequence = 1;
  27292. } else if (codePoint > 0xFFFF) {
  27293. // encode to utf16 (surrogate pair dance)
  27294. codePoint -= 0x10000;
  27295. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  27296. codePoint = 0xDC00 | codePoint & 0x3FF;
  27297. }
  27298. res.push(codePoint);
  27299. i += bytesPerSequence;
  27300. }
  27301. return decodeCodePointsArray(res);
  27302. }
  27303. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  27304. // the lowest limit is Chrome, with 0x10000 args.
  27305. // We go 1 magnitude less, for safety
  27306. var MAX_ARGUMENTS_LENGTH = 0x1000;
  27307. function decodeCodePointsArray(codePoints) {
  27308. var len = codePoints.length;
  27309. if (len <= MAX_ARGUMENTS_LENGTH) {
  27310. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  27311. }
  27312. // Decode in chunks to avoid "call stack size exceeded".
  27313. var res = '';
  27314. var i = 0;
  27315. while (i < len) {
  27316. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  27317. }
  27318. return res;
  27319. }
  27320. function asciiSlice(buf, start, end) {
  27321. var ret = '';
  27322. end = Math.min(buf.length, end);
  27323. for (var i = start; i < end; ++i) {
  27324. ret += String.fromCharCode(buf[i] & 0x7F);
  27325. }
  27326. return ret;
  27327. }
  27328. function latin1Slice(buf, start, end) {
  27329. var ret = '';
  27330. end = Math.min(buf.length, end);
  27331. for (var i = start; i < end; ++i) {
  27332. ret += String.fromCharCode(buf[i]);
  27333. }
  27334. return ret;
  27335. }
  27336. function hexSlice(buf, start, end) {
  27337. var len = buf.length;
  27338. if (!start || start < 0) start = 0;
  27339. if (!end || end < 0 || end > len) end = len;
  27340. var out = '';
  27341. for (var i = start; i < end; ++i) {
  27342. out += toHex(buf[i]);
  27343. }
  27344. return out;
  27345. }
  27346. function utf16leSlice(buf, start, end) {
  27347. var bytes = buf.slice(start, end);
  27348. var res = '';
  27349. for (var i = 0; i < bytes.length; i += 2) {
  27350. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  27351. }
  27352. return res;
  27353. }
  27354. Buffer.prototype.slice = function slice(start, end) {
  27355. var len = this.length;
  27356. start = ~~start;
  27357. end = end === undefined ? len : ~~end;
  27358. if (start < 0) {
  27359. start += len;
  27360. if (start < 0) start = 0;
  27361. } else if (start > len) {
  27362. start = len;
  27363. }
  27364. if (end < 0) {
  27365. end += len;
  27366. if (end < 0) end = 0;
  27367. } else if (end > len) {
  27368. end = len;
  27369. }
  27370. if (end < start) end = start;
  27371. var newBuf = this.subarray(start, end);
  27372. // Return an augmented `Uint8Array` instance
  27373. newBuf.__proto__ = Buffer.prototype;
  27374. return newBuf;
  27375. };
  27376. /*
  27377. * Need to make sure that buffer isn't trying to write out of bounds.
  27378. */
  27379. function checkOffset(offset, ext, length) {
  27380. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  27381. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  27382. }
  27383. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  27384. offset = offset >>> 0;
  27385. byteLength = byteLength >>> 0;
  27386. if (!noAssert) checkOffset(offset, byteLength, this.length);
  27387. var val = this[offset];
  27388. var mul = 1;
  27389. var i = 0;
  27390. while (++i < byteLength && (mul *= 0x100)) {
  27391. val += this[offset + i] * mul;
  27392. }
  27393. return val;
  27394. };
  27395. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  27396. offset = offset >>> 0;
  27397. byteLength = byteLength >>> 0;
  27398. if (!noAssert) {
  27399. checkOffset(offset, byteLength, this.length);
  27400. }
  27401. var val = this[offset + --byteLength];
  27402. var mul = 1;
  27403. while (byteLength > 0 && (mul *= 0x100)) {
  27404. val += this[offset + --byteLength] * mul;
  27405. }
  27406. return val;
  27407. };
  27408. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  27409. offset = offset >>> 0;
  27410. if (!noAssert) checkOffset(offset, 1, this.length);
  27411. return this[offset];
  27412. };
  27413. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  27414. offset = offset >>> 0;
  27415. if (!noAssert) checkOffset(offset, 2, this.length);
  27416. return this[offset] | this[offset + 1] << 8;
  27417. };
  27418. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  27419. offset = offset >>> 0;
  27420. if (!noAssert) checkOffset(offset, 2, this.length);
  27421. return this[offset] << 8 | this[offset + 1];
  27422. };
  27423. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  27424. offset = offset >>> 0;
  27425. if (!noAssert) checkOffset(offset, 4, this.length);
  27426. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  27427. };
  27428. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  27429. offset = offset >>> 0;
  27430. if (!noAssert) checkOffset(offset, 4, this.length);
  27431. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  27432. };
  27433. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  27434. offset = offset >>> 0;
  27435. byteLength = byteLength >>> 0;
  27436. if (!noAssert) checkOffset(offset, byteLength, this.length);
  27437. var val = this[offset];
  27438. var mul = 1;
  27439. var i = 0;
  27440. while (++i < byteLength && (mul *= 0x100)) {
  27441. val += this[offset + i] * mul;
  27442. }
  27443. mul *= 0x80;
  27444. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  27445. return val;
  27446. };
  27447. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  27448. offset = offset >>> 0;
  27449. byteLength = byteLength >>> 0;
  27450. if (!noAssert) checkOffset(offset, byteLength, this.length);
  27451. var i = byteLength;
  27452. var mul = 1;
  27453. var val = this[offset + --i];
  27454. while (i > 0 && (mul *= 0x100)) {
  27455. val += this[offset + --i] * mul;
  27456. }
  27457. mul *= 0x80;
  27458. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  27459. return val;
  27460. };
  27461. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  27462. offset = offset >>> 0;
  27463. if (!noAssert) checkOffset(offset, 1, this.length);
  27464. if (!(this[offset] & 0x80)) return this[offset];
  27465. return (0xff - this[offset] + 1) * -1;
  27466. };
  27467. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  27468. offset = offset >>> 0;
  27469. if (!noAssert) checkOffset(offset, 2, this.length);
  27470. var val = this[offset] | this[offset + 1] << 8;
  27471. return val & 0x8000 ? val | 0xFFFF0000 : val;
  27472. };
  27473. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  27474. offset = offset >>> 0;
  27475. if (!noAssert) checkOffset(offset, 2, this.length);
  27476. var val = this[offset + 1] | this[offset] << 8;
  27477. return val & 0x8000 ? val | 0xFFFF0000 : val;
  27478. };
  27479. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  27480. offset = offset >>> 0;
  27481. if (!noAssert) checkOffset(offset, 4, this.length);
  27482. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  27483. };
  27484. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  27485. offset = offset >>> 0;
  27486. if (!noAssert) checkOffset(offset, 4, this.length);
  27487. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  27488. };
  27489. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  27490. offset = offset >>> 0;
  27491. if (!noAssert) checkOffset(offset, 4, this.length);
  27492. return ieee754.read(this, offset, true, 23, 4);
  27493. };
  27494. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  27495. offset = offset >>> 0;
  27496. if (!noAssert) checkOffset(offset, 4, this.length);
  27497. return ieee754.read(this, offset, false, 23, 4);
  27498. };
  27499. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  27500. offset = offset >>> 0;
  27501. if (!noAssert) checkOffset(offset, 8, this.length);
  27502. return ieee754.read(this, offset, true, 52, 8);
  27503. };
  27504. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  27505. offset = offset >>> 0;
  27506. if (!noAssert) checkOffset(offset, 8, this.length);
  27507. return ieee754.read(this, offset, false, 52, 8);
  27508. };
  27509. function checkInt(buf, value, offset, ext, max, min) {
  27510. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  27511. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  27512. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  27513. }
  27514. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  27515. value = +value;
  27516. offset = offset >>> 0;
  27517. byteLength = byteLength >>> 0;
  27518. if (!noAssert) {
  27519. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  27520. checkInt(this, value, offset, byteLength, maxBytes, 0);
  27521. }
  27522. var mul = 1;
  27523. var i = 0;
  27524. this[offset] = value & 0xFF;
  27525. while (++i < byteLength && (mul *= 0x100)) {
  27526. this[offset + i] = value / mul & 0xFF;
  27527. }
  27528. return offset + byteLength;
  27529. };
  27530. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  27531. value = +value;
  27532. offset = offset >>> 0;
  27533. byteLength = byteLength >>> 0;
  27534. if (!noAssert) {
  27535. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  27536. checkInt(this, value, offset, byteLength, maxBytes, 0);
  27537. }
  27538. var i = byteLength - 1;
  27539. var mul = 1;
  27540. this[offset + i] = value & 0xFF;
  27541. while (--i >= 0 && (mul *= 0x100)) {
  27542. this[offset + i] = value / mul & 0xFF;
  27543. }
  27544. return offset + byteLength;
  27545. };
  27546. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  27547. value = +value;
  27548. offset = offset >>> 0;
  27549. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  27550. this[offset] = value & 0xff;
  27551. return offset + 1;
  27552. };
  27553. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  27554. value = +value;
  27555. offset = offset >>> 0;
  27556. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  27557. this[offset] = value & 0xff;
  27558. this[offset + 1] = value >>> 8;
  27559. return offset + 2;
  27560. };
  27561. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  27562. value = +value;
  27563. offset = offset >>> 0;
  27564. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  27565. this[offset] = value >>> 8;
  27566. this[offset + 1] = value & 0xff;
  27567. return offset + 2;
  27568. };
  27569. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  27570. value = +value;
  27571. offset = offset >>> 0;
  27572. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  27573. this[offset + 3] = value >>> 24;
  27574. this[offset + 2] = value >>> 16;
  27575. this[offset + 1] = value >>> 8;
  27576. this[offset] = value & 0xff;
  27577. return offset + 4;
  27578. };
  27579. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  27580. value = +value;
  27581. offset = offset >>> 0;
  27582. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  27583. this[offset] = value >>> 24;
  27584. this[offset + 1] = value >>> 16;
  27585. this[offset + 2] = value >>> 8;
  27586. this[offset + 3] = value & 0xff;
  27587. return offset + 4;
  27588. };
  27589. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  27590. value = +value;
  27591. offset = offset >>> 0;
  27592. if (!noAssert) {
  27593. var limit = Math.pow(2, 8 * byteLength - 1);
  27594. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  27595. }
  27596. var i = 0;
  27597. var mul = 1;
  27598. var sub = 0;
  27599. this[offset] = value & 0xFF;
  27600. while (++i < byteLength && (mul *= 0x100)) {
  27601. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  27602. sub = 1;
  27603. }
  27604. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  27605. }
  27606. return offset + byteLength;
  27607. };
  27608. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  27609. value = +value;
  27610. offset = offset >>> 0;
  27611. if (!noAssert) {
  27612. var limit = Math.pow(2, 8 * byteLength - 1);
  27613. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  27614. }
  27615. var i = byteLength - 1;
  27616. var mul = 1;
  27617. var sub = 0;
  27618. this[offset + i] = value & 0xFF;
  27619. while (--i >= 0 && (mul *= 0x100)) {
  27620. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  27621. sub = 1;
  27622. }
  27623. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  27624. }
  27625. return offset + byteLength;
  27626. };
  27627. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  27628. value = +value;
  27629. offset = offset >>> 0;
  27630. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  27631. if (value < 0) value = 0xff + value + 1;
  27632. this[offset] = value & 0xff;
  27633. return offset + 1;
  27634. };
  27635. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  27636. value = +value;
  27637. offset = offset >>> 0;
  27638. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  27639. this[offset] = value & 0xff;
  27640. this[offset + 1] = value >>> 8;
  27641. return offset + 2;
  27642. };
  27643. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  27644. value = +value;
  27645. offset = offset >>> 0;
  27646. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  27647. this[offset] = value >>> 8;
  27648. this[offset + 1] = value & 0xff;
  27649. return offset + 2;
  27650. };
  27651. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  27652. value = +value;
  27653. offset = offset >>> 0;
  27654. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  27655. this[offset] = value & 0xff;
  27656. this[offset + 1] = value >>> 8;
  27657. this[offset + 2] = value >>> 16;
  27658. this[offset + 3] = value >>> 24;
  27659. return offset + 4;
  27660. };
  27661. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  27662. value = +value;
  27663. offset = offset >>> 0;
  27664. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  27665. if (value < 0) value = 0xffffffff + value + 1;
  27666. this[offset] = value >>> 24;
  27667. this[offset + 1] = value >>> 16;
  27668. this[offset + 2] = value >>> 8;
  27669. this[offset + 3] = value & 0xff;
  27670. return offset + 4;
  27671. };
  27672. function checkIEEE754(buf, value, offset, ext, max, min) {
  27673. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  27674. if (offset < 0) throw new RangeError('Index out of range');
  27675. }
  27676. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  27677. value = +value;
  27678. offset = offset >>> 0;
  27679. if (!noAssert) {
  27680. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
  27681. }
  27682. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  27683. return offset + 4;
  27684. }
  27685. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  27686. return writeFloat(this, value, offset, true, noAssert);
  27687. };
  27688. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  27689. return writeFloat(this, value, offset, false, noAssert);
  27690. };
  27691. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  27692. value = +value;
  27693. offset = offset >>> 0;
  27694. if (!noAssert) {
  27695. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
  27696. }
  27697. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  27698. return offset + 8;
  27699. }
  27700. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  27701. return writeDouble(this, value, offset, true, noAssert);
  27702. };
  27703. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  27704. return writeDouble(this, value, offset, false, noAssert);
  27705. };
  27706. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  27707. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  27708. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
  27709. if (!start) start = 0;
  27710. if (!end && end !== 0) end = this.length;
  27711. if (targetStart >= target.length) targetStart = target.length;
  27712. if (!targetStart) targetStart = 0;
  27713. if (end > 0 && end < start) end = start;
  27714. // Copy 0 bytes; we're done
  27715. if (end === start) return 0;
  27716. if (target.length === 0 || this.length === 0) return 0;
  27717. // Fatal error conditions
  27718. if (targetStart < 0) {
  27719. throw new RangeError('targetStart out of bounds');
  27720. }
  27721. if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
  27722. if (end < 0) throw new RangeError('sourceEnd out of bounds');
  27723. // Are we oob?
  27724. if (end > this.length) end = this.length;
  27725. if (target.length - targetStart < end - start) {
  27726. end = target.length - targetStart + start;
  27727. }
  27728. var len = end - start;
  27729. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  27730. // Use built-in when available, missing from IE11
  27731. this.copyWithin(targetStart, start, end);
  27732. } else if (this === target && start < targetStart && targetStart < end) {
  27733. // descending copy from end
  27734. for (var i = len - 1; i >= 0; --i) {
  27735. target[i + targetStart] = this[i + start];
  27736. }
  27737. } else {
  27738. Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
  27739. }
  27740. return len;
  27741. };
  27742. // Usage:
  27743. // buffer.fill(number[, offset[, end]])
  27744. // buffer.fill(buffer[, offset[, end]])
  27745. // buffer.fill(string[, offset[, end]][, encoding])
  27746. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  27747. // Handle string cases:
  27748. if (typeof val === 'string') {
  27749. if (typeof start === 'string') {
  27750. encoding = start;
  27751. start = 0;
  27752. end = this.length;
  27753. } else if (typeof end === 'string') {
  27754. encoding = end;
  27755. end = this.length;
  27756. }
  27757. if (encoding !== undefined && typeof encoding !== 'string') {
  27758. throw new TypeError('encoding must be a string');
  27759. }
  27760. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  27761. throw new TypeError('Unknown encoding: ' + encoding);
  27762. }
  27763. if (val.length === 1) {
  27764. var code = val.charCodeAt(0);
  27765. if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
  27766. // Fast path: If `val` fits into a single byte, use that numeric value.
  27767. val = code;
  27768. }
  27769. }
  27770. } else if (typeof val === 'number') {
  27771. val = val & 255;
  27772. }
  27773. // Invalid ranges are not set to a default, so can range check early.
  27774. if (start < 0 || this.length < start || this.length < end) {
  27775. throw new RangeError('Out of range index');
  27776. }
  27777. if (end <= start) {
  27778. return this;
  27779. }
  27780. start = start >>> 0;
  27781. end = end === undefined ? this.length : end >>> 0;
  27782. if (!val) val = 0;
  27783. var i;
  27784. if (typeof val === 'number') {
  27785. for (i = start; i < end; ++i) {
  27786. this[i] = val;
  27787. }
  27788. } else {
  27789. var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
  27790. var len = bytes.length;
  27791. if (len === 0) {
  27792. throw new TypeError('The value "' + val + '" is invalid for argument "value"');
  27793. }
  27794. for (i = 0; i < end - start; ++i) {
  27795. this[i + start] = bytes[i % len];
  27796. }
  27797. }
  27798. return this;
  27799. };
  27800. // HELPER FUNCTIONS
  27801. // ================
  27802. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  27803. function base64clean(str) {
  27804. // Node takes equal signs as end of the Base64 encoding
  27805. str = str.split('=')[0];
  27806. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  27807. str = str.trim().replace(INVALID_BASE64_RE, '');
  27808. // Node converts strings with length < 2 to ''
  27809. if (str.length < 2) return '';
  27810. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  27811. while (str.length % 4 !== 0) {
  27812. str = str + '=';
  27813. }
  27814. return str;
  27815. }
  27816. function toHex(n) {
  27817. if (n < 16) return '0' + n.toString(16);
  27818. return n.toString(16);
  27819. }
  27820. function utf8ToBytes(string, units) {
  27821. units = units || Infinity;
  27822. var codePoint;
  27823. var length = string.length;
  27824. var leadSurrogate = null;
  27825. var bytes = [];
  27826. for (var i = 0; i < length; ++i) {
  27827. codePoint = string.charCodeAt(i);
  27828. // is surrogate component
  27829. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  27830. // last char was a lead
  27831. if (!leadSurrogate) {
  27832. // no lead yet
  27833. if (codePoint > 0xDBFF) {
  27834. // unexpected trail
  27835. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  27836. continue;
  27837. } else if (i + 1 === length) {
  27838. // unpaired lead
  27839. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  27840. continue;
  27841. }
  27842. // valid lead
  27843. leadSurrogate = codePoint;
  27844. continue;
  27845. }
  27846. // 2 leads in a row
  27847. if (codePoint < 0xDC00) {
  27848. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  27849. leadSurrogate = codePoint;
  27850. continue;
  27851. }
  27852. // valid surrogate pair
  27853. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  27854. } else if (leadSurrogate) {
  27855. // valid bmp char, but last char was a lead
  27856. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  27857. }
  27858. leadSurrogate = null;
  27859. // encode utf8
  27860. if (codePoint < 0x80) {
  27861. if ((units -= 1) < 0) break;
  27862. bytes.push(codePoint);
  27863. } else if (codePoint < 0x800) {
  27864. if ((units -= 2) < 0) break;
  27865. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  27866. } else if (codePoint < 0x10000) {
  27867. if ((units -= 3) < 0) break;
  27868. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  27869. } else if (codePoint < 0x110000) {
  27870. if ((units -= 4) < 0) break;
  27871. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  27872. } else {
  27873. throw new Error('Invalid code point');
  27874. }
  27875. }
  27876. return bytes;
  27877. }
  27878. function asciiToBytes(str) {
  27879. var byteArray = [];
  27880. for (var i = 0; i < str.length; ++i) {
  27881. // Node's code seems to be doing this and not & 0x7F..
  27882. byteArray.push(str.charCodeAt(i) & 0xFF);
  27883. }
  27884. return byteArray;
  27885. }
  27886. function utf16leToBytes(str, units) {
  27887. var c, hi, lo;
  27888. var byteArray = [];
  27889. for (var i = 0; i < str.length; ++i) {
  27890. if ((units -= 2) < 0) break;
  27891. c = str.charCodeAt(i);
  27892. hi = c >> 8;
  27893. lo = c % 256;
  27894. byteArray.push(lo);
  27895. byteArray.push(hi);
  27896. }
  27897. return byteArray;
  27898. }
  27899. function base64ToBytes(str) {
  27900. return base64.toByteArray(base64clean(str));
  27901. }
  27902. function blitBuffer(src, dst, offset, length) {
  27903. for (var i = 0; i < length; ++i) {
  27904. if (i + offset >= dst.length || i >= src.length) break;
  27905. dst[i + offset] = src[i];
  27906. }
  27907. return i;
  27908. }
  27909. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  27910. // the `instanceof` check but they should be treated as of that type.
  27911. // See: https://github.com/feross/buffer/issues/166
  27912. function isInstance(obj, type) {
  27913. return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
  27914. }
  27915. function numberIsNaN(obj) {
  27916. // For IE11 support
  27917. return obj !== obj; // eslint-disable-line no-self-compare
  27918. }
  27919. }).call(this)}).call(this,require("buffer").Buffer)
  27920. },{"base64-js":185,"buffer":220,"ieee754":439}],221:[function(require,module,exports){
  27921. "use strict";
  27922. var Buffer = require('safe-buffer').Buffer;
  27923. var Transform = require('stream').Transform;
  27924. var StringDecoder = require('string_decoder').StringDecoder;
  27925. var inherits = require('inherits');
  27926. function CipherBase(hashMode) {
  27927. Transform.call(this);
  27928. this.hashMode = typeof hashMode === 'string';
  27929. if (this.hashMode) {
  27930. this[hashMode] = this._finalOrDigest;
  27931. } else {
  27932. this.final = this._finalOrDigest;
  27933. }
  27934. if (this._final) {
  27935. this.__final = this._final;
  27936. this._final = null;
  27937. }
  27938. this._decoder = null;
  27939. this._encoding = null;
  27940. }
  27941. inherits(CipherBase, Transform);
  27942. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  27943. if (typeof data === 'string') {
  27944. data = Buffer.from(data, inputEnc);
  27945. }
  27946. var outData = this._update(data);
  27947. if (this.hashMode) return this;
  27948. if (outputEnc) {
  27949. outData = this._toString(outData, outputEnc);
  27950. }
  27951. return outData;
  27952. };
  27953. CipherBase.prototype.setAutoPadding = function () {};
  27954. CipherBase.prototype.getAuthTag = function () {
  27955. throw new Error('trying to get auth tag in unsupported state');
  27956. };
  27957. CipherBase.prototype.setAuthTag = function () {
  27958. throw new Error('trying to set auth tag in unsupported state');
  27959. };
  27960. CipherBase.prototype.setAAD = function () {
  27961. throw new Error('trying to set aad in unsupported state');
  27962. };
  27963. CipherBase.prototype._transform = function (data, _, next) {
  27964. var err;
  27965. try {
  27966. if (this.hashMode) {
  27967. this._update(data);
  27968. } else {
  27969. this.push(this._update(data));
  27970. }
  27971. } catch (e) {
  27972. err = e;
  27973. } finally {
  27974. next(err);
  27975. }
  27976. };
  27977. CipherBase.prototype._flush = function (done) {
  27978. var err;
  27979. try {
  27980. this.push(this.__final());
  27981. } catch (e) {
  27982. err = e;
  27983. }
  27984. done(err);
  27985. };
  27986. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  27987. var outData = this.__final() || Buffer.alloc(0);
  27988. if (outputEnc) {
  27989. outData = this._toString(outData, outputEnc, true);
  27990. }
  27991. return outData;
  27992. };
  27993. CipherBase.prototype._toString = function (value, enc, fin) {
  27994. if (!this._decoder) {
  27995. this._decoder = new StringDecoder(enc);
  27996. this._encoding = enc;
  27997. }
  27998. if (this._encoding !== enc) throw new Error('can\'t switch encodings');
  27999. var out = this._decoder.write(value);
  28000. if (fin) {
  28001. out += this._decoder.end();
  28002. }
  28003. return out;
  28004. };
  28005. module.exports = CipherBase;
  28006. },{"inherits":440,"safe-buffer":494,"stream":505,"string_decoder":218}],222:[function(require,module,exports){
  28007. 'use strict';
  28008. var isCallable = require('../internals/is-callable');
  28009. var tryToString = require('../internals/try-to-string');
  28010. var $TypeError = TypeError;
  28011. // `Assert: IsCallable(argument) is true`
  28012. module.exports = function (argument) {
  28013. if (isCallable(argument)) return argument;
  28014. throw new $TypeError(tryToString(argument) + ' is not a function');
  28015. };
  28016. },{"../internals/is-callable":285,"../internals/try-to-string":349}],223:[function(require,module,exports){
  28017. 'use strict';
  28018. var isConstructor = require('../internals/is-constructor');
  28019. var tryToString = require('../internals/try-to-string');
  28020. var $TypeError = TypeError;
  28021. // `Assert: IsConstructor(argument) is true`
  28022. module.exports = function (argument) {
  28023. if (isConstructor(argument)) return argument;
  28024. throw new $TypeError(tryToString(argument) + ' is not a constructor');
  28025. };
  28026. },{"../internals/is-constructor":286,"../internals/try-to-string":349}],224:[function(require,module,exports){
  28027. 'use strict';
  28028. var isCallable = require('../internals/is-callable');
  28029. var $String = String;
  28030. var $TypeError = TypeError;
  28031. module.exports = function (argument) {
  28032. if (typeof argument == 'object' || isCallable(argument)) return argument;
  28033. throw new $TypeError("Can't set " + $String(argument) + ' as a prototype');
  28034. };
  28035. },{"../internals/is-callable":285}],225:[function(require,module,exports){
  28036. 'use strict';
  28037. var wellKnownSymbol = require('../internals/well-known-symbol');
  28038. var create = require('../internals/object-create');
  28039. var defineProperty = require('../internals/object-define-property').f;
  28040. var UNSCOPABLES = wellKnownSymbol('unscopables');
  28041. var ArrayPrototype = Array.prototype;
  28042. // Array.prototype[@@unscopables]
  28043. // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
  28044. if (ArrayPrototype[UNSCOPABLES] === undefined) {
  28045. defineProperty(ArrayPrototype, UNSCOPABLES, {
  28046. configurable: true,
  28047. value: create(null)
  28048. });
  28049. }
  28050. // add a key to Array.prototype[@@unscopables]
  28051. module.exports = function (key) {
  28052. ArrayPrototype[UNSCOPABLES][key] = true;
  28053. };
  28054. },{"../internals/object-create":306,"../internals/object-define-property":308,"../internals/well-known-symbol":357}],226:[function(require,module,exports){
  28055. 'use strict';
  28056. var isPrototypeOf = require('../internals/object-is-prototype-of');
  28057. var $TypeError = TypeError;
  28058. module.exports = function (it, Prototype) {
  28059. if (isPrototypeOf(Prototype, it)) return it;
  28060. throw new $TypeError('Incorrect invocation');
  28061. };
  28062. },{"../internals/object-is-prototype-of":314}],227:[function(require,module,exports){
  28063. 'use strict';
  28064. var isObject = require('../internals/is-object');
  28065. var $String = String;
  28066. var $TypeError = TypeError;
  28067. // `Assert: Type(argument) is Object`
  28068. module.exports = function (argument) {
  28069. if (isObject(argument)) return argument;
  28070. throw new $TypeError($String(argument) + ' is not an object');
  28071. };
  28072. },{"../internals/is-object":289}],228:[function(require,module,exports){
  28073. 'use strict';
  28074. var toIndexedObject = require('../internals/to-indexed-object');
  28075. var toAbsoluteIndex = require('../internals/to-absolute-index');
  28076. var lengthOfArrayLike = require('../internals/length-of-array-like');
  28077. // `Array.prototype.{ indexOf, includes }` methods implementation
  28078. var createMethod = function (IS_INCLUDES) {
  28079. return function ($this, el, fromIndex) {
  28080. var O = toIndexedObject($this);
  28081. var length = lengthOfArrayLike(O);
  28082. var index = toAbsoluteIndex(fromIndex, length);
  28083. var value;
  28084. // Array#includes uses SameValueZero equality algorithm
  28085. // eslint-disable-next-line no-self-compare -- NaN check
  28086. if (IS_INCLUDES && el !== el) while (length > index) {
  28087. value = O[index++];
  28088. // eslint-disable-next-line no-self-compare -- NaN check
  28089. if (value !== value) return true;
  28090. // Array#indexOf ignores holes, Array#includes - not
  28091. } else for (;length > index; index++) {
  28092. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  28093. } return !IS_INCLUDES && -1;
  28094. };
  28095. };
  28096. module.exports = {
  28097. // `Array.prototype.includes` method
  28098. // https://tc39.es/ecma262/#sec-array.prototype.includes
  28099. includes: createMethod(true),
  28100. // `Array.prototype.indexOf` method
  28101. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  28102. indexOf: createMethod(false)
  28103. };
  28104. },{"../internals/length-of-array-like":299,"../internals/to-absolute-index":340,"../internals/to-indexed-object":341}],229:[function(require,module,exports){
  28105. 'use strict';
  28106. var bind = require('../internals/function-bind-context');
  28107. var uncurryThis = require('../internals/function-uncurry-this');
  28108. var IndexedObject = require('../internals/indexed-object');
  28109. var toObject = require('../internals/to-object');
  28110. var lengthOfArrayLike = require('../internals/length-of-array-like');
  28111. var arraySpeciesCreate = require('../internals/array-species-create');
  28112. var push = uncurryThis([].push);
  28113. // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterReject }` methods implementation
  28114. var createMethod = function (TYPE) {
  28115. var IS_MAP = TYPE === 1;
  28116. var IS_FILTER = TYPE === 2;
  28117. var IS_SOME = TYPE === 3;
  28118. var IS_EVERY = TYPE === 4;
  28119. var IS_FIND_INDEX = TYPE === 6;
  28120. var IS_FILTER_REJECT = TYPE === 7;
  28121. var NO_HOLES = TYPE === 5 || IS_FIND_INDEX;
  28122. return function ($this, callbackfn, that, specificCreate) {
  28123. var O = toObject($this);
  28124. var self = IndexedObject(O);
  28125. var boundFunction = bind(callbackfn, that);
  28126. var length = lengthOfArrayLike(self);
  28127. var index = 0;
  28128. var create = specificCreate || arraySpeciesCreate;
  28129. var target = IS_MAP ? create($this, length) : IS_FILTER || IS_FILTER_REJECT ? create($this, 0) : undefined;
  28130. var value, result;
  28131. for (;length > index; index++) if (NO_HOLES || index in self) {
  28132. value = self[index];
  28133. result = boundFunction(value, index, O);
  28134. if (TYPE) {
  28135. if (IS_MAP) target[index] = result; // map
  28136. else if (result) switch (TYPE) {
  28137. case 3: return true; // some
  28138. case 5: return value; // find
  28139. case 6: return index; // findIndex
  28140. case 2: push(target, value); // filter
  28141. } else switch (TYPE) {
  28142. case 4: return false; // every
  28143. case 7: push(target, value); // filterReject
  28144. }
  28145. }
  28146. }
  28147. return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
  28148. };
  28149. };
  28150. module.exports = {
  28151. // `Array.prototype.forEach` method
  28152. // https://tc39.es/ecma262/#sec-array.prototype.foreach
  28153. forEach: createMethod(0),
  28154. // `Array.prototype.map` method
  28155. // https://tc39.es/ecma262/#sec-array.prototype.map
  28156. map: createMethod(1),
  28157. // `Array.prototype.filter` method
  28158. // https://tc39.es/ecma262/#sec-array.prototype.filter
  28159. filter: createMethod(2),
  28160. // `Array.prototype.some` method
  28161. // https://tc39.es/ecma262/#sec-array.prototype.some
  28162. some: createMethod(3),
  28163. // `Array.prototype.every` method
  28164. // https://tc39.es/ecma262/#sec-array.prototype.every
  28165. every: createMethod(4),
  28166. // `Array.prototype.find` method
  28167. // https://tc39.es/ecma262/#sec-array.prototype.find
  28168. find: createMethod(5),
  28169. // `Array.prototype.findIndex` method
  28170. // https://tc39.es/ecma262/#sec-array.prototype.findIndex
  28171. findIndex: createMethod(6),
  28172. // `Array.prototype.filterReject` method
  28173. // https://github.com/tc39/proposal-array-filtering
  28174. filterReject: createMethod(7)
  28175. };
  28176. },{"../internals/array-species-create":233,"../internals/function-bind-context":262,"../internals/function-uncurry-this":268,"../internals/indexed-object":280,"../internals/length-of-array-like":299,"../internals/to-object":344}],230:[function(require,module,exports){
  28177. 'use strict';
  28178. var toAbsoluteIndex = require('../internals/to-absolute-index');
  28179. var lengthOfArrayLike = require('../internals/length-of-array-like');
  28180. var createProperty = require('../internals/create-property');
  28181. var $Array = Array;
  28182. var max = Math.max;
  28183. module.exports = function (O, start, end) {
  28184. var length = lengthOfArrayLike(O);
  28185. var k = toAbsoluteIndex(start, length);
  28186. var fin = toAbsoluteIndex(end === undefined ? length : end, length);
  28187. var result = $Array(max(fin - k, 0));
  28188. var n = 0;
  28189. for (; k < fin; k++, n++) createProperty(result, n, O[k]);
  28190. result.length = n;
  28191. return result;
  28192. };
  28193. },{"../internals/create-property":243,"../internals/length-of-array-like":299,"../internals/to-absolute-index":340}],231:[function(require,module,exports){
  28194. 'use strict';
  28195. var uncurryThis = require('../internals/function-uncurry-this');
  28196. module.exports = uncurryThis([].slice);
  28197. },{"../internals/function-uncurry-this":268}],232:[function(require,module,exports){
  28198. 'use strict';
  28199. var isArray = require('../internals/is-array');
  28200. var isConstructor = require('../internals/is-constructor');
  28201. var isObject = require('../internals/is-object');
  28202. var wellKnownSymbol = require('../internals/well-known-symbol');
  28203. var SPECIES = wellKnownSymbol('species');
  28204. var $Array = Array;
  28205. // a part of `ArraySpeciesCreate` abstract operation
  28206. // https://tc39.es/ecma262/#sec-arrayspeciescreate
  28207. module.exports = function (originalArray) {
  28208. var C;
  28209. if (isArray(originalArray)) {
  28210. C = originalArray.constructor;
  28211. // cross-realm fallback
  28212. if (isConstructor(C) && (C === $Array || isArray(C.prototype))) C = undefined;
  28213. else if (isObject(C)) {
  28214. C = C[SPECIES];
  28215. if (C === null) C = undefined;
  28216. }
  28217. } return C === undefined ? $Array : C;
  28218. };
  28219. },{"../internals/is-array":284,"../internals/is-constructor":286,"../internals/is-object":289,"../internals/well-known-symbol":357}],233:[function(require,module,exports){
  28220. 'use strict';
  28221. var arraySpeciesConstructor = require('../internals/array-species-constructor');
  28222. // `ArraySpeciesCreate` abstract operation
  28223. // https://tc39.es/ecma262/#sec-arrayspeciescreate
  28224. module.exports = function (originalArray, length) {
  28225. return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
  28226. };
  28227. },{"../internals/array-species-constructor":232}],234:[function(require,module,exports){
  28228. 'use strict';
  28229. var wellKnownSymbol = require('../internals/well-known-symbol');
  28230. var ITERATOR = wellKnownSymbol('iterator');
  28231. var SAFE_CLOSING = false;
  28232. try {
  28233. var called = 0;
  28234. var iteratorWithReturn = {
  28235. next: function () {
  28236. return { done: !!called++ };
  28237. },
  28238. 'return': function () {
  28239. SAFE_CLOSING = true;
  28240. }
  28241. };
  28242. iteratorWithReturn[ITERATOR] = function () {
  28243. return this;
  28244. };
  28245. // eslint-disable-next-line es/no-array-from, no-throw-literal -- required for testing
  28246. Array.from(iteratorWithReturn, function () { throw 2; });
  28247. } catch (error) { /* empty */ }
  28248. module.exports = function (exec, SKIP_CLOSING) {
  28249. try {
  28250. if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
  28251. } catch (error) { return false; } // workaround of old WebKit + `eval` bug
  28252. var ITERATION_SUPPORT = false;
  28253. try {
  28254. var object = {};
  28255. object[ITERATOR] = function () {
  28256. return {
  28257. next: function () {
  28258. return { done: ITERATION_SUPPORT = true };
  28259. }
  28260. };
  28261. };
  28262. exec(object);
  28263. } catch (error) { /* empty */ }
  28264. return ITERATION_SUPPORT;
  28265. };
  28266. },{"../internals/well-known-symbol":357}],235:[function(require,module,exports){
  28267. 'use strict';
  28268. var uncurryThis = require('../internals/function-uncurry-this');
  28269. var toString = uncurryThis({}.toString);
  28270. var stringSlice = uncurryThis(''.slice);
  28271. module.exports = function (it) {
  28272. return stringSlice(toString(it), 8, -1);
  28273. };
  28274. },{"../internals/function-uncurry-this":268}],236:[function(require,module,exports){
  28275. 'use strict';
  28276. var TO_STRING_TAG_SUPPORT = require('../internals/to-string-tag-support');
  28277. var isCallable = require('../internals/is-callable');
  28278. var classofRaw = require('../internals/classof-raw');
  28279. var wellKnownSymbol = require('../internals/well-known-symbol');
  28280. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  28281. var $Object = Object;
  28282. // ES3 wrong here
  28283. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) === 'Arguments';
  28284. // fallback for IE11 Script Access Denied error
  28285. var tryGet = function (it, key) {
  28286. try {
  28287. return it[key];
  28288. } catch (error) { /* empty */ }
  28289. };
  28290. // getting tag from ES6+ `Object.prototype.toString`
  28291. module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
  28292. var O, tag, result;
  28293. return it === undefined ? 'Undefined' : it === null ? 'Null'
  28294. // @@toStringTag case
  28295. : typeof (tag = tryGet(O = $Object(it), TO_STRING_TAG)) == 'string' ? tag
  28296. // builtinTag case
  28297. : CORRECT_ARGUMENTS ? classofRaw(O)
  28298. // ES3 arguments fallback
  28299. : (result = classofRaw(O)) === 'Object' && isCallable(O.callee) ? 'Arguments' : result;
  28300. };
  28301. },{"../internals/classof-raw":235,"../internals/is-callable":285,"../internals/to-string-tag-support":347,"../internals/well-known-symbol":357}],237:[function(require,module,exports){
  28302. 'use strict';
  28303. var hasOwn = require('../internals/has-own-property');
  28304. var ownKeys = require('../internals/own-keys');
  28305. var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
  28306. var definePropertyModule = require('../internals/object-define-property');
  28307. module.exports = function (target, source, exceptions) {
  28308. var keys = ownKeys(source);
  28309. var defineProperty = definePropertyModule.f;
  28310. var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  28311. for (var i = 0; i < keys.length; i++) {
  28312. var key = keys[i];
  28313. if (!hasOwn(target, key) && !(exceptions && hasOwn(exceptions, key))) {
  28314. defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  28315. }
  28316. }
  28317. };
  28318. },{"../internals/has-own-property":275,"../internals/object-define-property":308,"../internals/object-get-own-property-descriptor":309,"../internals/own-keys":321}],238:[function(require,module,exports){
  28319. 'use strict';
  28320. var wellKnownSymbol = require('../internals/well-known-symbol');
  28321. var MATCH = wellKnownSymbol('match');
  28322. module.exports = function (METHOD_NAME) {
  28323. var regexp = /./;
  28324. try {
  28325. '/./'[METHOD_NAME](regexp);
  28326. } catch (error1) {
  28327. try {
  28328. regexp[MATCH] = false;
  28329. return '/./'[METHOD_NAME](regexp);
  28330. } catch (error2) { /* empty */ }
  28331. } return false;
  28332. };
  28333. },{"../internals/well-known-symbol":357}],239:[function(require,module,exports){
  28334. 'use strict';
  28335. var fails = require('../internals/fails');
  28336. module.exports = !fails(function () {
  28337. function F() { /* empty */ }
  28338. F.prototype.constructor = null;
  28339. // eslint-disable-next-line es/no-object-getprototypeof -- required for testing
  28340. return Object.getPrototypeOf(new F()) !== F.prototype;
  28341. });
  28342. },{"../internals/fails":260}],240:[function(require,module,exports){
  28343. 'use strict';
  28344. // `CreateIterResultObject` abstract operation
  28345. // https://tc39.es/ecma262/#sec-createiterresultobject
  28346. module.exports = function (value, done) {
  28347. return { value: value, done: done };
  28348. };
  28349. },{}],241:[function(require,module,exports){
  28350. 'use strict';
  28351. var DESCRIPTORS = require('../internals/descriptors');
  28352. var definePropertyModule = require('../internals/object-define-property');
  28353. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  28354. module.exports = DESCRIPTORS ? function (object, key, value) {
  28355. return definePropertyModule.f(object, key, createPropertyDescriptor(1, value));
  28356. } : function (object, key, value) {
  28357. object[key] = value;
  28358. return object;
  28359. };
  28360. },{"../internals/create-property-descriptor":242,"../internals/descriptors":247,"../internals/object-define-property":308}],242:[function(require,module,exports){
  28361. 'use strict';
  28362. module.exports = function (bitmap, value) {
  28363. return {
  28364. enumerable: !(bitmap & 1),
  28365. configurable: !(bitmap & 2),
  28366. writable: !(bitmap & 4),
  28367. value: value
  28368. };
  28369. };
  28370. },{}],243:[function(require,module,exports){
  28371. 'use strict';
  28372. var toPropertyKey = require('../internals/to-property-key');
  28373. var definePropertyModule = require('../internals/object-define-property');
  28374. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  28375. module.exports = function (object, key, value) {
  28376. var propertyKey = toPropertyKey(key);
  28377. if (propertyKey in object) definePropertyModule.f(object, propertyKey, createPropertyDescriptor(0, value));
  28378. else object[propertyKey] = value;
  28379. };
  28380. },{"../internals/create-property-descriptor":242,"../internals/object-define-property":308,"../internals/to-property-key":346}],244:[function(require,module,exports){
  28381. 'use strict';
  28382. var makeBuiltIn = require('../internals/make-built-in');
  28383. var defineProperty = require('../internals/object-define-property');
  28384. module.exports = function (target, name, descriptor) {
  28385. if (descriptor.get) makeBuiltIn(descriptor.get, name, { getter: true });
  28386. if (descriptor.set) makeBuiltIn(descriptor.set, name, { setter: true });
  28387. return defineProperty.f(target, name, descriptor);
  28388. };
  28389. },{"../internals/make-built-in":300,"../internals/object-define-property":308}],245:[function(require,module,exports){
  28390. 'use strict';
  28391. var isCallable = require('../internals/is-callable');
  28392. var definePropertyModule = require('../internals/object-define-property');
  28393. var makeBuiltIn = require('../internals/make-built-in');
  28394. var defineGlobalProperty = require('../internals/define-global-property');
  28395. module.exports = function (O, key, value, options) {
  28396. if (!options) options = {};
  28397. var simple = options.enumerable;
  28398. var name = options.name !== undefined ? options.name : key;
  28399. if (isCallable(value)) makeBuiltIn(value, name, options);
  28400. if (options.global) {
  28401. if (simple) O[key] = value;
  28402. else defineGlobalProperty(key, value);
  28403. } else {
  28404. try {
  28405. if (!options.unsafe) delete O[key];
  28406. else if (O[key]) simple = true;
  28407. } catch (error) { /* empty */ }
  28408. if (simple) O[key] = value;
  28409. else definePropertyModule.f(O, key, {
  28410. value: value,
  28411. enumerable: false,
  28412. configurable: !options.nonConfigurable,
  28413. writable: !options.nonWritable
  28414. });
  28415. } return O;
  28416. };
  28417. },{"../internals/define-global-property":246,"../internals/is-callable":285,"../internals/make-built-in":300,"../internals/object-define-property":308}],246:[function(require,module,exports){
  28418. 'use strict';
  28419. var global = require('../internals/global');
  28420. // eslint-disable-next-line es/no-object-defineproperty -- safe
  28421. var defineProperty = Object.defineProperty;
  28422. module.exports = function (key, value) {
  28423. try {
  28424. defineProperty(global, key, { value: value, configurable: true, writable: true });
  28425. } catch (error) {
  28426. global[key] = value;
  28427. } return value;
  28428. };
  28429. },{"../internals/global":274}],247:[function(require,module,exports){
  28430. 'use strict';
  28431. var fails = require('../internals/fails');
  28432. // Detect IE8's incomplete defineProperty implementation
  28433. module.exports = !fails(function () {
  28434. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  28435. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] !== 7;
  28436. });
  28437. },{"../internals/fails":260}],248:[function(require,module,exports){
  28438. 'use strict';
  28439. var documentAll = typeof document == 'object' && document.all;
  28440. // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
  28441. // eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing
  28442. var IS_HTMLDDA = typeof documentAll == 'undefined' && documentAll !== undefined;
  28443. module.exports = {
  28444. all: documentAll,
  28445. IS_HTMLDDA: IS_HTMLDDA
  28446. };
  28447. },{}],249:[function(require,module,exports){
  28448. 'use strict';
  28449. var global = require('../internals/global');
  28450. var isObject = require('../internals/is-object');
  28451. var document = global.document;
  28452. // typeof document.createElement is 'object' in old IE
  28453. var EXISTS = isObject(document) && isObject(document.createElement);
  28454. module.exports = function (it) {
  28455. return EXISTS ? document.createElement(it) : {};
  28456. };
  28457. },{"../internals/global":274,"../internals/is-object":289}],250:[function(require,module,exports){
  28458. 'use strict';
  28459. var IS_DENO = require('../internals/engine-is-deno');
  28460. var IS_NODE = require('../internals/engine-is-node');
  28461. module.exports = !IS_DENO && !IS_NODE
  28462. && typeof window == 'object'
  28463. && typeof document == 'object';
  28464. },{"../internals/engine-is-deno":251,"../internals/engine-is-node":254}],251:[function(require,module,exports){
  28465. 'use strict';
  28466. /* global Deno -- Deno case */
  28467. module.exports = typeof Deno == 'object' && Deno && typeof Deno.version == 'object';
  28468. },{}],252:[function(require,module,exports){
  28469. 'use strict';
  28470. var userAgent = require('../internals/engine-user-agent');
  28471. module.exports = /ipad|iphone|ipod/i.test(userAgent) && typeof Pebble != 'undefined';
  28472. },{"../internals/engine-user-agent":256}],253:[function(require,module,exports){
  28473. 'use strict';
  28474. var userAgent = require('../internals/engine-user-agent');
  28475. // eslint-disable-next-line redos/no-vulnerable -- safe
  28476. module.exports = /(?:ipad|iphone|ipod).*applewebkit/i.test(userAgent);
  28477. },{"../internals/engine-user-agent":256}],254:[function(require,module,exports){
  28478. 'use strict';
  28479. var global = require('../internals/global');
  28480. var classof = require('../internals/classof-raw');
  28481. module.exports = classof(global.process) === 'process';
  28482. },{"../internals/classof-raw":235,"../internals/global":274}],255:[function(require,module,exports){
  28483. 'use strict';
  28484. var userAgent = require('../internals/engine-user-agent');
  28485. module.exports = /web0s(?!.*chrome)/i.test(userAgent);
  28486. },{"../internals/engine-user-agent":256}],256:[function(require,module,exports){
  28487. 'use strict';
  28488. module.exports = typeof navigator != 'undefined' && String(navigator.userAgent) || '';
  28489. },{}],257:[function(require,module,exports){
  28490. 'use strict';
  28491. var global = require('../internals/global');
  28492. var userAgent = require('../internals/engine-user-agent');
  28493. var process = global.process;
  28494. var Deno = global.Deno;
  28495. var versions = process && process.versions || Deno && Deno.version;
  28496. var v8 = versions && versions.v8;
  28497. var match, version;
  28498. if (v8) {
  28499. match = v8.split('.');
  28500. // in old Chrome, versions of V8 isn't V8 = Chrome / 10
  28501. // but their correct versions are not interesting for us
  28502. version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
  28503. }
  28504. // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
  28505. // so check `userAgent` even if `.v8` exists, but 0
  28506. if (!version && userAgent) {
  28507. match = userAgent.match(/Edge\/(\d+)/);
  28508. if (!match || match[1] >= 74) {
  28509. match = userAgent.match(/Chrome\/(\d+)/);
  28510. if (match) version = +match[1];
  28511. }
  28512. }
  28513. module.exports = version;
  28514. },{"../internals/engine-user-agent":256,"../internals/global":274}],258:[function(require,module,exports){
  28515. 'use strict';
  28516. // IE8- don't enum bug keys
  28517. module.exports = [
  28518. 'constructor',
  28519. 'hasOwnProperty',
  28520. 'isPrototypeOf',
  28521. 'propertyIsEnumerable',
  28522. 'toLocaleString',
  28523. 'toString',
  28524. 'valueOf'
  28525. ];
  28526. },{}],259:[function(require,module,exports){
  28527. 'use strict';
  28528. var global = require('../internals/global');
  28529. var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
  28530. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  28531. var defineBuiltIn = require('../internals/define-built-in');
  28532. var defineGlobalProperty = require('../internals/define-global-property');
  28533. var copyConstructorProperties = require('../internals/copy-constructor-properties');
  28534. var isForced = require('../internals/is-forced');
  28535. /*
  28536. options.target - name of the target object
  28537. options.global - target is the global object
  28538. options.stat - export as static methods of target
  28539. options.proto - export as prototype methods of target
  28540. options.real - real prototype method for the `pure` version
  28541. options.forced - export even if the native feature is available
  28542. options.bind - bind methods to the target, required for the `pure` version
  28543. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  28544. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  28545. options.sham - add a flag to not completely full polyfills
  28546. options.enumerable - export as enumerable property
  28547. options.dontCallGetSet - prevent calling a getter on target
  28548. options.name - the .name of the function if it does not match the key
  28549. */
  28550. module.exports = function (options, source) {
  28551. var TARGET = options.target;
  28552. var GLOBAL = options.global;
  28553. var STATIC = options.stat;
  28554. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  28555. if (GLOBAL) {
  28556. target = global;
  28557. } else if (STATIC) {
  28558. target = global[TARGET] || defineGlobalProperty(TARGET, {});
  28559. } else {
  28560. target = (global[TARGET] || {}).prototype;
  28561. }
  28562. if (target) for (key in source) {
  28563. sourceProperty = source[key];
  28564. if (options.dontCallGetSet) {
  28565. descriptor = getOwnPropertyDescriptor(target, key);
  28566. targetProperty = descriptor && descriptor.value;
  28567. } else targetProperty = target[key];
  28568. FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  28569. // contained in target
  28570. if (!FORCED && targetProperty !== undefined) {
  28571. if (typeof sourceProperty == typeof targetProperty) continue;
  28572. copyConstructorProperties(sourceProperty, targetProperty);
  28573. }
  28574. // add a flag to not completely full polyfills
  28575. if (options.sham || (targetProperty && targetProperty.sham)) {
  28576. createNonEnumerableProperty(sourceProperty, 'sham', true);
  28577. }
  28578. defineBuiltIn(target, key, sourceProperty, options);
  28579. }
  28580. };
  28581. },{"../internals/copy-constructor-properties":237,"../internals/create-non-enumerable-property":241,"../internals/define-built-in":245,"../internals/define-global-property":246,"../internals/global":274,"../internals/is-forced":287,"../internals/object-get-own-property-descriptor":309}],260:[function(require,module,exports){
  28582. 'use strict';
  28583. module.exports = function (exec) {
  28584. try {
  28585. return !!exec();
  28586. } catch (error) {
  28587. return true;
  28588. }
  28589. };
  28590. },{}],261:[function(require,module,exports){
  28591. 'use strict';
  28592. var NATIVE_BIND = require('../internals/function-bind-native');
  28593. var FunctionPrototype = Function.prototype;
  28594. var apply = FunctionPrototype.apply;
  28595. var call = FunctionPrototype.call;
  28596. // eslint-disable-next-line es/no-reflect -- safe
  28597. module.exports = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND ? call.bind(apply) : function () {
  28598. return call.apply(apply, arguments);
  28599. });
  28600. },{"../internals/function-bind-native":263}],262:[function(require,module,exports){
  28601. 'use strict';
  28602. var uncurryThis = require('../internals/function-uncurry-this-clause');
  28603. var aCallable = require('../internals/a-callable');
  28604. var NATIVE_BIND = require('../internals/function-bind-native');
  28605. var bind = uncurryThis(uncurryThis.bind);
  28606. // optional / simple context binding
  28607. module.exports = function (fn, that) {
  28608. aCallable(fn);
  28609. return that === undefined ? fn : NATIVE_BIND ? bind(fn, that) : function (/* ...args */) {
  28610. return fn.apply(that, arguments);
  28611. };
  28612. };
  28613. },{"../internals/a-callable":222,"../internals/function-bind-native":263,"../internals/function-uncurry-this-clause":267}],263:[function(require,module,exports){
  28614. 'use strict';
  28615. var fails = require('../internals/fails');
  28616. module.exports = !fails(function () {
  28617. // eslint-disable-next-line es/no-function-prototype-bind -- safe
  28618. var test = (function () { /* empty */ }).bind();
  28619. // eslint-disable-next-line no-prototype-builtins -- safe
  28620. return typeof test != 'function' || test.hasOwnProperty('prototype');
  28621. });
  28622. },{"../internals/fails":260}],264:[function(require,module,exports){
  28623. 'use strict';
  28624. var NATIVE_BIND = require('../internals/function-bind-native');
  28625. var call = Function.prototype.call;
  28626. module.exports = NATIVE_BIND ? call.bind(call) : function () {
  28627. return call.apply(call, arguments);
  28628. };
  28629. },{"../internals/function-bind-native":263}],265:[function(require,module,exports){
  28630. 'use strict';
  28631. var DESCRIPTORS = require('../internals/descriptors');
  28632. var hasOwn = require('../internals/has-own-property');
  28633. var FunctionPrototype = Function.prototype;
  28634. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  28635. var getDescriptor = DESCRIPTORS && Object.getOwnPropertyDescriptor;
  28636. var EXISTS = hasOwn(FunctionPrototype, 'name');
  28637. // additional protection from minified / mangled / dropped function names
  28638. var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
  28639. var CONFIGURABLE = EXISTS && (!DESCRIPTORS || (DESCRIPTORS && getDescriptor(FunctionPrototype, 'name').configurable));
  28640. module.exports = {
  28641. EXISTS: EXISTS,
  28642. PROPER: PROPER,
  28643. CONFIGURABLE: CONFIGURABLE
  28644. };
  28645. },{"../internals/descriptors":247,"../internals/has-own-property":275}],266:[function(require,module,exports){
  28646. 'use strict';
  28647. var uncurryThis = require('../internals/function-uncurry-this');
  28648. var aCallable = require('../internals/a-callable');
  28649. module.exports = function (object, key, method) {
  28650. try {
  28651. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  28652. return uncurryThis(aCallable(Object.getOwnPropertyDescriptor(object, key)[method]));
  28653. } catch (error) { /* empty */ }
  28654. };
  28655. },{"../internals/a-callable":222,"../internals/function-uncurry-this":268}],267:[function(require,module,exports){
  28656. 'use strict';
  28657. var classofRaw = require('../internals/classof-raw');
  28658. var uncurryThis = require('../internals/function-uncurry-this');
  28659. module.exports = function (fn) {
  28660. // Nashorn bug:
  28661. // https://github.com/zloirock/core-js/issues/1128
  28662. // https://github.com/zloirock/core-js/issues/1130
  28663. if (classofRaw(fn) === 'Function') return uncurryThis(fn);
  28664. };
  28665. },{"../internals/classof-raw":235,"../internals/function-uncurry-this":268}],268:[function(require,module,exports){
  28666. 'use strict';
  28667. var NATIVE_BIND = require('../internals/function-bind-native');
  28668. var FunctionPrototype = Function.prototype;
  28669. var call = FunctionPrototype.call;
  28670. var uncurryThisWithBind = NATIVE_BIND && FunctionPrototype.bind.bind(call, call);
  28671. module.exports = NATIVE_BIND ? uncurryThisWithBind : function (fn) {
  28672. return function () {
  28673. return call.apply(fn, arguments);
  28674. };
  28675. };
  28676. },{"../internals/function-bind-native":263}],269:[function(require,module,exports){
  28677. 'use strict';
  28678. var global = require('../internals/global');
  28679. var isCallable = require('../internals/is-callable');
  28680. var aFunction = function (argument) {
  28681. return isCallable(argument) ? argument : undefined;
  28682. };
  28683. module.exports = function (namespace, method) {
  28684. return arguments.length < 2 ? aFunction(global[namespace]) : global[namespace] && global[namespace][method];
  28685. };
  28686. },{"../internals/global":274,"../internals/is-callable":285}],270:[function(require,module,exports){
  28687. 'use strict';
  28688. var classof = require('../internals/classof');
  28689. var getMethod = require('../internals/get-method');
  28690. var isNullOrUndefined = require('../internals/is-null-or-undefined');
  28691. var Iterators = require('../internals/iterators');
  28692. var wellKnownSymbol = require('../internals/well-known-symbol');
  28693. var ITERATOR = wellKnownSymbol('iterator');
  28694. module.exports = function (it) {
  28695. if (!isNullOrUndefined(it)) return getMethod(it, ITERATOR)
  28696. || getMethod(it, '@@iterator')
  28697. || Iterators[classof(it)];
  28698. };
  28699. },{"../internals/classof":236,"../internals/get-method":273,"../internals/is-null-or-undefined":288,"../internals/iterators":298,"../internals/well-known-symbol":357}],271:[function(require,module,exports){
  28700. 'use strict';
  28701. var call = require('../internals/function-call');
  28702. var aCallable = require('../internals/a-callable');
  28703. var anObject = require('../internals/an-object');
  28704. var tryToString = require('../internals/try-to-string');
  28705. var getIteratorMethod = require('../internals/get-iterator-method');
  28706. var $TypeError = TypeError;
  28707. module.exports = function (argument, usingIterator) {
  28708. var iteratorMethod = arguments.length < 2 ? getIteratorMethod(argument) : usingIterator;
  28709. if (aCallable(iteratorMethod)) return anObject(call(iteratorMethod, argument));
  28710. throw new $TypeError(tryToString(argument) + ' is not iterable');
  28711. };
  28712. },{"../internals/a-callable":222,"../internals/an-object":227,"../internals/function-call":264,"../internals/get-iterator-method":270,"../internals/try-to-string":349}],272:[function(require,module,exports){
  28713. 'use strict';
  28714. var uncurryThis = require('../internals/function-uncurry-this');
  28715. var isArray = require('../internals/is-array');
  28716. var isCallable = require('../internals/is-callable');
  28717. var classof = require('../internals/classof-raw');
  28718. var toString = require('../internals/to-string');
  28719. var push = uncurryThis([].push);
  28720. module.exports = function (replacer) {
  28721. if (isCallable(replacer)) return replacer;
  28722. if (!isArray(replacer)) return;
  28723. var rawLength = replacer.length;
  28724. var keys = [];
  28725. for (var i = 0; i < rawLength; i++) {
  28726. var element = replacer[i];
  28727. if (typeof element == 'string') push(keys, element);
  28728. else if (typeof element == 'number' || classof(element) === 'Number' || classof(element) === 'String') push(keys, toString(element));
  28729. }
  28730. var keysLength = keys.length;
  28731. var root = true;
  28732. return function (key, value) {
  28733. if (root) {
  28734. root = false;
  28735. return value;
  28736. }
  28737. if (isArray(this)) return value;
  28738. for (var j = 0; j < keysLength; j++) if (keys[j] === key) return value;
  28739. };
  28740. };
  28741. },{"../internals/classof-raw":235,"../internals/function-uncurry-this":268,"../internals/is-array":284,"../internals/is-callable":285,"../internals/to-string":348}],273:[function(require,module,exports){
  28742. 'use strict';
  28743. var aCallable = require('../internals/a-callable');
  28744. var isNullOrUndefined = require('../internals/is-null-or-undefined');
  28745. // `GetMethod` abstract operation
  28746. // https://tc39.es/ecma262/#sec-getmethod
  28747. module.exports = function (V, P) {
  28748. var func = V[P];
  28749. return isNullOrUndefined(func) ? undefined : aCallable(func);
  28750. };
  28751. },{"../internals/a-callable":222,"../internals/is-null-or-undefined":288}],274:[function(require,module,exports){
  28752. (function (global){(function (){
  28753. 'use strict';
  28754. var check = function (it) {
  28755. return it && it.Math === Math && it;
  28756. };
  28757. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  28758. module.exports =
  28759. // eslint-disable-next-line es/no-global-this -- safe
  28760. check(typeof globalThis == 'object' && globalThis) ||
  28761. check(typeof window == 'object' && window) ||
  28762. // eslint-disable-next-line no-restricted-globals -- safe
  28763. check(typeof self == 'object' && self) ||
  28764. check(typeof global == 'object' && global) ||
  28765. // eslint-disable-next-line no-new-func -- fallback
  28766. (function () { return this; })() || this || Function('return this')();
  28767. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  28768. },{}],275:[function(require,module,exports){
  28769. 'use strict';
  28770. var uncurryThis = require('../internals/function-uncurry-this');
  28771. var toObject = require('../internals/to-object');
  28772. var hasOwnProperty = uncurryThis({}.hasOwnProperty);
  28773. // `HasOwnProperty` abstract operation
  28774. // https://tc39.es/ecma262/#sec-hasownproperty
  28775. // eslint-disable-next-line es/no-object-hasown -- safe
  28776. module.exports = Object.hasOwn || function hasOwn(it, key) {
  28777. return hasOwnProperty(toObject(it), key);
  28778. };
  28779. },{"../internals/function-uncurry-this":268,"../internals/to-object":344}],276:[function(require,module,exports){
  28780. 'use strict';
  28781. module.exports = {};
  28782. },{}],277:[function(require,module,exports){
  28783. 'use strict';
  28784. module.exports = function (a, b) {
  28785. try {
  28786. // eslint-disable-next-line no-console -- safe
  28787. arguments.length === 1 ? console.error(a) : console.error(a, b);
  28788. } catch (error) { /* empty */ }
  28789. };
  28790. },{}],278:[function(require,module,exports){
  28791. 'use strict';
  28792. var getBuiltIn = require('../internals/get-built-in');
  28793. module.exports = getBuiltIn('document', 'documentElement');
  28794. },{"../internals/get-built-in":269}],279:[function(require,module,exports){
  28795. 'use strict';
  28796. var DESCRIPTORS = require('../internals/descriptors');
  28797. var fails = require('../internals/fails');
  28798. var createElement = require('../internals/document-create-element');
  28799. // Thanks to IE8 for its funny defineProperty
  28800. module.exports = !DESCRIPTORS && !fails(function () {
  28801. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  28802. return Object.defineProperty(createElement('div'), 'a', {
  28803. get: function () { return 7; }
  28804. }).a !== 7;
  28805. });
  28806. },{"../internals/descriptors":247,"../internals/document-create-element":249,"../internals/fails":260}],280:[function(require,module,exports){
  28807. 'use strict';
  28808. var uncurryThis = require('../internals/function-uncurry-this');
  28809. var fails = require('../internals/fails');
  28810. var classof = require('../internals/classof-raw');
  28811. var $Object = Object;
  28812. var split = uncurryThis(''.split);
  28813. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  28814. module.exports = fails(function () {
  28815. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  28816. // eslint-disable-next-line no-prototype-builtins -- safe
  28817. return !$Object('z').propertyIsEnumerable(0);
  28818. }) ? function (it) {
  28819. return classof(it) === 'String' ? split(it, '') : $Object(it);
  28820. } : $Object;
  28821. },{"../internals/classof-raw":235,"../internals/fails":260,"../internals/function-uncurry-this":268}],281:[function(require,module,exports){
  28822. 'use strict';
  28823. var uncurryThis = require('../internals/function-uncurry-this');
  28824. var isCallable = require('../internals/is-callable');
  28825. var store = require('../internals/shared-store');
  28826. var functionToString = uncurryThis(Function.toString);
  28827. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  28828. if (!isCallable(store.inspectSource)) {
  28829. store.inspectSource = function (it) {
  28830. return functionToString(it);
  28831. };
  28832. }
  28833. module.exports = store.inspectSource;
  28834. },{"../internals/function-uncurry-this":268,"../internals/is-callable":285,"../internals/shared-store":333}],282:[function(require,module,exports){
  28835. 'use strict';
  28836. var NATIVE_WEAK_MAP = require('../internals/weak-map-basic-detection');
  28837. var global = require('../internals/global');
  28838. var isObject = require('../internals/is-object');
  28839. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  28840. var hasOwn = require('../internals/has-own-property');
  28841. var shared = require('../internals/shared-store');
  28842. var sharedKey = require('../internals/shared-key');
  28843. var hiddenKeys = require('../internals/hidden-keys');
  28844. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  28845. var TypeError = global.TypeError;
  28846. var WeakMap = global.WeakMap;
  28847. var set, get, has;
  28848. var enforce = function (it) {
  28849. return has(it) ? get(it) : set(it, {});
  28850. };
  28851. var getterFor = function (TYPE) {
  28852. return function (it) {
  28853. var state;
  28854. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  28855. throw new TypeError('Incompatible receiver, ' + TYPE + ' required');
  28856. } return state;
  28857. };
  28858. };
  28859. if (NATIVE_WEAK_MAP || shared.state) {
  28860. var store = shared.state || (shared.state = new WeakMap());
  28861. /* eslint-disable no-self-assign -- prototype methods protection */
  28862. store.get = store.get;
  28863. store.has = store.has;
  28864. store.set = store.set;
  28865. /* eslint-enable no-self-assign -- prototype methods protection */
  28866. set = function (it, metadata) {
  28867. if (store.has(it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  28868. metadata.facade = it;
  28869. store.set(it, metadata);
  28870. return metadata;
  28871. };
  28872. get = function (it) {
  28873. return store.get(it) || {};
  28874. };
  28875. has = function (it) {
  28876. return store.has(it);
  28877. };
  28878. } else {
  28879. var STATE = sharedKey('state');
  28880. hiddenKeys[STATE] = true;
  28881. set = function (it, metadata) {
  28882. if (hasOwn(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  28883. metadata.facade = it;
  28884. createNonEnumerableProperty(it, STATE, metadata);
  28885. return metadata;
  28886. };
  28887. get = function (it) {
  28888. return hasOwn(it, STATE) ? it[STATE] : {};
  28889. };
  28890. has = function (it) {
  28891. return hasOwn(it, STATE);
  28892. };
  28893. }
  28894. module.exports = {
  28895. set: set,
  28896. get: get,
  28897. has: has,
  28898. enforce: enforce,
  28899. getterFor: getterFor
  28900. };
  28901. },{"../internals/create-non-enumerable-property":241,"../internals/global":274,"../internals/has-own-property":275,"../internals/hidden-keys":276,"../internals/is-object":289,"../internals/shared-key":332,"../internals/shared-store":333,"../internals/weak-map-basic-detection":354}],283:[function(require,module,exports){
  28902. 'use strict';
  28903. var wellKnownSymbol = require('../internals/well-known-symbol');
  28904. var Iterators = require('../internals/iterators');
  28905. var ITERATOR = wellKnownSymbol('iterator');
  28906. var ArrayPrototype = Array.prototype;
  28907. // check on default Array iterator
  28908. module.exports = function (it) {
  28909. return it !== undefined && (Iterators.Array === it || ArrayPrototype[ITERATOR] === it);
  28910. };
  28911. },{"../internals/iterators":298,"../internals/well-known-symbol":357}],284:[function(require,module,exports){
  28912. 'use strict';
  28913. var classof = require('../internals/classof-raw');
  28914. // `IsArray` abstract operation
  28915. // https://tc39.es/ecma262/#sec-isarray
  28916. // eslint-disable-next-line es/no-array-isarray -- safe
  28917. module.exports = Array.isArray || function isArray(argument) {
  28918. return classof(argument) === 'Array';
  28919. };
  28920. },{"../internals/classof-raw":235}],285:[function(require,module,exports){
  28921. 'use strict';
  28922. var $documentAll = require('../internals/document-all');
  28923. var documentAll = $documentAll.all;
  28924. // `IsCallable` abstract operation
  28925. // https://tc39.es/ecma262/#sec-iscallable
  28926. module.exports = $documentAll.IS_HTMLDDA ? function (argument) {
  28927. return typeof argument == 'function' || argument === documentAll;
  28928. } : function (argument) {
  28929. return typeof argument == 'function';
  28930. };
  28931. },{"../internals/document-all":248}],286:[function(require,module,exports){
  28932. 'use strict';
  28933. var uncurryThis = require('../internals/function-uncurry-this');
  28934. var fails = require('../internals/fails');
  28935. var isCallable = require('../internals/is-callable');
  28936. var classof = require('../internals/classof');
  28937. var getBuiltIn = require('../internals/get-built-in');
  28938. var inspectSource = require('../internals/inspect-source');
  28939. var noop = function () { /* empty */ };
  28940. var empty = [];
  28941. var construct = getBuiltIn('Reflect', 'construct');
  28942. var constructorRegExp = /^\s*(?:class|function)\b/;
  28943. var exec = uncurryThis(constructorRegExp.exec);
  28944. var INCORRECT_TO_STRING = !constructorRegExp.test(noop);
  28945. var isConstructorModern = function isConstructor(argument) {
  28946. if (!isCallable(argument)) return false;
  28947. try {
  28948. construct(noop, empty, argument);
  28949. return true;
  28950. } catch (error) {
  28951. return false;
  28952. }
  28953. };
  28954. var isConstructorLegacy = function isConstructor(argument) {
  28955. if (!isCallable(argument)) return false;
  28956. switch (classof(argument)) {
  28957. case 'AsyncFunction':
  28958. case 'GeneratorFunction':
  28959. case 'AsyncGeneratorFunction': return false;
  28960. }
  28961. try {
  28962. // we can't check .prototype since constructors produced by .bind haven't it
  28963. // `Function#toString` throws on some built-it function in some legacy engines
  28964. // (for example, `DOMQuad` and similar in FF41-)
  28965. return INCORRECT_TO_STRING || !!exec(constructorRegExp, inspectSource(argument));
  28966. } catch (error) {
  28967. return true;
  28968. }
  28969. };
  28970. isConstructorLegacy.sham = true;
  28971. // `IsConstructor` abstract operation
  28972. // https://tc39.es/ecma262/#sec-isconstructor
  28973. module.exports = !construct || fails(function () {
  28974. var called;
  28975. return isConstructorModern(isConstructorModern.call)
  28976. || !isConstructorModern(Object)
  28977. || !isConstructorModern(function () { called = true; })
  28978. || called;
  28979. }) ? isConstructorLegacy : isConstructorModern;
  28980. },{"../internals/classof":236,"../internals/fails":260,"../internals/function-uncurry-this":268,"../internals/get-built-in":269,"../internals/inspect-source":281,"../internals/is-callable":285}],287:[function(require,module,exports){
  28981. 'use strict';
  28982. var fails = require('../internals/fails');
  28983. var isCallable = require('../internals/is-callable');
  28984. var replacement = /#|\.prototype\./;
  28985. var isForced = function (feature, detection) {
  28986. var value = data[normalize(feature)];
  28987. return value === POLYFILL ? true
  28988. : value === NATIVE ? false
  28989. : isCallable(detection) ? fails(detection)
  28990. : !!detection;
  28991. };
  28992. var normalize = isForced.normalize = function (string) {
  28993. return String(string).replace(replacement, '.').toLowerCase();
  28994. };
  28995. var data = isForced.data = {};
  28996. var NATIVE = isForced.NATIVE = 'N';
  28997. var POLYFILL = isForced.POLYFILL = 'P';
  28998. module.exports = isForced;
  28999. },{"../internals/fails":260,"../internals/is-callable":285}],288:[function(require,module,exports){
  29000. 'use strict';
  29001. // we can't use just `it == null` since of `document.all` special case
  29002. // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-aec
  29003. module.exports = function (it) {
  29004. return it === null || it === undefined;
  29005. };
  29006. },{}],289:[function(require,module,exports){
  29007. 'use strict';
  29008. var isCallable = require('../internals/is-callable');
  29009. var $documentAll = require('../internals/document-all');
  29010. var documentAll = $documentAll.all;
  29011. module.exports = $documentAll.IS_HTMLDDA ? function (it) {
  29012. return typeof it == 'object' ? it !== null : isCallable(it) || it === documentAll;
  29013. } : function (it) {
  29014. return typeof it == 'object' ? it !== null : isCallable(it);
  29015. };
  29016. },{"../internals/document-all":248,"../internals/is-callable":285}],290:[function(require,module,exports){
  29017. 'use strict';
  29018. module.exports = false;
  29019. },{}],291:[function(require,module,exports){
  29020. 'use strict';
  29021. var isObject = require('../internals/is-object');
  29022. var classof = require('../internals/classof-raw');
  29023. var wellKnownSymbol = require('../internals/well-known-symbol');
  29024. var MATCH = wellKnownSymbol('match');
  29025. // `IsRegExp` abstract operation
  29026. // https://tc39.es/ecma262/#sec-isregexp
  29027. module.exports = function (it) {
  29028. var isRegExp;
  29029. return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) === 'RegExp');
  29030. };
  29031. },{"../internals/classof-raw":235,"../internals/is-object":289,"../internals/well-known-symbol":357}],292:[function(require,module,exports){
  29032. 'use strict';
  29033. var getBuiltIn = require('../internals/get-built-in');
  29034. var isCallable = require('../internals/is-callable');
  29035. var isPrototypeOf = require('../internals/object-is-prototype-of');
  29036. var USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');
  29037. var $Object = Object;
  29038. module.exports = USE_SYMBOL_AS_UID ? function (it) {
  29039. return typeof it == 'symbol';
  29040. } : function (it) {
  29041. var $Symbol = getBuiltIn('Symbol');
  29042. return isCallable($Symbol) && isPrototypeOf($Symbol.prototype, $Object(it));
  29043. };
  29044. },{"../internals/get-built-in":269,"../internals/is-callable":285,"../internals/object-is-prototype-of":314,"../internals/use-symbol-as-uid":351}],293:[function(require,module,exports){
  29045. 'use strict';
  29046. var bind = require('../internals/function-bind-context');
  29047. var call = require('../internals/function-call');
  29048. var anObject = require('../internals/an-object');
  29049. var tryToString = require('../internals/try-to-string');
  29050. var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
  29051. var lengthOfArrayLike = require('../internals/length-of-array-like');
  29052. var isPrototypeOf = require('../internals/object-is-prototype-of');
  29053. var getIterator = require('../internals/get-iterator');
  29054. var getIteratorMethod = require('../internals/get-iterator-method');
  29055. var iteratorClose = require('../internals/iterator-close');
  29056. var $TypeError = TypeError;
  29057. var Result = function (stopped, result) {
  29058. this.stopped = stopped;
  29059. this.result = result;
  29060. };
  29061. var ResultPrototype = Result.prototype;
  29062. module.exports = function (iterable, unboundFunction, options) {
  29063. var that = options && options.that;
  29064. var AS_ENTRIES = !!(options && options.AS_ENTRIES);
  29065. var IS_RECORD = !!(options && options.IS_RECORD);
  29066. var IS_ITERATOR = !!(options && options.IS_ITERATOR);
  29067. var INTERRUPTED = !!(options && options.INTERRUPTED);
  29068. var fn = bind(unboundFunction, that);
  29069. var iterator, iterFn, index, length, result, next, step;
  29070. var stop = function (condition) {
  29071. if (iterator) iteratorClose(iterator, 'normal', condition);
  29072. return new Result(true, condition);
  29073. };
  29074. var callFn = function (value) {
  29075. if (AS_ENTRIES) {
  29076. anObject(value);
  29077. return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
  29078. } return INTERRUPTED ? fn(value, stop) : fn(value);
  29079. };
  29080. if (IS_RECORD) {
  29081. iterator = iterable.iterator;
  29082. } else if (IS_ITERATOR) {
  29083. iterator = iterable;
  29084. } else {
  29085. iterFn = getIteratorMethod(iterable);
  29086. if (!iterFn) throw new $TypeError(tryToString(iterable) + ' is not iterable');
  29087. // optimisation for array iterators
  29088. if (isArrayIteratorMethod(iterFn)) {
  29089. for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) {
  29090. result = callFn(iterable[index]);
  29091. if (result && isPrototypeOf(ResultPrototype, result)) return result;
  29092. } return new Result(false);
  29093. }
  29094. iterator = getIterator(iterable, iterFn);
  29095. }
  29096. next = IS_RECORD ? iterable.next : iterator.next;
  29097. while (!(step = call(next, iterator)).done) {
  29098. try {
  29099. result = callFn(step.value);
  29100. } catch (error) {
  29101. iteratorClose(iterator, 'throw', error);
  29102. }
  29103. if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result;
  29104. } return new Result(false);
  29105. };
  29106. },{"../internals/an-object":227,"../internals/function-bind-context":262,"../internals/function-call":264,"../internals/get-iterator":271,"../internals/get-iterator-method":270,"../internals/is-array-iterator-method":283,"../internals/iterator-close":294,"../internals/length-of-array-like":299,"../internals/object-is-prototype-of":314,"../internals/try-to-string":349}],294:[function(require,module,exports){
  29107. 'use strict';
  29108. var call = require('../internals/function-call');
  29109. var anObject = require('../internals/an-object');
  29110. var getMethod = require('../internals/get-method');
  29111. module.exports = function (iterator, kind, value) {
  29112. var innerResult, innerError;
  29113. anObject(iterator);
  29114. try {
  29115. innerResult = getMethod(iterator, 'return');
  29116. if (!innerResult) {
  29117. if (kind === 'throw') throw value;
  29118. return value;
  29119. }
  29120. innerResult = call(innerResult, iterator);
  29121. } catch (error) {
  29122. innerError = true;
  29123. innerResult = error;
  29124. }
  29125. if (kind === 'throw') throw value;
  29126. if (innerError) throw innerResult;
  29127. anObject(innerResult);
  29128. return value;
  29129. };
  29130. },{"../internals/an-object":227,"../internals/function-call":264,"../internals/get-method":273}],295:[function(require,module,exports){
  29131. 'use strict';
  29132. var IteratorPrototype = require('../internals/iterators-core').IteratorPrototype;
  29133. var create = require('../internals/object-create');
  29134. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  29135. var setToStringTag = require('../internals/set-to-string-tag');
  29136. var Iterators = require('../internals/iterators');
  29137. var returnThis = function () { return this; };
  29138. module.exports = function (IteratorConstructor, NAME, next, ENUMERABLE_NEXT) {
  29139. var TO_STRING_TAG = NAME + ' Iterator';
  29140. IteratorConstructor.prototype = create(IteratorPrototype, { next: createPropertyDescriptor(+!ENUMERABLE_NEXT, next) });
  29141. setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
  29142. Iterators[TO_STRING_TAG] = returnThis;
  29143. return IteratorConstructor;
  29144. };
  29145. },{"../internals/create-property-descriptor":242,"../internals/iterators":298,"../internals/iterators-core":297,"../internals/object-create":306,"../internals/set-to-string-tag":331}],296:[function(require,module,exports){
  29146. 'use strict';
  29147. var $ = require('../internals/export');
  29148. var call = require('../internals/function-call');
  29149. var IS_PURE = require('../internals/is-pure');
  29150. var FunctionName = require('../internals/function-name');
  29151. var isCallable = require('../internals/is-callable');
  29152. var createIteratorConstructor = require('../internals/iterator-create-constructor');
  29153. var getPrototypeOf = require('../internals/object-get-prototype-of');
  29154. var setPrototypeOf = require('../internals/object-set-prototype-of');
  29155. var setToStringTag = require('../internals/set-to-string-tag');
  29156. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  29157. var defineBuiltIn = require('../internals/define-built-in');
  29158. var wellKnownSymbol = require('../internals/well-known-symbol');
  29159. var Iterators = require('../internals/iterators');
  29160. var IteratorsCore = require('../internals/iterators-core');
  29161. var PROPER_FUNCTION_NAME = FunctionName.PROPER;
  29162. var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
  29163. var IteratorPrototype = IteratorsCore.IteratorPrototype;
  29164. var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
  29165. var ITERATOR = wellKnownSymbol('iterator');
  29166. var KEYS = 'keys';
  29167. var VALUES = 'values';
  29168. var ENTRIES = 'entries';
  29169. var returnThis = function () { return this; };
  29170. module.exports = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
  29171. createIteratorConstructor(IteratorConstructor, NAME, next);
  29172. var getIterationMethod = function (KIND) {
  29173. if (KIND === DEFAULT && defaultIterator) return defaultIterator;
  29174. if (!BUGGY_SAFARI_ITERATORS && KIND && KIND in IterablePrototype) return IterablePrototype[KIND];
  29175. switch (KIND) {
  29176. case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
  29177. case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
  29178. case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
  29179. }
  29180. return function () { return new IteratorConstructor(this); };
  29181. };
  29182. var TO_STRING_TAG = NAME + ' Iterator';
  29183. var INCORRECT_VALUES_NAME = false;
  29184. var IterablePrototype = Iterable.prototype;
  29185. var nativeIterator = IterablePrototype[ITERATOR]
  29186. || IterablePrototype['@@iterator']
  29187. || DEFAULT && IterablePrototype[DEFAULT];
  29188. var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT);
  29189. var anyNativeIterator = NAME === 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
  29190. var CurrentIteratorPrototype, methods, KEY;
  29191. // fix native
  29192. if (anyNativeIterator) {
  29193. CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable()));
  29194. if (CurrentIteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
  29195. if (!IS_PURE && getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) {
  29196. if (setPrototypeOf) {
  29197. setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype);
  29198. } else if (!isCallable(CurrentIteratorPrototype[ITERATOR])) {
  29199. defineBuiltIn(CurrentIteratorPrototype, ITERATOR, returnThis);
  29200. }
  29201. }
  29202. // Set @@toStringTag to native iterators
  29203. setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true);
  29204. if (IS_PURE) Iterators[TO_STRING_TAG] = returnThis;
  29205. }
  29206. }
  29207. // fix Array.prototype.{ values, @@iterator }.name in V8 / FF
  29208. if (PROPER_FUNCTION_NAME && DEFAULT === VALUES && nativeIterator && nativeIterator.name !== VALUES) {
  29209. if (!IS_PURE && CONFIGURABLE_FUNCTION_NAME) {
  29210. createNonEnumerableProperty(IterablePrototype, 'name', VALUES);
  29211. } else {
  29212. INCORRECT_VALUES_NAME = true;
  29213. defaultIterator = function values() { return call(nativeIterator, this); };
  29214. }
  29215. }
  29216. // export additional methods
  29217. if (DEFAULT) {
  29218. methods = {
  29219. values: getIterationMethod(VALUES),
  29220. keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
  29221. entries: getIterationMethod(ENTRIES)
  29222. };
  29223. if (FORCED) for (KEY in methods) {
  29224. if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
  29225. defineBuiltIn(IterablePrototype, KEY, methods[KEY]);
  29226. }
  29227. } else $({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
  29228. }
  29229. // define iterator
  29230. if ((!IS_PURE || FORCED) && IterablePrototype[ITERATOR] !== defaultIterator) {
  29231. defineBuiltIn(IterablePrototype, ITERATOR, defaultIterator, { name: DEFAULT });
  29232. }
  29233. Iterators[NAME] = defaultIterator;
  29234. return methods;
  29235. };
  29236. },{"../internals/create-non-enumerable-property":241,"../internals/define-built-in":245,"../internals/export":259,"../internals/function-call":264,"../internals/function-name":265,"../internals/is-callable":285,"../internals/is-pure":290,"../internals/iterator-create-constructor":295,"../internals/iterators":298,"../internals/iterators-core":297,"../internals/object-get-prototype-of":313,"../internals/object-set-prototype-of":318,"../internals/set-to-string-tag":331,"../internals/well-known-symbol":357}],297:[function(require,module,exports){
  29237. 'use strict';
  29238. var fails = require('../internals/fails');
  29239. var isCallable = require('../internals/is-callable');
  29240. var isObject = require('../internals/is-object');
  29241. var create = require('../internals/object-create');
  29242. var getPrototypeOf = require('../internals/object-get-prototype-of');
  29243. var defineBuiltIn = require('../internals/define-built-in');
  29244. var wellKnownSymbol = require('../internals/well-known-symbol');
  29245. var IS_PURE = require('../internals/is-pure');
  29246. var ITERATOR = wellKnownSymbol('iterator');
  29247. var BUGGY_SAFARI_ITERATORS = false;
  29248. // `%IteratorPrototype%` object
  29249. // https://tc39.es/ecma262/#sec-%iteratorprototype%-object
  29250. var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator;
  29251. /* eslint-disable es/no-array-prototype-keys -- safe */
  29252. if ([].keys) {
  29253. arrayIterator = [].keys();
  29254. // Safari 8 has buggy iterators w/o `next`
  29255. if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true;
  29256. else {
  29257. PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator));
  29258. if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype;
  29259. }
  29260. }
  29261. var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype) || fails(function () {
  29262. var test = {};
  29263. // FF44- legacy iterators case
  29264. return IteratorPrototype[ITERATOR].call(test) !== test;
  29265. });
  29266. if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype = {};
  29267. else if (IS_PURE) IteratorPrototype = create(IteratorPrototype);
  29268. // `%IteratorPrototype%[@@iterator]()` method
  29269. // https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
  29270. if (!isCallable(IteratorPrototype[ITERATOR])) {
  29271. defineBuiltIn(IteratorPrototype, ITERATOR, function () {
  29272. return this;
  29273. });
  29274. }
  29275. module.exports = {
  29276. IteratorPrototype: IteratorPrototype,
  29277. BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS
  29278. };
  29279. },{"../internals/define-built-in":245,"../internals/fails":260,"../internals/is-callable":285,"../internals/is-object":289,"../internals/is-pure":290,"../internals/object-create":306,"../internals/object-get-prototype-of":313,"../internals/well-known-symbol":357}],298:[function(require,module,exports){
  29280. arguments[4][276][0].apply(exports,arguments)
  29281. },{"dup":276}],299:[function(require,module,exports){
  29282. 'use strict';
  29283. var toLength = require('../internals/to-length');
  29284. // `LengthOfArrayLike` abstract operation
  29285. // https://tc39.es/ecma262/#sec-lengthofarraylike
  29286. module.exports = function (obj) {
  29287. return toLength(obj.length);
  29288. };
  29289. },{"../internals/to-length":343}],300:[function(require,module,exports){
  29290. 'use strict';
  29291. var uncurryThis = require('../internals/function-uncurry-this');
  29292. var fails = require('../internals/fails');
  29293. var isCallable = require('../internals/is-callable');
  29294. var hasOwn = require('../internals/has-own-property');
  29295. var DESCRIPTORS = require('../internals/descriptors');
  29296. var CONFIGURABLE_FUNCTION_NAME = require('../internals/function-name').CONFIGURABLE;
  29297. var inspectSource = require('../internals/inspect-source');
  29298. var InternalStateModule = require('../internals/internal-state');
  29299. var enforceInternalState = InternalStateModule.enforce;
  29300. var getInternalState = InternalStateModule.get;
  29301. var $String = String;
  29302. // eslint-disable-next-line es/no-object-defineproperty -- safe
  29303. var defineProperty = Object.defineProperty;
  29304. var stringSlice = uncurryThis(''.slice);
  29305. var replace = uncurryThis(''.replace);
  29306. var join = uncurryThis([].join);
  29307. var CONFIGURABLE_LENGTH = DESCRIPTORS && !fails(function () {
  29308. return defineProperty(function () { /* empty */ }, 'length', { value: 8 }).length !== 8;
  29309. });
  29310. var TEMPLATE = String(String).split('String');
  29311. var makeBuiltIn = module.exports = function (value, name, options) {
  29312. if (stringSlice($String(name), 0, 7) === 'Symbol(') {
  29313. name = '[' + replace($String(name), /^Symbol\(([^)]*)\)/, '$1') + ']';
  29314. }
  29315. if (options && options.getter) name = 'get ' + name;
  29316. if (options && options.setter) name = 'set ' + name;
  29317. if (!hasOwn(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) {
  29318. if (DESCRIPTORS) defineProperty(value, 'name', { value: name, configurable: true });
  29319. else value.name = name;
  29320. }
  29321. if (CONFIGURABLE_LENGTH && options && hasOwn(options, 'arity') && value.length !== options.arity) {
  29322. defineProperty(value, 'length', { value: options.arity });
  29323. }
  29324. try {
  29325. if (options && hasOwn(options, 'constructor') && options.constructor) {
  29326. if (DESCRIPTORS) defineProperty(value, 'prototype', { writable: false });
  29327. // in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable
  29328. } else if (value.prototype) value.prototype = undefined;
  29329. } catch (error) { /* empty */ }
  29330. var state = enforceInternalState(value);
  29331. if (!hasOwn(state, 'source')) {
  29332. state.source = join(TEMPLATE, typeof name == 'string' ? name : '');
  29333. } return value;
  29334. };
  29335. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  29336. // eslint-disable-next-line no-extend-native -- required
  29337. Function.prototype.toString = makeBuiltIn(function toString() {
  29338. return isCallable(this) && getInternalState(this).source || inspectSource(this);
  29339. }, 'toString');
  29340. },{"../internals/descriptors":247,"../internals/fails":260,"../internals/function-name":265,"../internals/function-uncurry-this":268,"../internals/has-own-property":275,"../internals/inspect-source":281,"../internals/internal-state":282,"../internals/is-callable":285}],301:[function(require,module,exports){
  29341. 'use strict';
  29342. var ceil = Math.ceil;
  29343. var floor = Math.floor;
  29344. // `Math.trunc` method
  29345. // https://tc39.es/ecma262/#sec-math.trunc
  29346. // eslint-disable-next-line es/no-math-trunc -- safe
  29347. module.exports = Math.trunc || function trunc(x) {
  29348. var n = +x;
  29349. return (n > 0 ? floor : ceil)(n);
  29350. };
  29351. },{}],302:[function(require,module,exports){
  29352. 'use strict';
  29353. var global = require('../internals/global');
  29354. var bind = require('../internals/function-bind-context');
  29355. var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
  29356. var macrotask = require('../internals/task').set;
  29357. var Queue = require('../internals/queue');
  29358. var IS_IOS = require('../internals/engine-is-ios');
  29359. var IS_IOS_PEBBLE = require('../internals/engine-is-ios-pebble');
  29360. var IS_WEBOS_WEBKIT = require('../internals/engine-is-webos-webkit');
  29361. var IS_NODE = require('../internals/engine-is-node');
  29362. var MutationObserver = global.MutationObserver || global.WebKitMutationObserver;
  29363. var document = global.document;
  29364. var process = global.process;
  29365. var Promise = global.Promise;
  29366. // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
  29367. var queueMicrotaskDescriptor = getOwnPropertyDescriptor(global, 'queueMicrotask');
  29368. var microtask = queueMicrotaskDescriptor && queueMicrotaskDescriptor.value;
  29369. var notify, toggle, node, promise, then;
  29370. // modern engines have queueMicrotask method
  29371. if (!microtask) {
  29372. var queue = new Queue();
  29373. var flush = function () {
  29374. var parent, fn;
  29375. if (IS_NODE && (parent = process.domain)) parent.exit();
  29376. while (fn = queue.get()) try {
  29377. fn();
  29378. } catch (error) {
  29379. if (queue.head) notify();
  29380. throw error;
  29381. }
  29382. if (parent) parent.enter();
  29383. };
  29384. // browsers with MutationObserver, except iOS - https://github.com/zloirock/core-js/issues/339
  29385. // also except WebOS Webkit https://github.com/zloirock/core-js/issues/898
  29386. if (!IS_IOS && !IS_NODE && !IS_WEBOS_WEBKIT && MutationObserver && document) {
  29387. toggle = true;
  29388. node = document.createTextNode('');
  29389. new MutationObserver(flush).observe(node, { characterData: true });
  29390. notify = function () {
  29391. node.data = toggle = !toggle;
  29392. };
  29393. // environments with maybe non-completely correct, but existent Promise
  29394. } else if (!IS_IOS_PEBBLE && Promise && Promise.resolve) {
  29395. // Promise.resolve without an argument throws an error in LG WebOS 2
  29396. promise = Promise.resolve(undefined);
  29397. // workaround of WebKit ~ iOS Safari 10.1 bug
  29398. promise.constructor = Promise;
  29399. then = bind(promise.then, promise);
  29400. notify = function () {
  29401. then(flush);
  29402. };
  29403. // Node.js without promises
  29404. } else if (IS_NODE) {
  29405. notify = function () {
  29406. process.nextTick(flush);
  29407. };
  29408. // for other environments - macrotask based on:
  29409. // - setImmediate
  29410. // - MessageChannel
  29411. // - window.postMessage
  29412. // - onreadystatechange
  29413. // - setTimeout
  29414. } else {
  29415. // `webpack` dev server bug on IE global methods - use bind(fn, global)
  29416. macrotask = bind(macrotask, global);
  29417. notify = function () {
  29418. macrotask(flush);
  29419. };
  29420. }
  29421. microtask = function (fn) {
  29422. if (!queue.head) notify();
  29423. queue.add(fn);
  29424. };
  29425. }
  29426. module.exports = microtask;
  29427. },{"../internals/engine-is-ios":253,"../internals/engine-is-ios-pebble":252,"../internals/engine-is-node":254,"../internals/engine-is-webos-webkit":255,"../internals/function-bind-context":262,"../internals/global":274,"../internals/object-get-own-property-descriptor":309,"../internals/queue":328,"../internals/task":339}],303:[function(require,module,exports){
  29428. 'use strict';
  29429. var aCallable = require('../internals/a-callable');
  29430. var $TypeError = TypeError;
  29431. var PromiseCapability = function (C) {
  29432. var resolve, reject;
  29433. this.promise = new C(function ($$resolve, $$reject) {
  29434. if (resolve !== undefined || reject !== undefined) throw new $TypeError('Bad Promise constructor');
  29435. resolve = $$resolve;
  29436. reject = $$reject;
  29437. });
  29438. this.resolve = aCallable(resolve);
  29439. this.reject = aCallable(reject);
  29440. };
  29441. // `NewPromiseCapability` abstract operation
  29442. // https://tc39.es/ecma262/#sec-newpromisecapability
  29443. module.exports.f = function (C) {
  29444. return new PromiseCapability(C);
  29445. };
  29446. },{"../internals/a-callable":222}],304:[function(require,module,exports){
  29447. 'use strict';
  29448. var isRegExp = require('../internals/is-regexp');
  29449. var $TypeError = TypeError;
  29450. module.exports = function (it) {
  29451. if (isRegExp(it)) {
  29452. throw new $TypeError("The method doesn't accept regular expressions");
  29453. } return it;
  29454. };
  29455. },{"../internals/is-regexp":291}],305:[function(require,module,exports){
  29456. 'use strict';
  29457. var DESCRIPTORS = require('../internals/descriptors');
  29458. var uncurryThis = require('../internals/function-uncurry-this');
  29459. var call = require('../internals/function-call');
  29460. var fails = require('../internals/fails');
  29461. var objectKeys = require('../internals/object-keys');
  29462. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  29463. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  29464. var toObject = require('../internals/to-object');
  29465. var IndexedObject = require('../internals/indexed-object');
  29466. // eslint-disable-next-line es/no-object-assign -- safe
  29467. var $assign = Object.assign;
  29468. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  29469. var defineProperty = Object.defineProperty;
  29470. var concat = uncurryThis([].concat);
  29471. // `Object.assign` method
  29472. // https://tc39.es/ecma262/#sec-object.assign
  29473. module.exports = !$assign || fails(function () {
  29474. // should have correct order of operations (Edge bug)
  29475. if (DESCRIPTORS && $assign({ b: 1 }, $assign(defineProperty({}, 'a', {
  29476. enumerable: true,
  29477. get: function () {
  29478. defineProperty(this, 'b', {
  29479. value: 3,
  29480. enumerable: false
  29481. });
  29482. }
  29483. }), { b: 2 })).b !== 1) return true;
  29484. // should work with symbols and should have deterministic property order (V8 bug)
  29485. var A = {};
  29486. var B = {};
  29487. // eslint-disable-next-line es/no-symbol -- safe
  29488. var symbol = Symbol('assign detection');
  29489. var alphabet = 'abcdefghijklmnopqrst';
  29490. A[symbol] = 7;
  29491. alphabet.split('').forEach(function (chr) { B[chr] = chr; });
  29492. return $assign({}, A)[symbol] !== 7 || objectKeys($assign({}, B)).join('') !== alphabet;
  29493. }) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
  29494. var T = toObject(target);
  29495. var argumentsLength = arguments.length;
  29496. var index = 1;
  29497. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  29498. var propertyIsEnumerable = propertyIsEnumerableModule.f;
  29499. while (argumentsLength > index) {
  29500. var S = IndexedObject(arguments[index++]);
  29501. var keys = getOwnPropertySymbols ? concat(objectKeys(S), getOwnPropertySymbols(S)) : objectKeys(S);
  29502. var length = keys.length;
  29503. var j = 0;
  29504. var key;
  29505. while (length > j) {
  29506. key = keys[j++];
  29507. if (!DESCRIPTORS || call(propertyIsEnumerable, S, key)) T[key] = S[key];
  29508. }
  29509. } return T;
  29510. } : $assign;
  29511. },{"../internals/descriptors":247,"../internals/fails":260,"../internals/function-call":264,"../internals/function-uncurry-this":268,"../internals/indexed-object":280,"../internals/object-get-own-property-symbols":312,"../internals/object-keys":316,"../internals/object-property-is-enumerable":317,"../internals/to-object":344}],306:[function(require,module,exports){
  29512. 'use strict';
  29513. /* global ActiveXObject -- old IE, WSH */
  29514. var anObject = require('../internals/an-object');
  29515. var definePropertiesModule = require('../internals/object-define-properties');
  29516. var enumBugKeys = require('../internals/enum-bug-keys');
  29517. var hiddenKeys = require('../internals/hidden-keys');
  29518. var html = require('../internals/html');
  29519. var documentCreateElement = require('../internals/document-create-element');
  29520. var sharedKey = require('../internals/shared-key');
  29521. var GT = '>';
  29522. var LT = '<';
  29523. var PROTOTYPE = 'prototype';
  29524. var SCRIPT = 'script';
  29525. var IE_PROTO = sharedKey('IE_PROTO');
  29526. var EmptyConstructor = function () { /* empty */ };
  29527. var scriptTag = function (content) {
  29528. return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
  29529. };
  29530. // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
  29531. var NullProtoObjectViaActiveX = function (activeXDocument) {
  29532. activeXDocument.write(scriptTag(''));
  29533. activeXDocument.close();
  29534. var temp = activeXDocument.parentWindow.Object;
  29535. activeXDocument = null; // avoid memory leak
  29536. return temp;
  29537. };
  29538. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  29539. var NullProtoObjectViaIFrame = function () {
  29540. // Thrash, waste and sodomy: IE GC bug
  29541. var iframe = documentCreateElement('iframe');
  29542. var JS = 'java' + SCRIPT + ':';
  29543. var iframeDocument;
  29544. iframe.style.display = 'none';
  29545. html.appendChild(iframe);
  29546. // https://github.com/zloirock/core-js/issues/475
  29547. iframe.src = String(JS);
  29548. iframeDocument = iframe.contentWindow.document;
  29549. iframeDocument.open();
  29550. iframeDocument.write(scriptTag('document.F=Object'));
  29551. iframeDocument.close();
  29552. return iframeDocument.F;
  29553. };
  29554. // Check for document.domain and active x support
  29555. // No need to use active x approach when document.domain is not set
  29556. // see https://github.com/es-shims/es5-shim/issues/150
  29557. // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
  29558. // avoid IE GC bug
  29559. var activeXDocument;
  29560. var NullProtoObject = function () {
  29561. try {
  29562. activeXDocument = new ActiveXObject('htmlfile');
  29563. } catch (error) { /* ignore */ }
  29564. NullProtoObject = typeof document != 'undefined'
  29565. ? document.domain && activeXDocument
  29566. ? NullProtoObjectViaActiveX(activeXDocument) // old IE
  29567. : NullProtoObjectViaIFrame()
  29568. : NullProtoObjectViaActiveX(activeXDocument); // WSH
  29569. var length = enumBugKeys.length;
  29570. while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
  29571. return NullProtoObject();
  29572. };
  29573. hiddenKeys[IE_PROTO] = true;
  29574. // `Object.create` method
  29575. // https://tc39.es/ecma262/#sec-object.create
  29576. // eslint-disable-next-line es/no-object-create -- safe
  29577. module.exports = Object.create || function create(O, Properties) {
  29578. var result;
  29579. if (O !== null) {
  29580. EmptyConstructor[PROTOTYPE] = anObject(O);
  29581. result = new EmptyConstructor();
  29582. EmptyConstructor[PROTOTYPE] = null;
  29583. // add "__proto__" for Object.getPrototypeOf polyfill
  29584. result[IE_PROTO] = O;
  29585. } else result = NullProtoObject();
  29586. return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
  29587. };
  29588. },{"../internals/an-object":227,"../internals/document-create-element":249,"../internals/enum-bug-keys":258,"../internals/hidden-keys":276,"../internals/html":278,"../internals/object-define-properties":307,"../internals/shared-key":332}],307:[function(require,module,exports){
  29589. 'use strict';
  29590. var DESCRIPTORS = require('../internals/descriptors');
  29591. var V8_PROTOTYPE_DEFINE_BUG = require('../internals/v8-prototype-define-bug');
  29592. var definePropertyModule = require('../internals/object-define-property');
  29593. var anObject = require('../internals/an-object');
  29594. var toIndexedObject = require('../internals/to-indexed-object');
  29595. var objectKeys = require('../internals/object-keys');
  29596. // `Object.defineProperties` method
  29597. // https://tc39.es/ecma262/#sec-object.defineproperties
  29598. // eslint-disable-next-line es/no-object-defineproperties -- safe
  29599. exports.f = DESCRIPTORS && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
  29600. anObject(O);
  29601. var props = toIndexedObject(Properties);
  29602. var keys = objectKeys(Properties);
  29603. var length = keys.length;
  29604. var index = 0;
  29605. var key;
  29606. while (length > index) definePropertyModule.f(O, key = keys[index++], props[key]);
  29607. return O;
  29608. };
  29609. },{"../internals/an-object":227,"../internals/descriptors":247,"../internals/object-define-property":308,"../internals/object-keys":316,"../internals/to-indexed-object":341,"../internals/v8-prototype-define-bug":352}],308:[function(require,module,exports){
  29610. 'use strict';
  29611. var DESCRIPTORS = require('../internals/descriptors');
  29612. var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
  29613. var V8_PROTOTYPE_DEFINE_BUG = require('../internals/v8-prototype-define-bug');
  29614. var anObject = require('../internals/an-object');
  29615. var toPropertyKey = require('../internals/to-property-key');
  29616. var $TypeError = TypeError;
  29617. // eslint-disable-next-line es/no-object-defineproperty -- safe
  29618. var $defineProperty = Object.defineProperty;
  29619. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  29620. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  29621. var ENUMERABLE = 'enumerable';
  29622. var CONFIGURABLE = 'configurable';
  29623. var WRITABLE = 'writable';
  29624. // `Object.defineProperty` method
  29625. // https://tc39.es/ecma262/#sec-object.defineproperty
  29626. exports.f = DESCRIPTORS ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) {
  29627. anObject(O);
  29628. P = toPropertyKey(P);
  29629. anObject(Attributes);
  29630. if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
  29631. var current = $getOwnPropertyDescriptor(O, P);
  29632. if (current && current[WRITABLE]) {
  29633. O[P] = Attributes.value;
  29634. Attributes = {
  29635. configurable: CONFIGURABLE in Attributes ? Attributes[CONFIGURABLE] : current[CONFIGURABLE],
  29636. enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
  29637. writable: false
  29638. };
  29639. }
  29640. } return $defineProperty(O, P, Attributes);
  29641. } : $defineProperty : function defineProperty(O, P, Attributes) {
  29642. anObject(O);
  29643. P = toPropertyKey(P);
  29644. anObject(Attributes);
  29645. if (IE8_DOM_DEFINE) try {
  29646. return $defineProperty(O, P, Attributes);
  29647. } catch (error) { /* empty */ }
  29648. if ('get' in Attributes || 'set' in Attributes) throw new $TypeError('Accessors not supported');
  29649. if ('value' in Attributes) O[P] = Attributes.value;
  29650. return O;
  29651. };
  29652. },{"../internals/an-object":227,"../internals/descriptors":247,"../internals/ie8-dom-define":279,"../internals/to-property-key":346,"../internals/v8-prototype-define-bug":352}],309:[function(require,module,exports){
  29653. 'use strict';
  29654. var DESCRIPTORS = require('../internals/descriptors');
  29655. var call = require('../internals/function-call');
  29656. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  29657. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  29658. var toIndexedObject = require('../internals/to-indexed-object');
  29659. var toPropertyKey = require('../internals/to-property-key');
  29660. var hasOwn = require('../internals/has-own-property');
  29661. var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
  29662. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  29663. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  29664. // `Object.getOwnPropertyDescriptor` method
  29665. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  29666. exports.f = DESCRIPTORS ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  29667. O = toIndexedObject(O);
  29668. P = toPropertyKey(P);
  29669. if (IE8_DOM_DEFINE) try {
  29670. return $getOwnPropertyDescriptor(O, P);
  29671. } catch (error) { /* empty */ }
  29672. if (hasOwn(O, P)) return createPropertyDescriptor(!call(propertyIsEnumerableModule.f, O, P), O[P]);
  29673. };
  29674. },{"../internals/create-property-descriptor":242,"../internals/descriptors":247,"../internals/function-call":264,"../internals/has-own-property":275,"../internals/ie8-dom-define":279,"../internals/object-property-is-enumerable":317,"../internals/to-indexed-object":341,"../internals/to-property-key":346}],310:[function(require,module,exports){
  29675. 'use strict';
  29676. /* eslint-disable es/no-object-getownpropertynames -- safe */
  29677. var classof = require('../internals/classof-raw');
  29678. var toIndexedObject = require('../internals/to-indexed-object');
  29679. var $getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
  29680. var arraySlice = require('../internals/array-slice-simple');
  29681. var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames
  29682. ? Object.getOwnPropertyNames(window) : [];
  29683. var getWindowNames = function (it) {
  29684. try {
  29685. return $getOwnPropertyNames(it);
  29686. } catch (error) {
  29687. return arraySlice(windowNames);
  29688. }
  29689. };
  29690. // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
  29691. module.exports.f = function getOwnPropertyNames(it) {
  29692. return windowNames && classof(it) === 'Window'
  29693. ? getWindowNames(it)
  29694. : $getOwnPropertyNames(toIndexedObject(it));
  29695. };
  29696. },{"../internals/array-slice-simple":230,"../internals/classof-raw":235,"../internals/object-get-own-property-names":311,"../internals/to-indexed-object":341}],311:[function(require,module,exports){
  29697. 'use strict';
  29698. var internalObjectKeys = require('../internals/object-keys-internal');
  29699. var enumBugKeys = require('../internals/enum-bug-keys');
  29700. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  29701. // `Object.getOwnPropertyNames` method
  29702. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  29703. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  29704. exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  29705. return internalObjectKeys(O, hiddenKeys);
  29706. };
  29707. },{"../internals/enum-bug-keys":258,"../internals/object-keys-internal":315}],312:[function(require,module,exports){
  29708. 'use strict';
  29709. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  29710. exports.f = Object.getOwnPropertySymbols;
  29711. },{}],313:[function(require,module,exports){
  29712. 'use strict';
  29713. var hasOwn = require('../internals/has-own-property');
  29714. var isCallable = require('../internals/is-callable');
  29715. var toObject = require('../internals/to-object');
  29716. var sharedKey = require('../internals/shared-key');
  29717. var CORRECT_PROTOTYPE_GETTER = require('../internals/correct-prototype-getter');
  29718. var IE_PROTO = sharedKey('IE_PROTO');
  29719. var $Object = Object;
  29720. var ObjectPrototype = $Object.prototype;
  29721. // `Object.getPrototypeOf` method
  29722. // https://tc39.es/ecma262/#sec-object.getprototypeof
  29723. // eslint-disable-next-line es/no-object-getprototypeof -- safe
  29724. module.exports = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : function (O) {
  29725. var object = toObject(O);
  29726. if (hasOwn(object, IE_PROTO)) return object[IE_PROTO];
  29727. var constructor = object.constructor;
  29728. if (isCallable(constructor) && object instanceof constructor) {
  29729. return constructor.prototype;
  29730. } return object instanceof $Object ? ObjectPrototype : null;
  29731. };
  29732. },{"../internals/correct-prototype-getter":239,"../internals/has-own-property":275,"../internals/is-callable":285,"../internals/shared-key":332,"../internals/to-object":344}],314:[function(require,module,exports){
  29733. 'use strict';
  29734. var uncurryThis = require('../internals/function-uncurry-this');
  29735. module.exports = uncurryThis({}.isPrototypeOf);
  29736. },{"../internals/function-uncurry-this":268}],315:[function(require,module,exports){
  29737. 'use strict';
  29738. var uncurryThis = require('../internals/function-uncurry-this');
  29739. var hasOwn = require('../internals/has-own-property');
  29740. var toIndexedObject = require('../internals/to-indexed-object');
  29741. var indexOf = require('../internals/array-includes').indexOf;
  29742. var hiddenKeys = require('../internals/hidden-keys');
  29743. var push = uncurryThis([].push);
  29744. module.exports = function (object, names) {
  29745. var O = toIndexedObject(object);
  29746. var i = 0;
  29747. var result = [];
  29748. var key;
  29749. for (key in O) !hasOwn(hiddenKeys, key) && hasOwn(O, key) && push(result, key);
  29750. // Don't enum bug & hidden keys
  29751. while (names.length > i) if (hasOwn(O, key = names[i++])) {
  29752. ~indexOf(result, key) || push(result, key);
  29753. }
  29754. return result;
  29755. };
  29756. },{"../internals/array-includes":228,"../internals/function-uncurry-this":268,"../internals/has-own-property":275,"../internals/hidden-keys":276,"../internals/to-indexed-object":341}],316:[function(require,module,exports){
  29757. 'use strict';
  29758. var internalObjectKeys = require('../internals/object-keys-internal');
  29759. var enumBugKeys = require('../internals/enum-bug-keys');
  29760. // `Object.keys` method
  29761. // https://tc39.es/ecma262/#sec-object.keys
  29762. // eslint-disable-next-line es/no-object-keys -- safe
  29763. module.exports = Object.keys || function keys(O) {
  29764. return internalObjectKeys(O, enumBugKeys);
  29765. };
  29766. },{"../internals/enum-bug-keys":258,"../internals/object-keys-internal":315}],317:[function(require,module,exports){
  29767. 'use strict';
  29768. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  29769. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  29770. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  29771. // Nashorn ~ JDK8 bug
  29772. var NASHORN_BUG = getOwnPropertyDescriptor && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  29773. // `Object.prototype.propertyIsEnumerable` method implementation
  29774. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  29775. exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  29776. var descriptor = getOwnPropertyDescriptor(this, V);
  29777. return !!descriptor && descriptor.enumerable;
  29778. } : $propertyIsEnumerable;
  29779. },{}],318:[function(require,module,exports){
  29780. 'use strict';
  29781. /* eslint-disable no-proto -- safe */
  29782. var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor');
  29783. var anObject = require('../internals/an-object');
  29784. var aPossiblePrototype = require('../internals/a-possible-prototype');
  29785. // `Object.setPrototypeOf` method
  29786. // https://tc39.es/ecma262/#sec-object.setprototypeof
  29787. // Works with __proto__ only. Old v8 can't work with null proto objects.
  29788. // eslint-disable-next-line es/no-object-setprototypeof -- safe
  29789. module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () {
  29790. var CORRECT_SETTER = false;
  29791. var test = {};
  29792. var setter;
  29793. try {
  29794. setter = uncurryThisAccessor(Object.prototype, '__proto__', 'set');
  29795. setter(test, []);
  29796. CORRECT_SETTER = test instanceof Array;
  29797. } catch (error) { /* empty */ }
  29798. return function setPrototypeOf(O, proto) {
  29799. anObject(O);
  29800. aPossiblePrototype(proto);
  29801. if (CORRECT_SETTER) setter(O, proto);
  29802. else O.__proto__ = proto;
  29803. return O;
  29804. };
  29805. }() : undefined);
  29806. },{"../internals/a-possible-prototype":224,"../internals/an-object":227,"../internals/function-uncurry-this-accessor":266}],319:[function(require,module,exports){
  29807. 'use strict';
  29808. var DESCRIPTORS = require('../internals/descriptors');
  29809. var fails = require('../internals/fails');
  29810. var uncurryThis = require('../internals/function-uncurry-this');
  29811. var objectGetPrototypeOf = require('../internals/object-get-prototype-of');
  29812. var objectKeys = require('../internals/object-keys');
  29813. var toIndexedObject = require('../internals/to-indexed-object');
  29814. var $propertyIsEnumerable = require('../internals/object-property-is-enumerable').f;
  29815. var propertyIsEnumerable = uncurryThis($propertyIsEnumerable);
  29816. var push = uncurryThis([].push);
  29817. // in some IE versions, `propertyIsEnumerable` returns incorrect result on integer keys
  29818. // of `null` prototype objects
  29819. var IE_BUG = DESCRIPTORS && fails(function () {
  29820. // eslint-disable-next-line es/no-object-create -- safe
  29821. var O = Object.create(null);
  29822. O[2] = 2;
  29823. return !propertyIsEnumerable(O, 2);
  29824. });
  29825. // `Object.{ entries, values }` methods implementation
  29826. var createMethod = function (TO_ENTRIES) {
  29827. return function (it) {
  29828. var O = toIndexedObject(it);
  29829. var keys = objectKeys(O);
  29830. var IE_WORKAROUND = IE_BUG && objectGetPrototypeOf(O) === null;
  29831. var length = keys.length;
  29832. var i = 0;
  29833. var result = [];
  29834. var key;
  29835. while (length > i) {
  29836. key = keys[i++];
  29837. if (!DESCRIPTORS || (IE_WORKAROUND ? key in O : propertyIsEnumerable(O, key))) {
  29838. push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
  29839. }
  29840. }
  29841. return result;
  29842. };
  29843. };
  29844. module.exports = {
  29845. // `Object.entries` method
  29846. // https://tc39.es/ecma262/#sec-object.entries
  29847. entries: createMethod(true),
  29848. // `Object.values` method
  29849. // https://tc39.es/ecma262/#sec-object.values
  29850. values: createMethod(false)
  29851. };
  29852. },{"../internals/descriptors":247,"../internals/fails":260,"../internals/function-uncurry-this":268,"../internals/object-get-prototype-of":313,"../internals/object-keys":316,"../internals/object-property-is-enumerable":317,"../internals/to-indexed-object":341}],320:[function(require,module,exports){
  29853. 'use strict';
  29854. var call = require('../internals/function-call');
  29855. var isCallable = require('../internals/is-callable');
  29856. var isObject = require('../internals/is-object');
  29857. var $TypeError = TypeError;
  29858. // `OrdinaryToPrimitive` abstract operation
  29859. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  29860. module.exports = function (input, pref) {
  29861. var fn, val;
  29862. if (pref === 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
  29863. if (isCallable(fn = input.valueOf) && !isObject(val = call(fn, input))) return val;
  29864. if (pref !== 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val;
  29865. throw new $TypeError("Can't convert object to primitive value");
  29866. };
  29867. },{"../internals/function-call":264,"../internals/is-callable":285,"../internals/is-object":289}],321:[function(require,module,exports){
  29868. 'use strict';
  29869. var getBuiltIn = require('../internals/get-built-in');
  29870. var uncurryThis = require('../internals/function-uncurry-this');
  29871. var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
  29872. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  29873. var anObject = require('../internals/an-object');
  29874. var concat = uncurryThis([].concat);
  29875. // all object keys, includes non-enumerable and symbols
  29876. module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  29877. var keys = getOwnPropertyNamesModule.f(anObject(it));
  29878. var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  29879. return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys;
  29880. };
  29881. },{"../internals/an-object":227,"../internals/function-uncurry-this":268,"../internals/get-built-in":269,"../internals/object-get-own-property-names":311,"../internals/object-get-own-property-symbols":312}],322:[function(require,module,exports){
  29882. 'use strict';
  29883. var global = require('../internals/global');
  29884. module.exports = global;
  29885. },{"../internals/global":274}],323:[function(require,module,exports){
  29886. 'use strict';
  29887. module.exports = function (exec) {
  29888. try {
  29889. return { error: false, value: exec() };
  29890. } catch (error) {
  29891. return { error: true, value: error };
  29892. }
  29893. };
  29894. },{}],324:[function(require,module,exports){
  29895. 'use strict';
  29896. var global = require('../internals/global');
  29897. var NativePromiseConstructor = require('../internals/promise-native-constructor');
  29898. var isCallable = require('../internals/is-callable');
  29899. var isForced = require('../internals/is-forced');
  29900. var inspectSource = require('../internals/inspect-source');
  29901. var wellKnownSymbol = require('../internals/well-known-symbol');
  29902. var IS_BROWSER = require('../internals/engine-is-browser');
  29903. var IS_DENO = require('../internals/engine-is-deno');
  29904. var IS_PURE = require('../internals/is-pure');
  29905. var V8_VERSION = require('../internals/engine-v8-version');
  29906. var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;
  29907. var SPECIES = wellKnownSymbol('species');
  29908. var SUBCLASSING = false;
  29909. var NATIVE_PROMISE_REJECTION_EVENT = isCallable(global.PromiseRejectionEvent);
  29910. var FORCED_PROMISE_CONSTRUCTOR = isForced('Promise', function () {
  29911. var PROMISE_CONSTRUCTOR_SOURCE = inspectSource(NativePromiseConstructor);
  29912. var GLOBAL_CORE_JS_PROMISE = PROMISE_CONSTRUCTOR_SOURCE !== String(NativePromiseConstructor);
  29913. // V8 6.6 (Node 10 and Chrome 66) have a bug with resolving custom thenables
  29914. // https://bugs.chromium.org/p/chromium/issues/detail?id=830565
  29915. // We can't detect it synchronously, so just check versions
  29916. if (!GLOBAL_CORE_JS_PROMISE && V8_VERSION === 66) return true;
  29917. // We need Promise#{ catch, finally } in the pure version for preventing prototype pollution
  29918. if (IS_PURE && !(NativePromisePrototype['catch'] && NativePromisePrototype['finally'])) return true;
  29919. // We can't use @@species feature detection in V8 since it causes
  29920. // deoptimization and performance degradation
  29921. // https://github.com/zloirock/core-js/issues/679
  29922. if (!V8_VERSION || V8_VERSION < 51 || !/native code/.test(PROMISE_CONSTRUCTOR_SOURCE)) {
  29923. // Detect correctness of subclassing with @@species support
  29924. var promise = new NativePromiseConstructor(function (resolve) { resolve(1); });
  29925. var FakePromise = function (exec) {
  29926. exec(function () { /* empty */ }, function () { /* empty */ });
  29927. };
  29928. var constructor = promise.constructor = {};
  29929. constructor[SPECIES] = FakePromise;
  29930. SUBCLASSING = promise.then(function () { /* empty */ }) instanceof FakePromise;
  29931. if (!SUBCLASSING) return true;
  29932. // Unhandled rejections tracking support, NodeJS Promise without it fails @@species test
  29933. } return !GLOBAL_CORE_JS_PROMISE && (IS_BROWSER || IS_DENO) && !NATIVE_PROMISE_REJECTION_EVENT;
  29934. });
  29935. module.exports = {
  29936. CONSTRUCTOR: FORCED_PROMISE_CONSTRUCTOR,
  29937. REJECTION_EVENT: NATIVE_PROMISE_REJECTION_EVENT,
  29938. SUBCLASSING: SUBCLASSING
  29939. };
  29940. },{"../internals/engine-is-browser":250,"../internals/engine-is-deno":251,"../internals/engine-v8-version":257,"../internals/global":274,"../internals/inspect-source":281,"../internals/is-callable":285,"../internals/is-forced":287,"../internals/is-pure":290,"../internals/promise-native-constructor":325,"../internals/well-known-symbol":357}],325:[function(require,module,exports){
  29941. 'use strict';
  29942. var global = require('../internals/global');
  29943. module.exports = global.Promise;
  29944. },{"../internals/global":274}],326:[function(require,module,exports){
  29945. 'use strict';
  29946. var anObject = require('../internals/an-object');
  29947. var isObject = require('../internals/is-object');
  29948. var newPromiseCapability = require('../internals/new-promise-capability');
  29949. module.exports = function (C, x) {
  29950. anObject(C);
  29951. if (isObject(x) && x.constructor === C) return x;
  29952. var promiseCapability = newPromiseCapability.f(C);
  29953. var resolve = promiseCapability.resolve;
  29954. resolve(x);
  29955. return promiseCapability.promise;
  29956. };
  29957. },{"../internals/an-object":227,"../internals/is-object":289,"../internals/new-promise-capability":303}],327:[function(require,module,exports){
  29958. 'use strict';
  29959. var NativePromiseConstructor = require('../internals/promise-native-constructor');
  29960. var checkCorrectnessOfIteration = require('../internals/check-correctness-of-iteration');
  29961. var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;
  29962. module.exports = FORCED_PROMISE_CONSTRUCTOR || !checkCorrectnessOfIteration(function (iterable) {
  29963. NativePromiseConstructor.all(iterable).then(undefined, function () { /* empty */ });
  29964. });
  29965. },{"../internals/check-correctness-of-iteration":234,"../internals/promise-constructor-detection":324,"../internals/promise-native-constructor":325}],328:[function(require,module,exports){
  29966. 'use strict';
  29967. var Queue = function () {
  29968. this.head = null;
  29969. this.tail = null;
  29970. };
  29971. Queue.prototype = {
  29972. add: function (item) {
  29973. var entry = { item: item, next: null };
  29974. var tail = this.tail;
  29975. if (tail) tail.next = entry;
  29976. else this.head = entry;
  29977. this.tail = entry;
  29978. },
  29979. get: function () {
  29980. var entry = this.head;
  29981. if (entry) {
  29982. var next = this.head = entry.next;
  29983. if (next === null) this.tail = null;
  29984. return entry.item;
  29985. }
  29986. }
  29987. };
  29988. module.exports = Queue;
  29989. },{}],329:[function(require,module,exports){
  29990. 'use strict';
  29991. var isNullOrUndefined = require('../internals/is-null-or-undefined');
  29992. var $TypeError = TypeError;
  29993. // `RequireObjectCoercible` abstract operation
  29994. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  29995. module.exports = function (it) {
  29996. if (isNullOrUndefined(it)) throw new $TypeError("Can't call method on " + it);
  29997. return it;
  29998. };
  29999. },{"../internals/is-null-or-undefined":288}],330:[function(require,module,exports){
  30000. 'use strict';
  30001. var getBuiltIn = require('../internals/get-built-in');
  30002. var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
  30003. var wellKnownSymbol = require('../internals/well-known-symbol');
  30004. var DESCRIPTORS = require('../internals/descriptors');
  30005. var SPECIES = wellKnownSymbol('species');
  30006. module.exports = function (CONSTRUCTOR_NAME) {
  30007. var Constructor = getBuiltIn(CONSTRUCTOR_NAME);
  30008. if (DESCRIPTORS && Constructor && !Constructor[SPECIES]) {
  30009. defineBuiltInAccessor(Constructor, SPECIES, {
  30010. configurable: true,
  30011. get: function () { return this; }
  30012. });
  30013. }
  30014. };
  30015. },{"../internals/define-built-in-accessor":244,"../internals/descriptors":247,"../internals/get-built-in":269,"../internals/well-known-symbol":357}],331:[function(require,module,exports){
  30016. 'use strict';
  30017. var defineProperty = require('../internals/object-define-property').f;
  30018. var hasOwn = require('../internals/has-own-property');
  30019. var wellKnownSymbol = require('../internals/well-known-symbol');
  30020. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  30021. module.exports = function (target, TAG, STATIC) {
  30022. if (target && !STATIC) target = target.prototype;
  30023. if (target && !hasOwn(target, TO_STRING_TAG)) {
  30024. defineProperty(target, TO_STRING_TAG, { configurable: true, value: TAG });
  30025. }
  30026. };
  30027. },{"../internals/has-own-property":275,"../internals/object-define-property":308,"../internals/well-known-symbol":357}],332:[function(require,module,exports){
  30028. 'use strict';
  30029. var shared = require('../internals/shared');
  30030. var uid = require('../internals/uid');
  30031. var keys = shared('keys');
  30032. module.exports = function (key) {
  30033. return keys[key] || (keys[key] = uid(key));
  30034. };
  30035. },{"../internals/shared":334,"../internals/uid":350}],333:[function(require,module,exports){
  30036. 'use strict';
  30037. var global = require('../internals/global');
  30038. var defineGlobalProperty = require('../internals/define-global-property');
  30039. var SHARED = '__core-js_shared__';
  30040. var store = global[SHARED] || defineGlobalProperty(SHARED, {});
  30041. module.exports = store;
  30042. },{"../internals/define-global-property":246,"../internals/global":274}],334:[function(require,module,exports){
  30043. 'use strict';
  30044. var IS_PURE = require('../internals/is-pure');
  30045. var store = require('../internals/shared-store');
  30046. (module.exports = function (key, value) {
  30047. return store[key] || (store[key] = value !== undefined ? value : {});
  30048. })('versions', []).push({
  30049. version: '3.33.0',
  30050. mode: IS_PURE ? 'pure' : 'global',
  30051. copyright: '© 2014-2023 Denis Pushkarev (zloirock.ru)',
  30052. license: 'https://github.com/zloirock/core-js/blob/v3.33.0/LICENSE',
  30053. source: 'https://github.com/zloirock/core-js'
  30054. });
  30055. },{"../internals/is-pure":290,"../internals/shared-store":333}],335:[function(require,module,exports){
  30056. 'use strict';
  30057. var anObject = require('../internals/an-object');
  30058. var aConstructor = require('../internals/a-constructor');
  30059. var isNullOrUndefined = require('../internals/is-null-or-undefined');
  30060. var wellKnownSymbol = require('../internals/well-known-symbol');
  30061. var SPECIES = wellKnownSymbol('species');
  30062. // `SpeciesConstructor` abstract operation
  30063. // https://tc39.es/ecma262/#sec-speciesconstructor
  30064. module.exports = function (O, defaultConstructor) {
  30065. var C = anObject(O).constructor;
  30066. var S;
  30067. return C === undefined || isNullOrUndefined(S = anObject(C)[SPECIES]) ? defaultConstructor : aConstructor(S);
  30068. };
  30069. },{"../internals/a-constructor":223,"../internals/an-object":227,"../internals/is-null-or-undefined":288,"../internals/well-known-symbol":357}],336:[function(require,module,exports){
  30070. 'use strict';
  30071. /* eslint-disable es/no-symbol -- required for testing */
  30072. var V8_VERSION = require('../internals/engine-v8-version');
  30073. var fails = require('../internals/fails');
  30074. var global = require('../internals/global');
  30075. var $String = global.String;
  30076. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  30077. module.exports = !!Object.getOwnPropertySymbols && !fails(function () {
  30078. var symbol = Symbol('symbol detection');
  30079. // Chrome 38 Symbol has incorrect toString conversion
  30080. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  30081. // nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will,
  30082. // of course, fail.
  30083. return !$String(symbol) || !(Object(symbol) instanceof Symbol) ||
  30084. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  30085. !Symbol.sham && V8_VERSION && V8_VERSION < 41;
  30086. });
  30087. },{"../internals/engine-v8-version":257,"../internals/fails":260,"../internals/global":274}],337:[function(require,module,exports){
  30088. 'use strict';
  30089. var call = require('../internals/function-call');
  30090. var getBuiltIn = require('../internals/get-built-in');
  30091. var wellKnownSymbol = require('../internals/well-known-symbol');
  30092. var defineBuiltIn = require('../internals/define-built-in');
  30093. module.exports = function () {
  30094. var Symbol = getBuiltIn('Symbol');
  30095. var SymbolPrototype = Symbol && Symbol.prototype;
  30096. var valueOf = SymbolPrototype && SymbolPrototype.valueOf;
  30097. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  30098. if (SymbolPrototype && !SymbolPrototype[TO_PRIMITIVE]) {
  30099. // `Symbol.prototype[@@toPrimitive]` method
  30100. // https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
  30101. // eslint-disable-next-line no-unused-vars -- required for .length
  30102. defineBuiltIn(SymbolPrototype, TO_PRIMITIVE, function (hint) {
  30103. return call(valueOf, this);
  30104. }, { arity: 1 });
  30105. }
  30106. };
  30107. },{"../internals/define-built-in":245,"../internals/function-call":264,"../internals/get-built-in":269,"../internals/well-known-symbol":357}],338:[function(require,module,exports){
  30108. 'use strict';
  30109. var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
  30110. /* eslint-disable es/no-symbol -- safe */
  30111. module.exports = NATIVE_SYMBOL && !!Symbol['for'] && !!Symbol.keyFor;
  30112. },{"../internals/symbol-constructor-detection":336}],339:[function(require,module,exports){
  30113. 'use strict';
  30114. var global = require('../internals/global');
  30115. var apply = require('../internals/function-apply');
  30116. var bind = require('../internals/function-bind-context');
  30117. var isCallable = require('../internals/is-callable');
  30118. var hasOwn = require('../internals/has-own-property');
  30119. var fails = require('../internals/fails');
  30120. var html = require('../internals/html');
  30121. var arraySlice = require('../internals/array-slice');
  30122. var createElement = require('../internals/document-create-element');
  30123. var validateArgumentsLength = require('../internals/validate-arguments-length');
  30124. var IS_IOS = require('../internals/engine-is-ios');
  30125. var IS_NODE = require('../internals/engine-is-node');
  30126. var set = global.setImmediate;
  30127. var clear = global.clearImmediate;
  30128. var process = global.process;
  30129. var Dispatch = global.Dispatch;
  30130. var Function = global.Function;
  30131. var MessageChannel = global.MessageChannel;
  30132. var String = global.String;
  30133. var counter = 0;
  30134. var queue = {};
  30135. var ONREADYSTATECHANGE = 'onreadystatechange';
  30136. var $location, defer, channel, port;
  30137. fails(function () {
  30138. // Deno throws a ReferenceError on `location` access without `--location` flag
  30139. $location = global.location;
  30140. });
  30141. var run = function (id) {
  30142. if (hasOwn(queue, id)) {
  30143. var fn = queue[id];
  30144. delete queue[id];
  30145. fn();
  30146. }
  30147. };
  30148. var runner = function (id) {
  30149. return function () {
  30150. run(id);
  30151. };
  30152. };
  30153. var eventListener = function (event) {
  30154. run(event.data);
  30155. };
  30156. var globalPostMessageDefer = function (id) {
  30157. // old engines have not location.origin
  30158. global.postMessage(String(id), $location.protocol + '//' + $location.host);
  30159. };
  30160. // Node.js 0.9+ & IE10+ has setImmediate, otherwise:
  30161. if (!set || !clear) {
  30162. set = function setImmediate(handler) {
  30163. validateArgumentsLength(arguments.length, 1);
  30164. var fn = isCallable(handler) ? handler : Function(handler);
  30165. var args = arraySlice(arguments, 1);
  30166. queue[++counter] = function () {
  30167. apply(fn, undefined, args);
  30168. };
  30169. defer(counter);
  30170. return counter;
  30171. };
  30172. clear = function clearImmediate(id) {
  30173. delete queue[id];
  30174. };
  30175. // Node.js 0.8-
  30176. if (IS_NODE) {
  30177. defer = function (id) {
  30178. process.nextTick(runner(id));
  30179. };
  30180. // Sphere (JS game engine) Dispatch API
  30181. } else if (Dispatch && Dispatch.now) {
  30182. defer = function (id) {
  30183. Dispatch.now(runner(id));
  30184. };
  30185. // Browsers with MessageChannel, includes WebWorkers
  30186. // except iOS - https://github.com/zloirock/core-js/issues/624
  30187. } else if (MessageChannel && !IS_IOS) {
  30188. channel = new MessageChannel();
  30189. port = channel.port2;
  30190. channel.port1.onmessage = eventListener;
  30191. defer = bind(port.postMessage, port);
  30192. // Browsers with postMessage, skip WebWorkers
  30193. // IE8 has postMessage, but it's sync & typeof its postMessage is 'object'
  30194. } else if (
  30195. global.addEventListener &&
  30196. isCallable(global.postMessage) &&
  30197. !global.importScripts &&
  30198. $location && $location.protocol !== 'file:' &&
  30199. !fails(globalPostMessageDefer)
  30200. ) {
  30201. defer = globalPostMessageDefer;
  30202. global.addEventListener('message', eventListener, false);
  30203. // IE8-
  30204. } else if (ONREADYSTATECHANGE in createElement('script')) {
  30205. defer = function (id) {
  30206. html.appendChild(createElement('script'))[ONREADYSTATECHANGE] = function () {
  30207. html.removeChild(this);
  30208. run(id);
  30209. };
  30210. };
  30211. // Rest old browsers
  30212. } else {
  30213. defer = function (id) {
  30214. setTimeout(runner(id), 0);
  30215. };
  30216. }
  30217. }
  30218. module.exports = {
  30219. set: set,
  30220. clear: clear
  30221. };
  30222. },{"../internals/array-slice":231,"../internals/document-create-element":249,"../internals/engine-is-ios":253,"../internals/engine-is-node":254,"../internals/fails":260,"../internals/function-apply":261,"../internals/function-bind-context":262,"../internals/global":274,"../internals/has-own-property":275,"../internals/html":278,"../internals/is-callable":285,"../internals/validate-arguments-length":353}],340:[function(require,module,exports){
  30223. 'use strict';
  30224. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  30225. var max = Math.max;
  30226. var min = Math.min;
  30227. // Helper for a popular repeating case of the spec:
  30228. // Let integer be ? ToInteger(index).
  30229. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  30230. module.exports = function (index, length) {
  30231. var integer = toIntegerOrInfinity(index);
  30232. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  30233. };
  30234. },{"../internals/to-integer-or-infinity":342}],341:[function(require,module,exports){
  30235. 'use strict';
  30236. // toObject with fallback for non-array-like ES3 strings
  30237. var IndexedObject = require('../internals/indexed-object');
  30238. var requireObjectCoercible = require('../internals/require-object-coercible');
  30239. module.exports = function (it) {
  30240. return IndexedObject(requireObjectCoercible(it));
  30241. };
  30242. },{"../internals/indexed-object":280,"../internals/require-object-coercible":329}],342:[function(require,module,exports){
  30243. 'use strict';
  30244. var trunc = require('../internals/math-trunc');
  30245. // `ToIntegerOrInfinity` abstract operation
  30246. // https://tc39.es/ecma262/#sec-tointegerorinfinity
  30247. module.exports = function (argument) {
  30248. var number = +argument;
  30249. // eslint-disable-next-line no-self-compare -- NaN check
  30250. return number !== number || number === 0 ? 0 : trunc(number);
  30251. };
  30252. },{"../internals/math-trunc":301}],343:[function(require,module,exports){
  30253. 'use strict';
  30254. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  30255. var min = Math.min;
  30256. // `ToLength` abstract operation
  30257. // https://tc39.es/ecma262/#sec-tolength
  30258. module.exports = function (argument) {
  30259. return argument > 0 ? min(toIntegerOrInfinity(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  30260. };
  30261. },{"../internals/to-integer-or-infinity":342}],344:[function(require,module,exports){
  30262. 'use strict';
  30263. var requireObjectCoercible = require('../internals/require-object-coercible');
  30264. var $Object = Object;
  30265. // `ToObject` abstract operation
  30266. // https://tc39.es/ecma262/#sec-toobject
  30267. module.exports = function (argument) {
  30268. return $Object(requireObjectCoercible(argument));
  30269. };
  30270. },{"../internals/require-object-coercible":329}],345:[function(require,module,exports){
  30271. 'use strict';
  30272. var call = require('../internals/function-call');
  30273. var isObject = require('../internals/is-object');
  30274. var isSymbol = require('../internals/is-symbol');
  30275. var getMethod = require('../internals/get-method');
  30276. var ordinaryToPrimitive = require('../internals/ordinary-to-primitive');
  30277. var wellKnownSymbol = require('../internals/well-known-symbol');
  30278. var $TypeError = TypeError;
  30279. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  30280. // `ToPrimitive` abstract operation
  30281. // https://tc39.es/ecma262/#sec-toprimitive
  30282. module.exports = function (input, pref) {
  30283. if (!isObject(input) || isSymbol(input)) return input;
  30284. var exoticToPrim = getMethod(input, TO_PRIMITIVE);
  30285. var result;
  30286. if (exoticToPrim) {
  30287. if (pref === undefined) pref = 'default';
  30288. result = call(exoticToPrim, input, pref);
  30289. if (!isObject(result) || isSymbol(result)) return result;
  30290. throw new $TypeError("Can't convert object to primitive value");
  30291. }
  30292. if (pref === undefined) pref = 'number';
  30293. return ordinaryToPrimitive(input, pref);
  30294. };
  30295. },{"../internals/function-call":264,"../internals/get-method":273,"../internals/is-object":289,"../internals/is-symbol":292,"../internals/ordinary-to-primitive":320,"../internals/well-known-symbol":357}],346:[function(require,module,exports){
  30296. 'use strict';
  30297. var toPrimitive = require('../internals/to-primitive');
  30298. var isSymbol = require('../internals/is-symbol');
  30299. // `ToPropertyKey` abstract operation
  30300. // https://tc39.es/ecma262/#sec-topropertykey
  30301. module.exports = function (argument) {
  30302. var key = toPrimitive(argument, 'string');
  30303. return isSymbol(key) ? key : key + '';
  30304. };
  30305. },{"../internals/is-symbol":292,"../internals/to-primitive":345}],347:[function(require,module,exports){
  30306. 'use strict';
  30307. var wellKnownSymbol = require('../internals/well-known-symbol');
  30308. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  30309. var test = {};
  30310. test[TO_STRING_TAG] = 'z';
  30311. module.exports = String(test) === '[object z]';
  30312. },{"../internals/well-known-symbol":357}],348:[function(require,module,exports){
  30313. 'use strict';
  30314. var classof = require('../internals/classof');
  30315. var $String = String;
  30316. module.exports = function (argument) {
  30317. if (classof(argument) === 'Symbol') throw new TypeError('Cannot convert a Symbol value to a string');
  30318. return $String(argument);
  30319. };
  30320. },{"../internals/classof":236}],349:[function(require,module,exports){
  30321. 'use strict';
  30322. var $String = String;
  30323. module.exports = function (argument) {
  30324. try {
  30325. return $String(argument);
  30326. } catch (error) {
  30327. return 'Object';
  30328. }
  30329. };
  30330. },{}],350:[function(require,module,exports){
  30331. 'use strict';
  30332. var uncurryThis = require('../internals/function-uncurry-this');
  30333. var id = 0;
  30334. var postfix = Math.random();
  30335. var toString = uncurryThis(1.0.toString);
  30336. module.exports = function (key) {
  30337. return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36);
  30338. };
  30339. },{"../internals/function-uncurry-this":268}],351:[function(require,module,exports){
  30340. 'use strict';
  30341. /* eslint-disable es/no-symbol -- required for testing */
  30342. var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
  30343. module.exports = NATIVE_SYMBOL
  30344. && !Symbol.sham
  30345. && typeof Symbol.iterator == 'symbol';
  30346. },{"../internals/symbol-constructor-detection":336}],352:[function(require,module,exports){
  30347. 'use strict';
  30348. var DESCRIPTORS = require('../internals/descriptors');
  30349. var fails = require('../internals/fails');
  30350. // V8 ~ Chrome 36-
  30351. // https://bugs.chromium.org/p/v8/issues/detail?id=3334
  30352. module.exports = DESCRIPTORS && fails(function () {
  30353. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  30354. return Object.defineProperty(function () { /* empty */ }, 'prototype', {
  30355. value: 42,
  30356. writable: false
  30357. }).prototype !== 42;
  30358. });
  30359. },{"../internals/descriptors":247,"../internals/fails":260}],353:[function(require,module,exports){
  30360. 'use strict';
  30361. var $TypeError = TypeError;
  30362. module.exports = function (passed, required) {
  30363. if (passed < required) throw new $TypeError('Not enough arguments');
  30364. return passed;
  30365. };
  30366. },{}],354:[function(require,module,exports){
  30367. 'use strict';
  30368. var global = require('../internals/global');
  30369. var isCallable = require('../internals/is-callable');
  30370. var WeakMap = global.WeakMap;
  30371. module.exports = isCallable(WeakMap) && /native code/.test(String(WeakMap));
  30372. },{"../internals/global":274,"../internals/is-callable":285}],355:[function(require,module,exports){
  30373. 'use strict';
  30374. var path = require('../internals/path');
  30375. var hasOwn = require('../internals/has-own-property');
  30376. var wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');
  30377. var defineProperty = require('../internals/object-define-property').f;
  30378. module.exports = function (NAME) {
  30379. var Symbol = path.Symbol || (path.Symbol = {});
  30380. if (!hasOwn(Symbol, NAME)) defineProperty(Symbol, NAME, {
  30381. value: wrappedWellKnownSymbolModule.f(NAME)
  30382. });
  30383. };
  30384. },{"../internals/has-own-property":275,"../internals/object-define-property":308,"../internals/path":322,"../internals/well-known-symbol-wrapped":356}],356:[function(require,module,exports){
  30385. 'use strict';
  30386. var wellKnownSymbol = require('../internals/well-known-symbol');
  30387. exports.f = wellKnownSymbol;
  30388. },{"../internals/well-known-symbol":357}],357:[function(require,module,exports){
  30389. 'use strict';
  30390. var global = require('../internals/global');
  30391. var shared = require('../internals/shared');
  30392. var hasOwn = require('../internals/has-own-property');
  30393. var uid = require('../internals/uid');
  30394. var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
  30395. var USE_SYMBOL_AS_UID = require('../internals/use-symbol-as-uid');
  30396. var Symbol = global.Symbol;
  30397. var WellKnownSymbolsStore = shared('wks');
  30398. var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol['for'] || Symbol : Symbol && Symbol.withoutSetter || uid;
  30399. module.exports = function (name) {
  30400. if (!hasOwn(WellKnownSymbolsStore, name)) {
  30401. WellKnownSymbolsStore[name] = NATIVE_SYMBOL && hasOwn(Symbol, name)
  30402. ? Symbol[name]
  30403. : createWellKnownSymbol('Symbol.' + name);
  30404. } return WellKnownSymbolsStore[name];
  30405. };
  30406. },{"../internals/global":274,"../internals/has-own-property":275,"../internals/shared":334,"../internals/symbol-constructor-detection":336,"../internals/uid":350,"../internals/use-symbol-as-uid":351}],358:[function(require,module,exports){
  30407. 'use strict';
  30408. var $ = require('../internals/export');
  30409. var $findIndex = require('../internals/array-iteration').findIndex;
  30410. var addToUnscopables = require('../internals/add-to-unscopables');
  30411. var FIND_INDEX = 'findIndex';
  30412. var SKIPS_HOLES = true;
  30413. // Shouldn't skip holes
  30414. // eslint-disable-next-line es/no-array-prototype-findindex -- testing
  30415. if (FIND_INDEX in []) Array(1)[FIND_INDEX](function () { SKIPS_HOLES = false; });
  30416. // `Array.prototype.findIndex` method
  30417. // https://tc39.es/ecma262/#sec-array.prototype.findindex
  30418. $({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
  30419. findIndex: function findIndex(callbackfn /* , that = undefined */) {
  30420. return $findIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  30421. }
  30422. });
  30423. // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
  30424. addToUnscopables(FIND_INDEX);
  30425. },{"../internals/add-to-unscopables":225,"../internals/array-iteration":229,"../internals/export":259}],359:[function(require,module,exports){
  30426. 'use strict';
  30427. var $ = require('../internals/export');
  30428. var $find = require('../internals/array-iteration').find;
  30429. var addToUnscopables = require('../internals/add-to-unscopables');
  30430. var FIND = 'find';
  30431. var SKIPS_HOLES = true;
  30432. // Shouldn't skip holes
  30433. // eslint-disable-next-line es/no-array-prototype-find -- testing
  30434. if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
  30435. // `Array.prototype.find` method
  30436. // https://tc39.es/ecma262/#sec-array.prototype.find
  30437. $({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
  30438. find: function find(callbackfn /* , that = undefined */) {
  30439. return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  30440. }
  30441. });
  30442. // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
  30443. addToUnscopables(FIND);
  30444. },{"../internals/add-to-unscopables":225,"../internals/array-iteration":229,"../internals/export":259}],360:[function(require,module,exports){
  30445. 'use strict';
  30446. var $ = require('../internals/export');
  30447. var $includes = require('../internals/array-includes').includes;
  30448. var fails = require('../internals/fails');
  30449. var addToUnscopables = require('../internals/add-to-unscopables');
  30450. // FF99+ bug
  30451. var BROKEN_ON_SPARSE = fails(function () {
  30452. // eslint-disable-next-line es/no-array-prototype-includes -- detection
  30453. return !Array(1).includes();
  30454. });
  30455. // `Array.prototype.includes` method
  30456. // https://tc39.es/ecma262/#sec-array.prototype.includes
  30457. $({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
  30458. includes: function includes(el /* , fromIndex = 0 */) {
  30459. return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
  30460. }
  30461. });
  30462. // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
  30463. addToUnscopables('includes');
  30464. },{"../internals/add-to-unscopables":225,"../internals/array-includes":228,"../internals/export":259,"../internals/fails":260}],361:[function(require,module,exports){
  30465. 'use strict';
  30466. var toIndexedObject = require('../internals/to-indexed-object');
  30467. var addToUnscopables = require('../internals/add-to-unscopables');
  30468. var Iterators = require('../internals/iterators');
  30469. var InternalStateModule = require('../internals/internal-state');
  30470. var defineProperty = require('../internals/object-define-property').f;
  30471. var defineIterator = require('../internals/iterator-define');
  30472. var createIterResultObject = require('../internals/create-iter-result-object');
  30473. var IS_PURE = require('../internals/is-pure');
  30474. var DESCRIPTORS = require('../internals/descriptors');
  30475. var ARRAY_ITERATOR = 'Array Iterator';
  30476. var setInternalState = InternalStateModule.set;
  30477. var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR);
  30478. // `Array.prototype.entries` method
  30479. // https://tc39.es/ecma262/#sec-array.prototype.entries
  30480. // `Array.prototype.keys` method
  30481. // https://tc39.es/ecma262/#sec-array.prototype.keys
  30482. // `Array.prototype.values` method
  30483. // https://tc39.es/ecma262/#sec-array.prototype.values
  30484. // `Array.prototype[@@iterator]` method
  30485. // https://tc39.es/ecma262/#sec-array.prototype-@@iterator
  30486. // `CreateArrayIterator` internal method
  30487. // https://tc39.es/ecma262/#sec-createarrayiterator
  30488. module.exports = defineIterator(Array, 'Array', function (iterated, kind) {
  30489. setInternalState(this, {
  30490. type: ARRAY_ITERATOR,
  30491. target: toIndexedObject(iterated), // target
  30492. index: 0, // next index
  30493. kind: kind // kind
  30494. });
  30495. // `%ArrayIteratorPrototype%.next` method
  30496. // https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
  30497. }, function () {
  30498. var state = getInternalState(this);
  30499. var target = state.target;
  30500. var kind = state.kind;
  30501. var index = state.index++;
  30502. if (!target || index >= target.length) {
  30503. state.target = undefined;
  30504. return createIterResultObject(undefined, true);
  30505. }
  30506. switch (kind) {
  30507. case 'keys': return createIterResultObject(index, false);
  30508. case 'values': return createIterResultObject(target[index], false);
  30509. } return createIterResultObject([index, target[index]], false);
  30510. }, 'values');
  30511. // argumentsList[@@iterator] is %ArrayProto_values%
  30512. // https://tc39.es/ecma262/#sec-createunmappedargumentsobject
  30513. // https://tc39.es/ecma262/#sec-createmappedargumentsobject
  30514. var values = Iterators.Arguments = Iterators.Array;
  30515. // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
  30516. addToUnscopables('keys');
  30517. addToUnscopables('values');
  30518. addToUnscopables('entries');
  30519. // V8 ~ Chrome 45- bug
  30520. if (!IS_PURE && DESCRIPTORS && values.name !== 'values') try {
  30521. defineProperty(values, 'name', { value: 'values' });
  30522. } catch (error) { /* empty */ }
  30523. },{"../internals/add-to-unscopables":225,"../internals/create-iter-result-object":240,"../internals/descriptors":247,"../internals/internal-state":282,"../internals/is-pure":290,"../internals/iterator-define":296,"../internals/iterators":298,"../internals/object-define-property":308,"../internals/to-indexed-object":341}],362:[function(require,module,exports){
  30524. 'use strict';
  30525. var $ = require('../internals/export');
  30526. var getBuiltIn = require('../internals/get-built-in');
  30527. var apply = require('../internals/function-apply');
  30528. var call = require('../internals/function-call');
  30529. var uncurryThis = require('../internals/function-uncurry-this');
  30530. var fails = require('../internals/fails');
  30531. var isCallable = require('../internals/is-callable');
  30532. var isSymbol = require('../internals/is-symbol');
  30533. var arraySlice = require('../internals/array-slice');
  30534. var getReplacerFunction = require('../internals/get-json-replacer-function');
  30535. var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
  30536. var $String = String;
  30537. var $stringify = getBuiltIn('JSON', 'stringify');
  30538. var exec = uncurryThis(/./.exec);
  30539. var charAt = uncurryThis(''.charAt);
  30540. var charCodeAt = uncurryThis(''.charCodeAt);
  30541. var replace = uncurryThis(''.replace);
  30542. var numberToString = uncurryThis(1.0.toString);
  30543. var tester = /[\uD800-\uDFFF]/g;
  30544. var low = /^[\uD800-\uDBFF]$/;
  30545. var hi = /^[\uDC00-\uDFFF]$/;
  30546. var WRONG_SYMBOLS_CONVERSION = !NATIVE_SYMBOL || fails(function () {
  30547. var symbol = getBuiltIn('Symbol')('stringify detection');
  30548. // MS Edge converts symbol values to JSON as {}
  30549. return $stringify([symbol]) !== '[null]'
  30550. // WebKit converts symbol values to JSON as null
  30551. || $stringify({ a: symbol }) !== '{}'
  30552. // V8 throws on boxed symbols
  30553. || $stringify(Object(symbol)) !== '{}';
  30554. });
  30555. // https://github.com/tc39/proposal-well-formed-stringify
  30556. var ILL_FORMED_UNICODE = fails(function () {
  30557. return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
  30558. || $stringify('\uDEAD') !== '"\\udead"';
  30559. });
  30560. var stringifyWithSymbolsFix = function (it, replacer) {
  30561. var args = arraySlice(arguments);
  30562. var $replacer = getReplacerFunction(replacer);
  30563. if (!isCallable($replacer) && (it === undefined || isSymbol(it))) return; // IE8 returns string on undefined
  30564. args[1] = function (key, value) {
  30565. // some old implementations (like WebKit) could pass numbers as keys
  30566. if (isCallable($replacer)) value = call($replacer, this, $String(key), value);
  30567. if (!isSymbol(value)) return value;
  30568. };
  30569. return apply($stringify, null, args);
  30570. };
  30571. var fixIllFormed = function (match, offset, string) {
  30572. var prev = charAt(string, offset - 1);
  30573. var next = charAt(string, offset + 1);
  30574. if ((exec(low, match) && !exec(hi, next)) || (exec(hi, match) && !exec(low, prev))) {
  30575. return '\\u' + numberToString(charCodeAt(match, 0), 16);
  30576. } return match;
  30577. };
  30578. if ($stringify) {
  30579. // `JSON.stringify` method
  30580. // https://tc39.es/ecma262/#sec-json.stringify
  30581. $({ target: 'JSON', stat: true, arity: 3, forced: WRONG_SYMBOLS_CONVERSION || ILL_FORMED_UNICODE }, {
  30582. // eslint-disable-next-line no-unused-vars -- required for `.length`
  30583. stringify: function stringify(it, replacer, space) {
  30584. var args = arraySlice(arguments);
  30585. var result = apply(WRONG_SYMBOLS_CONVERSION ? stringifyWithSymbolsFix : $stringify, null, args);
  30586. return ILL_FORMED_UNICODE && typeof result == 'string' ? replace(result, tester, fixIllFormed) : result;
  30587. }
  30588. });
  30589. }
  30590. },{"../internals/array-slice":231,"../internals/export":259,"../internals/fails":260,"../internals/function-apply":261,"../internals/function-call":264,"../internals/function-uncurry-this":268,"../internals/get-built-in":269,"../internals/get-json-replacer-function":272,"../internals/is-callable":285,"../internals/is-symbol":292,"../internals/symbol-constructor-detection":336}],363:[function(require,module,exports){
  30591. 'use strict';
  30592. var $ = require('../internals/export');
  30593. // `Number.isNaN` method
  30594. // https://tc39.es/ecma262/#sec-number.isnan
  30595. $({ target: 'Number', stat: true }, {
  30596. isNaN: function isNaN(number) {
  30597. // eslint-disable-next-line no-self-compare -- NaN check
  30598. return number !== number;
  30599. }
  30600. });
  30601. },{"../internals/export":259}],364:[function(require,module,exports){
  30602. 'use strict';
  30603. var $ = require('../internals/export');
  30604. var assign = require('../internals/object-assign');
  30605. // `Object.assign` method
  30606. // https://tc39.es/ecma262/#sec-object.assign
  30607. // eslint-disable-next-line es/no-object-assign -- required for testing
  30608. $({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }, {
  30609. assign: assign
  30610. });
  30611. },{"../internals/export":259,"../internals/object-assign":305}],365:[function(require,module,exports){
  30612. 'use strict';
  30613. var $ = require('../internals/export');
  30614. var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
  30615. var fails = require('../internals/fails');
  30616. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  30617. var toObject = require('../internals/to-object');
  30618. // V8 ~ Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
  30619. // https://bugs.chromium.org/p/v8/issues/detail?id=3443
  30620. var FORCED = !NATIVE_SYMBOL || fails(function () { getOwnPropertySymbolsModule.f(1); });
  30621. // `Object.getOwnPropertySymbols` method
  30622. // https://tc39.es/ecma262/#sec-object.getownpropertysymbols
  30623. $({ target: 'Object', stat: true, forced: FORCED }, {
  30624. getOwnPropertySymbols: function getOwnPropertySymbols(it) {
  30625. var $getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
  30626. return $getOwnPropertySymbols ? $getOwnPropertySymbols(toObject(it)) : [];
  30627. }
  30628. });
  30629. },{"../internals/export":259,"../internals/fails":260,"../internals/object-get-own-property-symbols":312,"../internals/symbol-constructor-detection":336,"../internals/to-object":344}],366:[function(require,module,exports){
  30630. 'use strict';
  30631. var $ = require('../internals/export');
  30632. var toObject = require('../internals/to-object');
  30633. var nativeKeys = require('../internals/object-keys');
  30634. var fails = require('../internals/fails');
  30635. var FAILS_ON_PRIMITIVES = fails(function () { nativeKeys(1); });
  30636. // `Object.keys` method
  30637. // https://tc39.es/ecma262/#sec-object.keys
  30638. $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
  30639. keys: function keys(it) {
  30640. return nativeKeys(toObject(it));
  30641. }
  30642. });
  30643. },{"../internals/export":259,"../internals/fails":260,"../internals/object-keys":316,"../internals/to-object":344}],367:[function(require,module,exports){
  30644. 'use strict';
  30645. var $ = require('../internals/export');
  30646. var $values = require('../internals/object-to-array').values;
  30647. // `Object.values` method
  30648. // https://tc39.es/ecma262/#sec-object.values
  30649. $({ target: 'Object', stat: true }, {
  30650. values: function values(O) {
  30651. return $values(O);
  30652. }
  30653. });
  30654. },{"../internals/export":259,"../internals/object-to-array":319}],368:[function(require,module,exports){
  30655. 'use strict';
  30656. var $ = require('../internals/export');
  30657. var call = require('../internals/function-call');
  30658. var aCallable = require('../internals/a-callable');
  30659. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  30660. var perform = require('../internals/perform');
  30661. var iterate = require('../internals/iterate');
  30662. var PROMISE_STATICS_INCORRECT_ITERATION = require('../internals/promise-statics-incorrect-iteration');
  30663. // `Promise.all` method
  30664. // https://tc39.es/ecma262/#sec-promise.all
  30665. $({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, {
  30666. all: function all(iterable) {
  30667. var C = this;
  30668. var capability = newPromiseCapabilityModule.f(C);
  30669. var resolve = capability.resolve;
  30670. var reject = capability.reject;
  30671. var result = perform(function () {
  30672. var $promiseResolve = aCallable(C.resolve);
  30673. var values = [];
  30674. var counter = 0;
  30675. var remaining = 1;
  30676. iterate(iterable, function (promise) {
  30677. var index = counter++;
  30678. var alreadyCalled = false;
  30679. remaining++;
  30680. call($promiseResolve, C, promise).then(function (value) {
  30681. if (alreadyCalled) return;
  30682. alreadyCalled = true;
  30683. values[index] = value;
  30684. --remaining || resolve(values);
  30685. }, reject);
  30686. });
  30687. --remaining || resolve(values);
  30688. });
  30689. if (result.error) reject(result.value);
  30690. return capability.promise;
  30691. }
  30692. });
  30693. },{"../internals/a-callable":222,"../internals/export":259,"../internals/function-call":264,"../internals/iterate":293,"../internals/new-promise-capability":303,"../internals/perform":323,"../internals/promise-statics-incorrect-iteration":327}],369:[function(require,module,exports){
  30694. 'use strict';
  30695. var $ = require('../internals/export');
  30696. var IS_PURE = require('../internals/is-pure');
  30697. var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;
  30698. var NativePromiseConstructor = require('../internals/promise-native-constructor');
  30699. var getBuiltIn = require('../internals/get-built-in');
  30700. var isCallable = require('../internals/is-callable');
  30701. var defineBuiltIn = require('../internals/define-built-in');
  30702. var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;
  30703. // `Promise.prototype.catch` method
  30704. // https://tc39.es/ecma262/#sec-promise.prototype.catch
  30705. $({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR, real: true }, {
  30706. 'catch': function (onRejected) {
  30707. return this.then(undefined, onRejected);
  30708. }
  30709. });
  30710. // makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then`
  30711. if (!IS_PURE && isCallable(NativePromiseConstructor)) {
  30712. var method = getBuiltIn('Promise').prototype['catch'];
  30713. if (NativePromisePrototype['catch'] !== method) {
  30714. defineBuiltIn(NativePromisePrototype, 'catch', method, { unsafe: true });
  30715. }
  30716. }
  30717. },{"../internals/define-built-in":245,"../internals/export":259,"../internals/get-built-in":269,"../internals/is-callable":285,"../internals/is-pure":290,"../internals/promise-constructor-detection":324,"../internals/promise-native-constructor":325}],370:[function(require,module,exports){
  30718. 'use strict';
  30719. var $ = require('../internals/export');
  30720. var IS_PURE = require('../internals/is-pure');
  30721. var IS_NODE = require('../internals/engine-is-node');
  30722. var global = require('../internals/global');
  30723. var call = require('../internals/function-call');
  30724. var defineBuiltIn = require('../internals/define-built-in');
  30725. var setPrototypeOf = require('../internals/object-set-prototype-of');
  30726. var setToStringTag = require('../internals/set-to-string-tag');
  30727. var setSpecies = require('../internals/set-species');
  30728. var aCallable = require('../internals/a-callable');
  30729. var isCallable = require('../internals/is-callable');
  30730. var isObject = require('../internals/is-object');
  30731. var anInstance = require('../internals/an-instance');
  30732. var speciesConstructor = require('../internals/species-constructor');
  30733. var task = require('../internals/task').set;
  30734. var microtask = require('../internals/microtask');
  30735. var hostReportErrors = require('../internals/host-report-errors');
  30736. var perform = require('../internals/perform');
  30737. var Queue = require('../internals/queue');
  30738. var InternalStateModule = require('../internals/internal-state');
  30739. var NativePromiseConstructor = require('../internals/promise-native-constructor');
  30740. var PromiseConstructorDetection = require('../internals/promise-constructor-detection');
  30741. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  30742. var PROMISE = 'Promise';
  30743. var FORCED_PROMISE_CONSTRUCTOR = PromiseConstructorDetection.CONSTRUCTOR;
  30744. var NATIVE_PROMISE_REJECTION_EVENT = PromiseConstructorDetection.REJECTION_EVENT;
  30745. var NATIVE_PROMISE_SUBCLASSING = PromiseConstructorDetection.SUBCLASSING;
  30746. var getInternalPromiseState = InternalStateModule.getterFor(PROMISE);
  30747. var setInternalState = InternalStateModule.set;
  30748. var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;
  30749. var PromiseConstructor = NativePromiseConstructor;
  30750. var PromisePrototype = NativePromisePrototype;
  30751. var TypeError = global.TypeError;
  30752. var document = global.document;
  30753. var process = global.process;
  30754. var newPromiseCapability = newPromiseCapabilityModule.f;
  30755. var newGenericPromiseCapability = newPromiseCapability;
  30756. var DISPATCH_EVENT = !!(document && document.createEvent && global.dispatchEvent);
  30757. var UNHANDLED_REJECTION = 'unhandledrejection';
  30758. var REJECTION_HANDLED = 'rejectionhandled';
  30759. var PENDING = 0;
  30760. var FULFILLED = 1;
  30761. var REJECTED = 2;
  30762. var HANDLED = 1;
  30763. var UNHANDLED = 2;
  30764. var Internal, OwnPromiseCapability, PromiseWrapper, nativeThen;
  30765. // helpers
  30766. var isThenable = function (it) {
  30767. var then;
  30768. return isObject(it) && isCallable(then = it.then) ? then : false;
  30769. };
  30770. var callReaction = function (reaction, state) {
  30771. var value = state.value;
  30772. var ok = state.state === FULFILLED;
  30773. var handler = ok ? reaction.ok : reaction.fail;
  30774. var resolve = reaction.resolve;
  30775. var reject = reaction.reject;
  30776. var domain = reaction.domain;
  30777. var result, then, exited;
  30778. try {
  30779. if (handler) {
  30780. if (!ok) {
  30781. if (state.rejection === UNHANDLED) onHandleUnhandled(state);
  30782. state.rejection = HANDLED;
  30783. }
  30784. if (handler === true) result = value;
  30785. else {
  30786. if (domain) domain.enter();
  30787. result = handler(value); // can throw
  30788. if (domain) {
  30789. domain.exit();
  30790. exited = true;
  30791. }
  30792. }
  30793. if (result === reaction.promise) {
  30794. reject(new TypeError('Promise-chain cycle'));
  30795. } else if (then = isThenable(result)) {
  30796. call(then, result, resolve, reject);
  30797. } else resolve(result);
  30798. } else reject(value);
  30799. } catch (error) {
  30800. if (domain && !exited) domain.exit();
  30801. reject(error);
  30802. }
  30803. };
  30804. var notify = function (state, isReject) {
  30805. if (state.notified) return;
  30806. state.notified = true;
  30807. microtask(function () {
  30808. var reactions = state.reactions;
  30809. var reaction;
  30810. while (reaction = reactions.get()) {
  30811. callReaction(reaction, state);
  30812. }
  30813. state.notified = false;
  30814. if (isReject && !state.rejection) onUnhandled(state);
  30815. });
  30816. };
  30817. var dispatchEvent = function (name, promise, reason) {
  30818. var event, handler;
  30819. if (DISPATCH_EVENT) {
  30820. event = document.createEvent('Event');
  30821. event.promise = promise;
  30822. event.reason = reason;
  30823. event.initEvent(name, false, true);
  30824. global.dispatchEvent(event);
  30825. } else event = { promise: promise, reason: reason };
  30826. if (!NATIVE_PROMISE_REJECTION_EVENT && (handler = global['on' + name])) handler(event);
  30827. else if (name === UNHANDLED_REJECTION) hostReportErrors('Unhandled promise rejection', reason);
  30828. };
  30829. var onUnhandled = function (state) {
  30830. call(task, global, function () {
  30831. var promise = state.facade;
  30832. var value = state.value;
  30833. var IS_UNHANDLED = isUnhandled(state);
  30834. var result;
  30835. if (IS_UNHANDLED) {
  30836. result = perform(function () {
  30837. if (IS_NODE) {
  30838. process.emit('unhandledRejection', value, promise);
  30839. } else dispatchEvent(UNHANDLED_REJECTION, promise, value);
  30840. });
  30841. // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
  30842. state.rejection = IS_NODE || isUnhandled(state) ? UNHANDLED : HANDLED;
  30843. if (result.error) throw result.value;
  30844. }
  30845. });
  30846. };
  30847. var isUnhandled = function (state) {
  30848. return state.rejection !== HANDLED && !state.parent;
  30849. };
  30850. var onHandleUnhandled = function (state) {
  30851. call(task, global, function () {
  30852. var promise = state.facade;
  30853. if (IS_NODE) {
  30854. process.emit('rejectionHandled', promise);
  30855. } else dispatchEvent(REJECTION_HANDLED, promise, state.value);
  30856. });
  30857. };
  30858. var bind = function (fn, state, unwrap) {
  30859. return function (value) {
  30860. fn(state, value, unwrap);
  30861. };
  30862. };
  30863. var internalReject = function (state, value, unwrap) {
  30864. if (state.done) return;
  30865. state.done = true;
  30866. if (unwrap) state = unwrap;
  30867. state.value = value;
  30868. state.state = REJECTED;
  30869. notify(state, true);
  30870. };
  30871. var internalResolve = function (state, value, unwrap) {
  30872. if (state.done) return;
  30873. state.done = true;
  30874. if (unwrap) state = unwrap;
  30875. try {
  30876. if (state.facade === value) throw new TypeError("Promise can't be resolved itself");
  30877. var then = isThenable(value);
  30878. if (then) {
  30879. microtask(function () {
  30880. var wrapper = { done: false };
  30881. try {
  30882. call(then, value,
  30883. bind(internalResolve, wrapper, state),
  30884. bind(internalReject, wrapper, state)
  30885. );
  30886. } catch (error) {
  30887. internalReject(wrapper, error, state);
  30888. }
  30889. });
  30890. } else {
  30891. state.value = value;
  30892. state.state = FULFILLED;
  30893. notify(state, false);
  30894. }
  30895. } catch (error) {
  30896. internalReject({ done: false }, error, state);
  30897. }
  30898. };
  30899. // constructor polyfill
  30900. if (FORCED_PROMISE_CONSTRUCTOR) {
  30901. // 25.4.3.1 Promise(executor)
  30902. PromiseConstructor = function Promise(executor) {
  30903. anInstance(this, PromisePrototype);
  30904. aCallable(executor);
  30905. call(Internal, this);
  30906. var state = getInternalPromiseState(this);
  30907. try {
  30908. executor(bind(internalResolve, state), bind(internalReject, state));
  30909. } catch (error) {
  30910. internalReject(state, error);
  30911. }
  30912. };
  30913. PromisePrototype = PromiseConstructor.prototype;
  30914. // eslint-disable-next-line no-unused-vars -- required for `.length`
  30915. Internal = function Promise(executor) {
  30916. setInternalState(this, {
  30917. type: PROMISE,
  30918. done: false,
  30919. notified: false,
  30920. parent: false,
  30921. reactions: new Queue(),
  30922. rejection: false,
  30923. state: PENDING,
  30924. value: undefined
  30925. });
  30926. };
  30927. // `Promise.prototype.then` method
  30928. // https://tc39.es/ecma262/#sec-promise.prototype.then
  30929. Internal.prototype = defineBuiltIn(PromisePrototype, 'then', function then(onFulfilled, onRejected) {
  30930. var state = getInternalPromiseState(this);
  30931. var reaction = newPromiseCapability(speciesConstructor(this, PromiseConstructor));
  30932. state.parent = true;
  30933. reaction.ok = isCallable(onFulfilled) ? onFulfilled : true;
  30934. reaction.fail = isCallable(onRejected) && onRejected;
  30935. reaction.domain = IS_NODE ? process.domain : undefined;
  30936. if (state.state === PENDING) state.reactions.add(reaction);
  30937. else microtask(function () {
  30938. callReaction(reaction, state);
  30939. });
  30940. return reaction.promise;
  30941. });
  30942. OwnPromiseCapability = function () {
  30943. var promise = new Internal();
  30944. var state = getInternalPromiseState(promise);
  30945. this.promise = promise;
  30946. this.resolve = bind(internalResolve, state);
  30947. this.reject = bind(internalReject, state);
  30948. };
  30949. newPromiseCapabilityModule.f = newPromiseCapability = function (C) {
  30950. return C === PromiseConstructor || C === PromiseWrapper
  30951. ? new OwnPromiseCapability(C)
  30952. : newGenericPromiseCapability(C);
  30953. };
  30954. if (!IS_PURE && isCallable(NativePromiseConstructor) && NativePromisePrototype !== Object.prototype) {
  30955. nativeThen = NativePromisePrototype.then;
  30956. if (!NATIVE_PROMISE_SUBCLASSING) {
  30957. // make `Promise#then` return a polyfilled `Promise` for native promise-based APIs
  30958. defineBuiltIn(NativePromisePrototype, 'then', function then(onFulfilled, onRejected) {
  30959. var that = this;
  30960. return new PromiseConstructor(function (resolve, reject) {
  30961. call(nativeThen, that, resolve, reject);
  30962. }).then(onFulfilled, onRejected);
  30963. // https://github.com/zloirock/core-js/issues/640
  30964. }, { unsafe: true });
  30965. }
  30966. // make `.constructor === Promise` work for native promise-based APIs
  30967. try {
  30968. delete NativePromisePrototype.constructor;
  30969. } catch (error) { /* empty */ }
  30970. // make `instanceof Promise` work for native promise-based APIs
  30971. if (setPrototypeOf) {
  30972. setPrototypeOf(NativePromisePrototype, PromisePrototype);
  30973. }
  30974. }
  30975. }
  30976. $({ global: true, constructor: true, wrap: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {
  30977. Promise: PromiseConstructor
  30978. });
  30979. setToStringTag(PromiseConstructor, PROMISE, false, true);
  30980. setSpecies(PROMISE);
  30981. },{"../internals/a-callable":222,"../internals/an-instance":226,"../internals/define-built-in":245,"../internals/engine-is-node":254,"../internals/export":259,"../internals/function-call":264,"../internals/global":274,"../internals/host-report-errors":277,"../internals/internal-state":282,"../internals/is-callable":285,"../internals/is-object":289,"../internals/is-pure":290,"../internals/microtask":302,"../internals/new-promise-capability":303,"../internals/object-set-prototype-of":318,"../internals/perform":323,"../internals/promise-constructor-detection":324,"../internals/promise-native-constructor":325,"../internals/queue":328,"../internals/set-species":330,"../internals/set-to-string-tag":331,"../internals/species-constructor":335,"../internals/task":339}],371:[function(require,module,exports){
  30982. 'use strict';
  30983. var $ = require('../internals/export');
  30984. var IS_PURE = require('../internals/is-pure');
  30985. var NativePromiseConstructor = require('../internals/promise-native-constructor');
  30986. var fails = require('../internals/fails');
  30987. var getBuiltIn = require('../internals/get-built-in');
  30988. var isCallable = require('../internals/is-callable');
  30989. var speciesConstructor = require('../internals/species-constructor');
  30990. var promiseResolve = require('../internals/promise-resolve');
  30991. var defineBuiltIn = require('../internals/define-built-in');
  30992. var NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;
  30993. // Safari bug https://bugs.webkit.org/show_bug.cgi?id=200829
  30994. var NON_GENERIC = !!NativePromiseConstructor && fails(function () {
  30995. // eslint-disable-next-line unicorn/no-thenable -- required for testing
  30996. NativePromisePrototype['finally'].call({ then: function () { /* empty */ } }, function () { /* empty */ });
  30997. });
  30998. // `Promise.prototype.finally` method
  30999. // https://tc39.es/ecma262/#sec-promise.prototype.finally
  31000. $({ target: 'Promise', proto: true, real: true, forced: NON_GENERIC }, {
  31001. 'finally': function (onFinally) {
  31002. var C = speciesConstructor(this, getBuiltIn('Promise'));
  31003. var isFunction = isCallable(onFinally);
  31004. return this.then(
  31005. isFunction ? function (x) {
  31006. return promiseResolve(C, onFinally()).then(function () { return x; });
  31007. } : onFinally,
  31008. isFunction ? function (e) {
  31009. return promiseResolve(C, onFinally()).then(function () { throw e; });
  31010. } : onFinally
  31011. );
  31012. }
  31013. });
  31014. // makes sure that native promise-based APIs `Promise#finally` properly works with patched `Promise#then`
  31015. if (!IS_PURE && isCallable(NativePromiseConstructor)) {
  31016. var method = getBuiltIn('Promise').prototype['finally'];
  31017. if (NativePromisePrototype['finally'] !== method) {
  31018. defineBuiltIn(NativePromisePrototype, 'finally', method, { unsafe: true });
  31019. }
  31020. }
  31021. },{"../internals/define-built-in":245,"../internals/export":259,"../internals/fails":260,"../internals/get-built-in":269,"../internals/is-callable":285,"../internals/is-pure":290,"../internals/promise-native-constructor":325,"../internals/promise-resolve":326,"../internals/species-constructor":335}],372:[function(require,module,exports){
  31022. 'use strict';
  31023. // TODO: Remove this module from `core-js@4` since it's split to modules listed below
  31024. require('../modules/es.promise.constructor');
  31025. require('../modules/es.promise.all');
  31026. require('../modules/es.promise.catch');
  31027. require('../modules/es.promise.race');
  31028. require('../modules/es.promise.reject');
  31029. require('../modules/es.promise.resolve');
  31030. },{"../modules/es.promise.all":368,"../modules/es.promise.catch":369,"../modules/es.promise.constructor":370,"../modules/es.promise.race":373,"../modules/es.promise.reject":374,"../modules/es.promise.resolve":375}],373:[function(require,module,exports){
  31031. 'use strict';
  31032. var $ = require('../internals/export');
  31033. var call = require('../internals/function-call');
  31034. var aCallable = require('../internals/a-callable');
  31035. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  31036. var perform = require('../internals/perform');
  31037. var iterate = require('../internals/iterate');
  31038. var PROMISE_STATICS_INCORRECT_ITERATION = require('../internals/promise-statics-incorrect-iteration');
  31039. // `Promise.race` method
  31040. // https://tc39.es/ecma262/#sec-promise.race
  31041. $({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, {
  31042. race: function race(iterable) {
  31043. var C = this;
  31044. var capability = newPromiseCapabilityModule.f(C);
  31045. var reject = capability.reject;
  31046. var result = perform(function () {
  31047. var $promiseResolve = aCallable(C.resolve);
  31048. iterate(iterable, function (promise) {
  31049. call($promiseResolve, C, promise).then(capability.resolve, reject);
  31050. });
  31051. });
  31052. if (result.error) reject(result.value);
  31053. return capability.promise;
  31054. }
  31055. });
  31056. },{"../internals/a-callable":222,"../internals/export":259,"../internals/function-call":264,"../internals/iterate":293,"../internals/new-promise-capability":303,"../internals/perform":323,"../internals/promise-statics-incorrect-iteration":327}],374:[function(require,module,exports){
  31057. 'use strict';
  31058. var $ = require('../internals/export');
  31059. var call = require('../internals/function-call');
  31060. var newPromiseCapabilityModule = require('../internals/new-promise-capability');
  31061. var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;
  31062. // `Promise.reject` method
  31063. // https://tc39.es/ecma262/#sec-promise.reject
  31064. $({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {
  31065. reject: function reject(r) {
  31066. var capability = newPromiseCapabilityModule.f(this);
  31067. call(capability.reject, undefined, r);
  31068. return capability.promise;
  31069. }
  31070. });
  31071. },{"../internals/export":259,"../internals/function-call":264,"../internals/new-promise-capability":303,"../internals/promise-constructor-detection":324}],375:[function(require,module,exports){
  31072. 'use strict';
  31073. var $ = require('../internals/export');
  31074. var getBuiltIn = require('../internals/get-built-in');
  31075. var IS_PURE = require('../internals/is-pure');
  31076. var NativePromiseConstructor = require('../internals/promise-native-constructor');
  31077. var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;
  31078. var promiseResolve = require('../internals/promise-resolve');
  31079. var PromiseConstructorWrapper = getBuiltIn('Promise');
  31080. var CHECK_WRAPPER = IS_PURE && !FORCED_PROMISE_CONSTRUCTOR;
  31081. // `Promise.resolve` method
  31082. // https://tc39.es/ecma262/#sec-promise.resolve
  31083. $({ target: 'Promise', stat: true, forced: IS_PURE || FORCED_PROMISE_CONSTRUCTOR }, {
  31084. resolve: function resolve(x) {
  31085. return promiseResolve(CHECK_WRAPPER && this === PromiseConstructorWrapper ? NativePromiseConstructor : this, x);
  31086. }
  31087. });
  31088. },{"../internals/export":259,"../internals/get-built-in":269,"../internals/is-pure":290,"../internals/promise-constructor-detection":324,"../internals/promise-native-constructor":325,"../internals/promise-resolve":326}],376:[function(require,module,exports){
  31089. 'use strict';
  31090. var $ = require('../internals/export');
  31091. var uncurryThis = require('../internals/function-uncurry-this');
  31092. var toAbsoluteIndex = require('../internals/to-absolute-index');
  31093. var $RangeError = RangeError;
  31094. var fromCharCode = String.fromCharCode;
  31095. // eslint-disable-next-line es/no-string-fromcodepoint -- required for testing
  31096. var $fromCodePoint = String.fromCodePoint;
  31097. var join = uncurryThis([].join);
  31098. // length should be 1, old FF problem
  31099. var INCORRECT_LENGTH = !!$fromCodePoint && $fromCodePoint.length !== 1;
  31100. // `String.fromCodePoint` method
  31101. // https://tc39.es/ecma262/#sec-string.fromcodepoint
  31102. $({ target: 'String', stat: true, arity: 1, forced: INCORRECT_LENGTH }, {
  31103. // eslint-disable-next-line no-unused-vars -- required for `.length`
  31104. fromCodePoint: function fromCodePoint(x) {
  31105. var elements = [];
  31106. var length = arguments.length;
  31107. var i = 0;
  31108. var code;
  31109. while (length > i) {
  31110. code = +arguments[i++];
  31111. if (toAbsoluteIndex(code, 0x10FFFF) !== code) throw new $RangeError(code + ' is not a valid code point');
  31112. elements[i] = code < 0x10000
  31113. ? fromCharCode(code)
  31114. : fromCharCode(((code -= 0x10000) >> 10) + 0xD800, code % 0x400 + 0xDC00);
  31115. } return join(elements, '');
  31116. }
  31117. });
  31118. },{"../internals/export":259,"../internals/function-uncurry-this":268,"../internals/to-absolute-index":340}],377:[function(require,module,exports){
  31119. 'use strict';
  31120. var $ = require('../internals/export');
  31121. var uncurryThis = require('../internals/function-uncurry-this');
  31122. var notARegExp = require('../internals/not-a-regexp');
  31123. var requireObjectCoercible = require('../internals/require-object-coercible');
  31124. var toString = require('../internals/to-string');
  31125. var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic');
  31126. var stringIndexOf = uncurryThis(''.indexOf);
  31127. // `String.prototype.includes` method
  31128. // https://tc39.es/ecma262/#sec-string.prototype.includes
  31129. $({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
  31130. includes: function includes(searchString /* , position = 0 */) {
  31131. return !!~stringIndexOf(
  31132. toString(requireObjectCoercible(this)),
  31133. toString(notARegExp(searchString)),
  31134. arguments.length > 1 ? arguments[1] : undefined
  31135. );
  31136. }
  31137. });
  31138. },{"../internals/correct-is-regexp-logic":238,"../internals/export":259,"../internals/function-uncurry-this":268,"../internals/not-a-regexp":304,"../internals/require-object-coercible":329,"../internals/to-string":348}],378:[function(require,module,exports){
  31139. 'use strict';
  31140. var defineWellKnownSymbol = require('../internals/well-known-symbol-define');
  31141. // `Symbol.asyncIterator` well-known symbol
  31142. // https://tc39.es/ecma262/#sec-symbol.asynciterator
  31143. defineWellKnownSymbol('asyncIterator');
  31144. },{"../internals/well-known-symbol-define":355}],379:[function(require,module,exports){
  31145. 'use strict';
  31146. var $ = require('../internals/export');
  31147. var global = require('../internals/global');
  31148. var call = require('../internals/function-call');
  31149. var uncurryThis = require('../internals/function-uncurry-this');
  31150. var IS_PURE = require('../internals/is-pure');
  31151. var DESCRIPTORS = require('../internals/descriptors');
  31152. var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
  31153. var fails = require('../internals/fails');
  31154. var hasOwn = require('../internals/has-own-property');
  31155. var isPrototypeOf = require('../internals/object-is-prototype-of');
  31156. var anObject = require('../internals/an-object');
  31157. var toIndexedObject = require('../internals/to-indexed-object');
  31158. var toPropertyKey = require('../internals/to-property-key');
  31159. var $toString = require('../internals/to-string');
  31160. var createPropertyDescriptor = require('../internals/create-property-descriptor');
  31161. var nativeObjectCreate = require('../internals/object-create');
  31162. var objectKeys = require('../internals/object-keys');
  31163. var getOwnPropertyNamesModule = require('../internals/object-get-own-property-names');
  31164. var getOwnPropertyNamesExternal = require('../internals/object-get-own-property-names-external');
  31165. var getOwnPropertySymbolsModule = require('../internals/object-get-own-property-symbols');
  31166. var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
  31167. var definePropertyModule = require('../internals/object-define-property');
  31168. var definePropertiesModule = require('../internals/object-define-properties');
  31169. var propertyIsEnumerableModule = require('../internals/object-property-is-enumerable');
  31170. var defineBuiltIn = require('../internals/define-built-in');
  31171. var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
  31172. var shared = require('../internals/shared');
  31173. var sharedKey = require('../internals/shared-key');
  31174. var hiddenKeys = require('../internals/hidden-keys');
  31175. var uid = require('../internals/uid');
  31176. var wellKnownSymbol = require('../internals/well-known-symbol');
  31177. var wrappedWellKnownSymbolModule = require('../internals/well-known-symbol-wrapped');
  31178. var defineWellKnownSymbol = require('../internals/well-known-symbol-define');
  31179. var defineSymbolToPrimitive = require('../internals/symbol-define-to-primitive');
  31180. var setToStringTag = require('../internals/set-to-string-tag');
  31181. var InternalStateModule = require('../internals/internal-state');
  31182. var $forEach = require('../internals/array-iteration').forEach;
  31183. var HIDDEN = sharedKey('hidden');
  31184. var SYMBOL = 'Symbol';
  31185. var PROTOTYPE = 'prototype';
  31186. var setInternalState = InternalStateModule.set;
  31187. var getInternalState = InternalStateModule.getterFor(SYMBOL);
  31188. var ObjectPrototype = Object[PROTOTYPE];
  31189. var $Symbol = global.Symbol;
  31190. var SymbolPrototype = $Symbol && $Symbol[PROTOTYPE];
  31191. var RangeError = global.RangeError;
  31192. var TypeError = global.TypeError;
  31193. var QObject = global.QObject;
  31194. var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
  31195. var nativeDefineProperty = definePropertyModule.f;
  31196. var nativeGetOwnPropertyNames = getOwnPropertyNamesExternal.f;
  31197. var nativePropertyIsEnumerable = propertyIsEnumerableModule.f;
  31198. var push = uncurryThis([].push);
  31199. var AllSymbols = shared('symbols');
  31200. var ObjectPrototypeSymbols = shared('op-symbols');
  31201. var WellKnownSymbolsStore = shared('wks');
  31202. // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
  31203. var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild;
  31204. // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
  31205. var fallbackDefineProperty = function (O, P, Attributes) {
  31206. var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor(ObjectPrototype, P);
  31207. if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
  31208. nativeDefineProperty(O, P, Attributes);
  31209. if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
  31210. nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
  31211. }
  31212. };
  31213. var setSymbolDescriptor = DESCRIPTORS && fails(function () {
  31214. return nativeObjectCreate(nativeDefineProperty({}, 'a', {
  31215. get: function () { return nativeDefineProperty(this, 'a', { value: 7 }).a; }
  31216. })).a !== 7;
  31217. }) ? fallbackDefineProperty : nativeDefineProperty;
  31218. var wrap = function (tag, description) {
  31219. var symbol = AllSymbols[tag] = nativeObjectCreate(SymbolPrototype);
  31220. setInternalState(symbol, {
  31221. type: SYMBOL,
  31222. tag: tag,
  31223. description: description
  31224. });
  31225. if (!DESCRIPTORS) symbol.description = description;
  31226. return symbol;
  31227. };
  31228. var $defineProperty = function defineProperty(O, P, Attributes) {
  31229. if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
  31230. anObject(O);
  31231. var key = toPropertyKey(P);
  31232. anObject(Attributes);
  31233. if (hasOwn(AllSymbols, key)) {
  31234. if (!Attributes.enumerable) {
  31235. if (!hasOwn(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
  31236. O[HIDDEN][key] = true;
  31237. } else {
  31238. if (hasOwn(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
  31239. Attributes = nativeObjectCreate(Attributes, { enumerable: createPropertyDescriptor(0, false) });
  31240. } return setSymbolDescriptor(O, key, Attributes);
  31241. } return nativeDefineProperty(O, key, Attributes);
  31242. };
  31243. var $defineProperties = function defineProperties(O, Properties) {
  31244. anObject(O);
  31245. var properties = toIndexedObject(Properties);
  31246. var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
  31247. $forEach(keys, function (key) {
  31248. if (!DESCRIPTORS || call($propertyIsEnumerable, properties, key)) $defineProperty(O, key, properties[key]);
  31249. });
  31250. return O;
  31251. };
  31252. var $create = function create(O, Properties) {
  31253. return Properties === undefined ? nativeObjectCreate(O) : $defineProperties(nativeObjectCreate(O), Properties);
  31254. };
  31255. var $propertyIsEnumerable = function propertyIsEnumerable(V) {
  31256. var P = toPropertyKey(V);
  31257. var enumerable = call(nativePropertyIsEnumerable, this, P);
  31258. if (this === ObjectPrototype && hasOwn(AllSymbols, P) && !hasOwn(ObjectPrototypeSymbols, P)) return false;
  31259. return enumerable || !hasOwn(this, P) || !hasOwn(AllSymbols, P) || hasOwn(this, HIDDEN) && this[HIDDEN][P]
  31260. ? enumerable : true;
  31261. };
  31262. var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
  31263. var it = toIndexedObject(O);
  31264. var key = toPropertyKey(P);
  31265. if (it === ObjectPrototype && hasOwn(AllSymbols, key) && !hasOwn(ObjectPrototypeSymbols, key)) return;
  31266. var descriptor = nativeGetOwnPropertyDescriptor(it, key);
  31267. if (descriptor && hasOwn(AllSymbols, key) && !(hasOwn(it, HIDDEN) && it[HIDDEN][key])) {
  31268. descriptor.enumerable = true;
  31269. }
  31270. return descriptor;
  31271. };
  31272. var $getOwnPropertyNames = function getOwnPropertyNames(O) {
  31273. var names = nativeGetOwnPropertyNames(toIndexedObject(O));
  31274. var result = [];
  31275. $forEach(names, function (key) {
  31276. if (!hasOwn(AllSymbols, key) && !hasOwn(hiddenKeys, key)) push(result, key);
  31277. });
  31278. return result;
  31279. };
  31280. var $getOwnPropertySymbols = function (O) {
  31281. var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
  31282. var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
  31283. var result = [];
  31284. $forEach(names, function (key) {
  31285. if (hasOwn(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || hasOwn(ObjectPrototype, key))) {
  31286. push(result, AllSymbols[key]);
  31287. }
  31288. });
  31289. return result;
  31290. };
  31291. // `Symbol` constructor
  31292. // https://tc39.es/ecma262/#sec-symbol-constructor
  31293. if (!NATIVE_SYMBOL) {
  31294. $Symbol = function Symbol() {
  31295. if (isPrototypeOf(SymbolPrototype, this)) throw new TypeError('Symbol is not a constructor');
  31296. var description = !arguments.length || arguments[0] === undefined ? undefined : $toString(arguments[0]);
  31297. var tag = uid(description);
  31298. var setter = function (value) {
  31299. if (this === ObjectPrototype) call(setter, ObjectPrototypeSymbols, value);
  31300. if (hasOwn(this, HIDDEN) && hasOwn(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
  31301. var descriptor = createPropertyDescriptor(1, value);
  31302. try {
  31303. setSymbolDescriptor(this, tag, descriptor);
  31304. } catch (error) {
  31305. if (!(error instanceof RangeError)) throw error;
  31306. fallbackDefineProperty(this, tag, descriptor);
  31307. }
  31308. };
  31309. if (DESCRIPTORS && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, { configurable: true, set: setter });
  31310. return wrap(tag, description);
  31311. };
  31312. SymbolPrototype = $Symbol[PROTOTYPE];
  31313. defineBuiltIn(SymbolPrototype, 'toString', function toString() {
  31314. return getInternalState(this).tag;
  31315. });
  31316. defineBuiltIn($Symbol, 'withoutSetter', function (description) {
  31317. return wrap(uid(description), description);
  31318. });
  31319. propertyIsEnumerableModule.f = $propertyIsEnumerable;
  31320. definePropertyModule.f = $defineProperty;
  31321. definePropertiesModule.f = $defineProperties;
  31322. getOwnPropertyDescriptorModule.f = $getOwnPropertyDescriptor;
  31323. getOwnPropertyNamesModule.f = getOwnPropertyNamesExternal.f = $getOwnPropertyNames;
  31324. getOwnPropertySymbolsModule.f = $getOwnPropertySymbols;
  31325. wrappedWellKnownSymbolModule.f = function (name) {
  31326. return wrap(wellKnownSymbol(name), name);
  31327. };
  31328. if (DESCRIPTORS) {
  31329. // https://github.com/tc39/proposal-Symbol-description
  31330. defineBuiltInAccessor(SymbolPrototype, 'description', {
  31331. configurable: true,
  31332. get: function description() {
  31333. return getInternalState(this).description;
  31334. }
  31335. });
  31336. if (!IS_PURE) {
  31337. defineBuiltIn(ObjectPrototype, 'propertyIsEnumerable', $propertyIsEnumerable, { unsafe: true });
  31338. }
  31339. }
  31340. }
  31341. $({ global: true, constructor: true, wrap: true, forced: !NATIVE_SYMBOL, sham: !NATIVE_SYMBOL }, {
  31342. Symbol: $Symbol
  31343. });
  31344. $forEach(objectKeys(WellKnownSymbolsStore), function (name) {
  31345. defineWellKnownSymbol(name);
  31346. });
  31347. $({ target: SYMBOL, stat: true, forced: !NATIVE_SYMBOL }, {
  31348. useSetter: function () { USE_SETTER = true; },
  31349. useSimple: function () { USE_SETTER = false; }
  31350. });
  31351. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL, sham: !DESCRIPTORS }, {
  31352. // `Object.create` method
  31353. // https://tc39.es/ecma262/#sec-object.create
  31354. create: $create,
  31355. // `Object.defineProperty` method
  31356. // https://tc39.es/ecma262/#sec-object.defineproperty
  31357. defineProperty: $defineProperty,
  31358. // `Object.defineProperties` method
  31359. // https://tc39.es/ecma262/#sec-object.defineproperties
  31360. defineProperties: $defineProperties,
  31361. // `Object.getOwnPropertyDescriptor` method
  31362. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
  31363. getOwnPropertyDescriptor: $getOwnPropertyDescriptor
  31364. });
  31365. $({ target: 'Object', stat: true, forced: !NATIVE_SYMBOL }, {
  31366. // `Object.getOwnPropertyNames` method
  31367. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  31368. getOwnPropertyNames: $getOwnPropertyNames
  31369. });
  31370. // `Symbol.prototype[@@toPrimitive]` method
  31371. // https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
  31372. defineSymbolToPrimitive();
  31373. // `Symbol.prototype[@@toStringTag]` property
  31374. // https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag
  31375. setToStringTag($Symbol, SYMBOL);
  31376. hiddenKeys[HIDDEN] = true;
  31377. },{"../internals/an-object":227,"../internals/array-iteration":229,"../internals/create-property-descriptor":242,"../internals/define-built-in":245,"../internals/define-built-in-accessor":244,"../internals/descriptors":247,"../internals/export":259,"../internals/fails":260,"../internals/function-call":264,"../internals/function-uncurry-this":268,"../internals/global":274,"../internals/has-own-property":275,"../internals/hidden-keys":276,"../internals/internal-state":282,"../internals/is-pure":290,"../internals/object-create":306,"../internals/object-define-properties":307,"../internals/object-define-property":308,"../internals/object-get-own-property-descriptor":309,"../internals/object-get-own-property-names":311,"../internals/object-get-own-property-names-external":310,"../internals/object-get-own-property-symbols":312,"../internals/object-is-prototype-of":314,"../internals/object-keys":316,"../internals/object-property-is-enumerable":317,"../internals/set-to-string-tag":331,"../internals/shared":334,"../internals/shared-key":332,"../internals/symbol-constructor-detection":336,"../internals/symbol-define-to-primitive":337,"../internals/to-indexed-object":341,"../internals/to-property-key":346,"../internals/to-string":348,"../internals/uid":350,"../internals/well-known-symbol":357,"../internals/well-known-symbol-define":355,"../internals/well-known-symbol-wrapped":356}],380:[function(require,module,exports){
  31378. 'use strict';
  31379. var $ = require('../internals/export');
  31380. var getBuiltIn = require('../internals/get-built-in');
  31381. var hasOwn = require('../internals/has-own-property');
  31382. var toString = require('../internals/to-string');
  31383. var shared = require('../internals/shared');
  31384. var NATIVE_SYMBOL_REGISTRY = require('../internals/symbol-registry-detection');
  31385. var StringToSymbolRegistry = shared('string-to-symbol-registry');
  31386. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  31387. // `Symbol.for` method
  31388. // https://tc39.es/ecma262/#sec-symbol.for
  31389. $({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
  31390. 'for': function (key) {
  31391. var string = toString(key);
  31392. if (hasOwn(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
  31393. var symbol = getBuiltIn('Symbol')(string);
  31394. StringToSymbolRegistry[string] = symbol;
  31395. SymbolToStringRegistry[symbol] = string;
  31396. return symbol;
  31397. }
  31398. });
  31399. },{"../internals/export":259,"../internals/get-built-in":269,"../internals/has-own-property":275,"../internals/shared":334,"../internals/symbol-registry-detection":338,"../internals/to-string":348}],381:[function(require,module,exports){
  31400. 'use strict';
  31401. // TODO: Remove this module from `core-js@4` since it's split to modules listed below
  31402. require('../modules/es.symbol.constructor');
  31403. require('../modules/es.symbol.for');
  31404. require('../modules/es.symbol.key-for');
  31405. require('../modules/es.json.stringify');
  31406. require('../modules/es.object.get-own-property-symbols');
  31407. },{"../modules/es.json.stringify":362,"../modules/es.object.get-own-property-symbols":365,"../modules/es.symbol.constructor":379,"../modules/es.symbol.for":380,"../modules/es.symbol.key-for":382}],382:[function(require,module,exports){
  31408. 'use strict';
  31409. var $ = require('../internals/export');
  31410. var hasOwn = require('../internals/has-own-property');
  31411. var isSymbol = require('../internals/is-symbol');
  31412. var tryToString = require('../internals/try-to-string');
  31413. var shared = require('../internals/shared');
  31414. var NATIVE_SYMBOL_REGISTRY = require('../internals/symbol-registry-detection');
  31415. var SymbolToStringRegistry = shared('symbol-to-string-registry');
  31416. // `Symbol.keyFor` method
  31417. // https://tc39.es/ecma262/#sec-symbol.keyfor
  31418. $({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {
  31419. keyFor: function keyFor(sym) {
  31420. if (!isSymbol(sym)) throw new TypeError(tryToString(sym) + ' is not a symbol');
  31421. if (hasOwn(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
  31422. }
  31423. });
  31424. },{"../internals/export":259,"../internals/has-own-property":275,"../internals/is-symbol":292,"../internals/shared":334,"../internals/symbol-registry-detection":338,"../internals/try-to-string":349}],383:[function(require,module,exports){
  31425. "use strict";
  31426. // Copyright Joyent, Inc. and other Node contributors.
  31427. //
  31428. // Permission is hereby granted, free of charge, to any person obtaining a
  31429. // copy of this software and associated documentation files (the
  31430. // "Software"), to deal in the Software without restriction, including
  31431. // without limitation the rights to use, copy, modify, merge, publish,
  31432. // distribute, sublicense, and/or sell copies of the Software, and to permit
  31433. // persons to whom the Software is furnished to do so, subject to the
  31434. // following conditions:
  31435. //
  31436. // The above copyright notice and this permission notice shall be included
  31437. // in all copies or substantial portions of the Software.
  31438. //
  31439. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  31440. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31441. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  31442. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  31443. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  31444. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  31445. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  31446. // NOTE: These type checking functions intentionally don't use `instanceof`
  31447. // because it is fragile and can be easily faked with `Object.create()`.
  31448. function isArray(arg) {
  31449. if (Array.isArray) {
  31450. return Array.isArray(arg);
  31451. }
  31452. return objectToString(arg) === '[object Array]';
  31453. }
  31454. exports.isArray = isArray;
  31455. function isBoolean(arg) {
  31456. return typeof arg === 'boolean';
  31457. }
  31458. exports.isBoolean = isBoolean;
  31459. function isNull(arg) {
  31460. return arg === null;
  31461. }
  31462. exports.isNull = isNull;
  31463. function isNullOrUndefined(arg) {
  31464. return arg == null;
  31465. }
  31466. exports.isNullOrUndefined = isNullOrUndefined;
  31467. function isNumber(arg) {
  31468. return typeof arg === 'number';
  31469. }
  31470. exports.isNumber = isNumber;
  31471. function isString(arg) {
  31472. return typeof arg === 'string';
  31473. }
  31474. exports.isString = isString;
  31475. function isSymbol(arg) {
  31476. return typeof arg === 'symbol';
  31477. }
  31478. exports.isSymbol = isSymbol;
  31479. function isUndefined(arg) {
  31480. return arg === void 0;
  31481. }
  31482. exports.isUndefined = isUndefined;
  31483. function isRegExp(re) {
  31484. return objectToString(re) === '[object RegExp]';
  31485. }
  31486. exports.isRegExp = isRegExp;
  31487. function isObject(arg) {
  31488. return typeof arg === 'object' && arg !== null;
  31489. }
  31490. exports.isObject = isObject;
  31491. function isDate(d) {
  31492. return objectToString(d) === '[object Date]';
  31493. }
  31494. exports.isDate = isDate;
  31495. function isError(e) {
  31496. return objectToString(e) === '[object Error]' || e instanceof Error;
  31497. }
  31498. exports.isError = isError;
  31499. function isFunction(arg) {
  31500. return typeof arg === 'function';
  31501. }
  31502. exports.isFunction = isFunction;
  31503. function isPrimitive(arg) {
  31504. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || typeof arg === 'symbol' ||
  31505. // ES6 symbol
  31506. typeof arg === 'undefined';
  31507. }
  31508. exports.isPrimitive = isPrimitive;
  31509. exports.isBuffer = require('buffer').Buffer.isBuffer;
  31510. function objectToString(o) {
  31511. return Object.prototype.toString.call(o);
  31512. }
  31513. },{"buffer":220}],384:[function(require,module,exports){
  31514. (function (Buffer){(function (){
  31515. "use strict";
  31516. var elliptic = require('elliptic');
  31517. var BN = require('bn.js');
  31518. module.exports = function createECDH(curve) {
  31519. return new ECDH(curve);
  31520. };
  31521. var aliases = {
  31522. secp256k1: {
  31523. name: 'secp256k1',
  31524. byteLength: 32
  31525. },
  31526. secp224r1: {
  31527. name: 'p224',
  31528. byteLength: 28
  31529. },
  31530. prime256v1: {
  31531. name: 'p256',
  31532. byteLength: 32
  31533. },
  31534. prime192v1: {
  31535. name: 'p192',
  31536. byteLength: 24
  31537. },
  31538. ed25519: {
  31539. name: 'ed25519',
  31540. byteLength: 32
  31541. },
  31542. secp384r1: {
  31543. name: 'p384',
  31544. byteLength: 48
  31545. },
  31546. secp521r1: {
  31547. name: 'p521',
  31548. byteLength: 66
  31549. }
  31550. };
  31551. aliases.p224 = aliases.secp224r1;
  31552. aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
  31553. aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
  31554. aliases.p384 = aliases.secp384r1;
  31555. aliases.p521 = aliases.secp521r1;
  31556. function ECDH(curve) {
  31557. this.curveType = aliases[curve];
  31558. if (!this.curveType) {
  31559. this.curveType = {
  31560. name: curve
  31561. };
  31562. }
  31563. this.curve = new elliptic.ec(this.curveType.name); // eslint-disable-line new-cap
  31564. this.keys = void 0;
  31565. }
  31566. ECDH.prototype.generateKeys = function (enc, format) {
  31567. this.keys = this.curve.genKeyPair();
  31568. return this.getPublicKey(enc, format);
  31569. };
  31570. ECDH.prototype.computeSecret = function (other, inenc, enc) {
  31571. inenc = inenc || 'utf8';
  31572. if (!Buffer.isBuffer(other)) {
  31573. other = new Buffer(other, inenc);
  31574. }
  31575. var otherPub = this.curve.keyFromPublic(other).getPublic();
  31576. var out = otherPub.mul(this.keys.getPrivate()).getX();
  31577. return formatReturnValue(out, enc, this.curveType.byteLength);
  31578. };
  31579. ECDH.prototype.getPublicKey = function (enc, format) {
  31580. var key = this.keys.getPublic(format === 'compressed', true);
  31581. if (format === 'hybrid') {
  31582. if (key[key.length - 1] % 2) {
  31583. key[0] = 7;
  31584. } else {
  31585. key[0] = 6;
  31586. }
  31587. }
  31588. return formatReturnValue(key, enc);
  31589. };
  31590. ECDH.prototype.getPrivateKey = function (enc) {
  31591. return formatReturnValue(this.keys.getPrivate(), enc);
  31592. };
  31593. ECDH.prototype.setPublicKey = function (pub, enc) {
  31594. enc = enc || 'utf8';
  31595. if (!Buffer.isBuffer(pub)) {
  31596. pub = new Buffer(pub, enc);
  31597. }
  31598. this.keys._importPublic(pub);
  31599. return this;
  31600. };
  31601. ECDH.prototype.setPrivateKey = function (priv, enc) {
  31602. enc = enc || 'utf8';
  31603. if (!Buffer.isBuffer(priv)) {
  31604. priv = new Buffer(priv, enc);
  31605. }
  31606. var _priv = new BN(priv);
  31607. _priv = _priv.toString(16);
  31608. this.keys = this.curve.genKeyPair();
  31609. this.keys._importPrivate(_priv);
  31610. return this;
  31611. };
  31612. function formatReturnValue(bn, enc, len) {
  31613. if (!Array.isArray(bn)) {
  31614. bn = bn.toArray();
  31615. }
  31616. var buf = new Buffer(bn);
  31617. if (len && buf.length < len) {
  31618. var zeros = new Buffer(len - buf.length);
  31619. zeros.fill(0);
  31620. buf = Buffer.concat([zeros, buf]);
  31621. }
  31622. if (!enc) {
  31623. return buf;
  31624. } else {
  31625. return buf.toString(enc);
  31626. }
  31627. }
  31628. }).call(this)}).call(this,require("buffer").Buffer)
  31629. },{"bn.js":385,"buffer":220,"elliptic":405}],385:[function(require,module,exports){
  31630. arguments[4][184][0].apply(exports,arguments)
  31631. },{"buffer":188,"dup":184}],386:[function(require,module,exports){
  31632. 'use strict';
  31633. var inherits = require('inherits');
  31634. var MD5 = require('md5.js');
  31635. var RIPEMD160 = require('ripemd160');
  31636. var sha = require('sha.js');
  31637. var Base = require('cipher-base');
  31638. function Hash(hash) {
  31639. Base.call(this, 'digest');
  31640. this._hash = hash;
  31641. }
  31642. inherits(Hash, Base);
  31643. Hash.prototype._update = function (data) {
  31644. this._hash.update(data);
  31645. };
  31646. Hash.prototype._final = function () {
  31647. return this._hash.digest();
  31648. };
  31649. module.exports = function createHash(alg) {
  31650. alg = alg.toLowerCase();
  31651. if (alg === 'md5') return new MD5();
  31652. if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160();
  31653. return new Hash(sha(alg));
  31654. };
  31655. },{"cipher-base":221,"inherits":440,"md5.js":450,"ripemd160":493,"sha.js":498}],387:[function(require,module,exports){
  31656. "use strict";
  31657. var MD5 = require('md5.js');
  31658. module.exports = function (buffer) {
  31659. return new MD5().update(buffer).digest();
  31660. };
  31661. },{"md5.js":450}],388:[function(require,module,exports){
  31662. 'use strict';
  31663. var inherits = require('inherits');
  31664. var Legacy = require('./legacy');
  31665. var Base = require('cipher-base');
  31666. var Buffer = require('safe-buffer').Buffer;
  31667. var md5 = require('create-hash/md5');
  31668. var RIPEMD160 = require('ripemd160');
  31669. var sha = require('sha.js');
  31670. var ZEROS = Buffer.alloc(128);
  31671. function Hmac(alg, key) {
  31672. Base.call(this, 'digest');
  31673. if (typeof key === 'string') {
  31674. key = Buffer.from(key);
  31675. }
  31676. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  31677. this._alg = alg;
  31678. this._key = key;
  31679. if (key.length > blocksize) {
  31680. var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  31681. key = hash.update(key).digest();
  31682. } else if (key.length < blocksize) {
  31683. key = Buffer.concat([key, ZEROS], blocksize);
  31684. }
  31685. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  31686. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  31687. for (var i = 0; i < blocksize; i++) {
  31688. ipad[i] = key[i] ^ 0x36;
  31689. opad[i] = key[i] ^ 0x5C;
  31690. }
  31691. this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  31692. this._hash.update(ipad);
  31693. }
  31694. inherits(Hmac, Base);
  31695. Hmac.prototype._update = function (data) {
  31696. this._hash.update(data);
  31697. };
  31698. Hmac.prototype._final = function () {
  31699. var h = this._hash.digest();
  31700. var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg);
  31701. return hash.update(this._opad).update(h).digest();
  31702. };
  31703. module.exports = function createHmac(alg, key) {
  31704. alg = alg.toLowerCase();
  31705. if (alg === 'rmd160' || alg === 'ripemd160') {
  31706. return new Hmac('rmd160', key);
  31707. }
  31708. if (alg === 'md5') {
  31709. return new Legacy(md5, key);
  31710. }
  31711. return new Hmac(alg, key);
  31712. };
  31713. },{"./legacy":389,"cipher-base":221,"create-hash/md5":387,"inherits":440,"ripemd160":493,"safe-buffer":494,"sha.js":498}],389:[function(require,module,exports){
  31714. 'use strict';
  31715. var inherits = require('inherits');
  31716. var Buffer = require('safe-buffer').Buffer;
  31717. var Base = require('cipher-base');
  31718. var ZEROS = Buffer.alloc(128);
  31719. var blocksize = 64;
  31720. function Hmac(alg, key) {
  31721. Base.call(this, 'digest');
  31722. if (typeof key === 'string') {
  31723. key = Buffer.from(key);
  31724. }
  31725. this._alg = alg;
  31726. this._key = key;
  31727. if (key.length > blocksize) {
  31728. key = alg(key);
  31729. } else if (key.length < blocksize) {
  31730. key = Buffer.concat([key, ZEROS], blocksize);
  31731. }
  31732. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  31733. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  31734. for (var i = 0; i < blocksize; i++) {
  31735. ipad[i] = key[i] ^ 0x36;
  31736. opad[i] = key[i] ^ 0x5C;
  31737. }
  31738. this._hash = [ipad];
  31739. }
  31740. inherits(Hmac, Base);
  31741. Hmac.prototype._update = function (data) {
  31742. this._hash.push(data);
  31743. };
  31744. Hmac.prototype._final = function () {
  31745. var h = this._alg(Buffer.concat(this._hash));
  31746. return this._alg(Buffer.concat([this._opad, h]));
  31747. };
  31748. module.exports = Hmac;
  31749. },{"cipher-base":221,"inherits":440,"safe-buffer":494}],390:[function(require,module,exports){
  31750. 'use strict';
  31751. exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes');
  31752. exports.createHash = exports.Hash = require('create-hash');
  31753. exports.createHmac = exports.Hmac = require('create-hmac');
  31754. var algos = require('browserify-sign/algos');
  31755. var algoKeys = Object.keys(algos);
  31756. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
  31757. exports.getHashes = function () {
  31758. return hashes;
  31759. };
  31760. var p = require('pbkdf2');
  31761. exports.pbkdf2 = p.pbkdf2;
  31762. exports.pbkdf2Sync = p.pbkdf2Sync;
  31763. var aes = require('browserify-cipher');
  31764. exports.Cipher = aes.Cipher;
  31765. exports.createCipher = aes.createCipher;
  31766. exports.Cipheriv = aes.Cipheriv;
  31767. exports.createCipheriv = aes.createCipheriv;
  31768. exports.Decipher = aes.Decipher;
  31769. exports.createDecipher = aes.createDecipher;
  31770. exports.Decipheriv = aes.Decipheriv;
  31771. exports.createDecipheriv = aes.createDecipheriv;
  31772. exports.getCiphers = aes.getCiphers;
  31773. exports.listCiphers = aes.listCiphers;
  31774. var dh = require('diffie-hellman');
  31775. exports.DiffieHellmanGroup = dh.DiffieHellmanGroup;
  31776. exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup;
  31777. exports.getDiffieHellman = dh.getDiffieHellman;
  31778. exports.createDiffieHellman = dh.createDiffieHellman;
  31779. exports.DiffieHellman = dh.DiffieHellman;
  31780. var sign = require('browserify-sign');
  31781. exports.createSign = sign.createSign;
  31782. exports.Sign = sign.Sign;
  31783. exports.createVerify = sign.createVerify;
  31784. exports.Verify = sign.Verify;
  31785. exports.createECDH = require('create-ecdh');
  31786. var publicEncrypt = require('public-encrypt');
  31787. exports.publicEncrypt = publicEncrypt.publicEncrypt;
  31788. exports.privateEncrypt = publicEncrypt.privateEncrypt;
  31789. exports.publicDecrypt = publicEncrypt.publicDecrypt;
  31790. exports.privateDecrypt = publicEncrypt.privateDecrypt;
  31791. // the least I can do is make error messages for the rest of the node.js/crypto api.
  31792. // ;[
  31793. // 'createCredentials'
  31794. // ].forEach(function (name) {
  31795. // exports[name] = function () {
  31796. // throw new Error([
  31797. // 'sorry, ' + name + ' is not implemented yet',
  31798. // 'we accept pull requests',
  31799. // 'https://github.com/crypto-browserify/crypto-browserify'
  31800. // ].join('\n'))
  31801. // }
  31802. // })
  31803. var rf = require('randomfill');
  31804. exports.randomFill = rf.randomFill;
  31805. exports.randomFillSync = rf.randomFillSync;
  31806. exports.createCredentials = function () {
  31807. throw new Error(['sorry, createCredentials is not implemented yet', 'we accept pull requests', 'https://github.com/crypto-browserify/crypto-browserify'].join('\n'));
  31808. };
  31809. exports.constants = {
  31810. 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
  31811. 'DH_CHECK_P_NOT_PRIME': 1,
  31812. 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
  31813. 'DH_NOT_SUITABLE_GENERATOR': 8,
  31814. 'NPN_ENABLED': 1,
  31815. 'ALPN_ENABLED': 1,
  31816. 'RSA_PKCS1_PADDING': 1,
  31817. 'RSA_SSLV23_PADDING': 2,
  31818. 'RSA_NO_PADDING': 3,
  31819. 'RSA_PKCS1_OAEP_PADDING': 4,
  31820. 'RSA_X931_PADDING': 5,
  31821. 'RSA_PKCS1_PSS_PADDING': 6,
  31822. 'POINT_CONVERSION_COMPRESSED': 2,
  31823. 'POINT_CONVERSION_UNCOMPRESSED': 4,
  31824. 'POINT_CONVERSION_HYBRID': 6
  31825. };
  31826. },{"browserify-cipher":206,"browserify-sign":213,"browserify-sign/algos":210,"create-ecdh":384,"create-hash":386,"create-hmac":388,"diffie-hellman":400,"pbkdf2":460,"public-encrypt":468,"randombytes":475,"randomfill":476}],391:[function(require,module,exports){
  31827. "use strict";
  31828. !function (t, e) {
  31829. "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
  31830. }(void 0, function () {
  31831. "use strict";
  31832. var t = 1e3,
  31833. e = 6e4,
  31834. n = 36e5,
  31835. r = "millisecond",
  31836. i = "second",
  31837. s = "minute",
  31838. u = "hour",
  31839. a = "day",
  31840. o = "week",
  31841. c = "month",
  31842. f = "quarter",
  31843. h = "year",
  31844. d = "date",
  31845. l = "Invalid Date",
  31846. $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,
  31847. y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,
  31848. M = {
  31849. name: "en",
  31850. weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
  31851. months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
  31852. ordinal: function (t) {
  31853. var e = ["th", "st", "nd", "rd"],
  31854. n = t % 100;
  31855. return "[" + t + (e[(n - 20) % 10] || e[n] || e[0]) + "]";
  31856. }
  31857. },
  31858. m = function (t, e, n) {
  31859. var r = String(t);
  31860. return !r || r.length >= e ? t : "" + Array(e + 1 - r.length).join(n) + t;
  31861. },
  31862. v = {
  31863. s: m,
  31864. z: function (t) {
  31865. var e = -t.utcOffset(),
  31866. n = Math.abs(e),
  31867. r = Math.floor(n / 60),
  31868. i = n % 60;
  31869. return (e <= 0 ? "+" : "-") + m(r, 2, "0") + ":" + m(i, 2, "0");
  31870. },
  31871. m: function t(e, n) {
  31872. if (e.date() < n.date()) return -t(n, e);
  31873. var r = 12 * (n.year() - e.year()) + (n.month() - e.month()),
  31874. i = e.clone().add(r, c),
  31875. s = n - i < 0,
  31876. u = e.clone().add(r + (s ? -1 : 1), c);
  31877. return +(-(r + (n - i) / (s ? i - u : u - i)) || 0);
  31878. },
  31879. a: function (t) {
  31880. return t < 0 ? Math.ceil(t) || 0 : Math.floor(t);
  31881. },
  31882. p: function (t) {
  31883. return {
  31884. M: c,
  31885. y: h,
  31886. w: o,
  31887. d: a,
  31888. D: d,
  31889. h: u,
  31890. m: s,
  31891. s: i,
  31892. ms: r,
  31893. Q: f
  31894. }[t] || String(t || "").toLowerCase().replace(/s$/, "");
  31895. },
  31896. u: function (t) {
  31897. return void 0 === t;
  31898. }
  31899. },
  31900. g = "en",
  31901. D = {};
  31902. D[g] = M;
  31903. var p = "$isDayjsObject",
  31904. S = function (t) {
  31905. return t instanceof _ || !(!t || !t[p]);
  31906. },
  31907. w = function t(e, n, r) {
  31908. var i;
  31909. if (!e) return g;
  31910. if ("string" == typeof e) {
  31911. var s = e.toLowerCase();
  31912. D[s] && (i = s), n && (D[s] = n, i = s);
  31913. var u = e.split("-");
  31914. if (!i && u.length > 1) return t(u[0]);
  31915. } else {
  31916. var a = e.name;
  31917. D[a] = e, i = a;
  31918. }
  31919. return !r && i && (g = i), i || !r && g;
  31920. },
  31921. O = function (t, e) {
  31922. if (S(t)) return t.clone();
  31923. var n = "object" == typeof e ? e : {};
  31924. return n.date = t, n.args = arguments, new _(n);
  31925. },
  31926. b = v;
  31927. b.l = w, b.i = S, b.w = function (t, e) {
  31928. return O(t, {
  31929. locale: e.$L,
  31930. utc: e.$u,
  31931. x: e.$x,
  31932. $offset: e.$offset
  31933. });
  31934. };
  31935. var _ = function () {
  31936. function M(t) {
  31937. this.$L = w(t.locale, null, !0), this.parse(t), this.$x = this.$x || t.x || {}, this[p] = !0;
  31938. }
  31939. var m = M.prototype;
  31940. return m.parse = function (t) {
  31941. this.$d = function (t) {
  31942. var e = t.date,
  31943. n = t.utc;
  31944. if (null === e) return new Date(NaN);
  31945. if (b.u(e)) return new Date();
  31946. if (e instanceof Date) return new Date(e);
  31947. if ("string" == typeof e && !/Z$/i.test(e)) {
  31948. var r = e.match($);
  31949. if (r) {
  31950. var i = r[2] - 1 || 0,
  31951. s = (r[7] || "0").substring(0, 3);
  31952. return n ? new Date(Date.UTC(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s)) : new Date(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s);
  31953. }
  31954. }
  31955. return new Date(e);
  31956. }(t), this.init();
  31957. }, m.init = function () {
  31958. var t = this.$d;
  31959. this.$y = t.getFullYear(), this.$M = t.getMonth(), this.$D = t.getDate(), this.$W = t.getDay(), this.$H = t.getHours(), this.$m = t.getMinutes(), this.$s = t.getSeconds(), this.$ms = t.getMilliseconds();
  31960. }, m.$utils = function () {
  31961. return b;
  31962. }, m.isValid = function () {
  31963. return !(this.$d.toString() === l);
  31964. }, m.isSame = function (t, e) {
  31965. var n = O(t);
  31966. return this.startOf(e) <= n && n <= this.endOf(e);
  31967. }, m.isAfter = function (t, e) {
  31968. return O(t) < this.startOf(e);
  31969. }, m.isBefore = function (t, e) {
  31970. return this.endOf(e) < O(t);
  31971. }, m.$g = function (t, e, n) {
  31972. return b.u(t) ? this[e] : this.set(n, t);
  31973. }, m.unix = function () {
  31974. return Math.floor(this.valueOf() / 1e3);
  31975. }, m.valueOf = function () {
  31976. return this.$d.getTime();
  31977. }, m.startOf = function (t, e) {
  31978. var n = this,
  31979. r = !!b.u(e) || e,
  31980. f = b.p(t),
  31981. l = function (t, e) {
  31982. var i = b.w(n.$u ? Date.UTC(n.$y, e, t) : new Date(n.$y, e, t), n);
  31983. return r ? i : i.endOf(a);
  31984. },
  31985. $ = function (t, e) {
  31986. return b.w(n.toDate()[t].apply(n.toDate("s"), (r ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e)), n);
  31987. },
  31988. y = this.$W,
  31989. M = this.$M,
  31990. m = this.$D,
  31991. v = "set" + (this.$u ? "UTC" : "");
  31992. switch (f) {
  31993. case h:
  31994. return r ? l(1, 0) : l(31, 11);
  31995. case c:
  31996. return r ? l(1, M) : l(0, M + 1);
  31997. case o:
  31998. var g = this.$locale().weekStart || 0,
  31999. D = (y < g ? y + 7 : y) - g;
  32000. return l(r ? m - D : m + (6 - D), M);
  32001. case a:
  32002. case d:
  32003. return $(v + "Hours", 0);
  32004. case u:
  32005. return $(v + "Minutes", 1);
  32006. case s:
  32007. return $(v + "Seconds", 2);
  32008. case i:
  32009. return $(v + "Milliseconds", 3);
  32010. default:
  32011. return this.clone();
  32012. }
  32013. }, m.endOf = function (t) {
  32014. return this.startOf(t, !1);
  32015. }, m.$set = function (t, e) {
  32016. var n,
  32017. o = b.p(t),
  32018. f = "set" + (this.$u ? "UTC" : ""),
  32019. l = (n = {}, n[a] = f + "Date", n[d] = f + "Date", n[c] = f + "Month", n[h] = f + "FullYear", n[u] = f + "Hours", n[s] = f + "Minutes", n[i] = f + "Seconds", n[r] = f + "Milliseconds", n)[o],
  32020. $ = o === a ? this.$D + (e - this.$W) : e;
  32021. if (o === c || o === h) {
  32022. var y = this.clone().set(d, 1);
  32023. y.$d[l]($), y.init(), this.$d = y.set(d, Math.min(this.$D, y.daysInMonth())).$d;
  32024. } else l && this.$d[l]($);
  32025. return this.init(), this;
  32026. }, m.set = function (t, e) {
  32027. return this.clone().$set(t, e);
  32028. }, m.get = function (t) {
  32029. return this[b.p(t)]();
  32030. }, m.add = function (r, f) {
  32031. var d,
  32032. l = this;
  32033. r = Number(r);
  32034. var $ = b.p(f),
  32035. y = function (t) {
  32036. var e = O(l);
  32037. return b.w(e.date(e.date() + Math.round(t * r)), l);
  32038. };
  32039. if ($ === c) return this.set(c, this.$M + r);
  32040. if ($ === h) return this.set(h, this.$y + r);
  32041. if ($ === a) return y(1);
  32042. if ($ === o) return y(7);
  32043. var M = (d = {}, d[s] = e, d[u] = n, d[i] = t, d)[$] || 1,
  32044. m = this.$d.getTime() + r * M;
  32045. return b.w(m, this);
  32046. }, m.subtract = function (t, e) {
  32047. return this.add(-1 * t, e);
  32048. }, m.format = function (t) {
  32049. var e = this,
  32050. n = this.$locale();
  32051. if (!this.isValid()) return n.invalidDate || l;
  32052. var r = t || "YYYY-MM-DDTHH:mm:ssZ",
  32053. i = b.z(this),
  32054. s = this.$H,
  32055. u = this.$m,
  32056. a = this.$M,
  32057. o = n.weekdays,
  32058. c = n.months,
  32059. f = n.meridiem,
  32060. h = function (t, n, i, s) {
  32061. return t && (t[n] || t(e, r)) || i[n].slice(0, s);
  32062. },
  32063. d = function (t) {
  32064. return b.s(s % 12 || 12, t, "0");
  32065. },
  32066. $ = f || function (t, e, n) {
  32067. var r = t < 12 ? "AM" : "PM";
  32068. return n ? r.toLowerCase() : r;
  32069. };
  32070. return r.replace(y, function (t, r) {
  32071. return r || function (t) {
  32072. switch (t) {
  32073. case "YY":
  32074. return String(e.$y).slice(-2);
  32075. case "YYYY":
  32076. return b.s(e.$y, 4, "0");
  32077. case "M":
  32078. return a + 1;
  32079. case "MM":
  32080. return b.s(a + 1, 2, "0");
  32081. case "MMM":
  32082. return h(n.monthsShort, a, c, 3);
  32083. case "MMMM":
  32084. return h(c, a);
  32085. case "D":
  32086. return e.$D;
  32087. case "DD":
  32088. return b.s(e.$D, 2, "0");
  32089. case "d":
  32090. return String(e.$W);
  32091. case "dd":
  32092. return h(n.weekdaysMin, e.$W, o, 2);
  32093. case "ddd":
  32094. return h(n.weekdaysShort, e.$W, o, 3);
  32095. case "dddd":
  32096. return o[e.$W];
  32097. case "H":
  32098. return String(s);
  32099. case "HH":
  32100. return b.s(s, 2, "0");
  32101. case "h":
  32102. return d(1);
  32103. case "hh":
  32104. return d(2);
  32105. case "a":
  32106. return $(s, u, !0);
  32107. case "A":
  32108. return $(s, u, !1);
  32109. case "m":
  32110. return String(u);
  32111. case "mm":
  32112. return b.s(u, 2, "0");
  32113. case "s":
  32114. return String(e.$s);
  32115. case "ss":
  32116. return b.s(e.$s, 2, "0");
  32117. case "SSS":
  32118. return b.s(e.$ms, 3, "0");
  32119. case "Z":
  32120. return i;
  32121. }
  32122. return null;
  32123. }(t) || i.replace(":", "");
  32124. });
  32125. }, m.utcOffset = function () {
  32126. return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
  32127. }, m.diff = function (r, d, l) {
  32128. var $,
  32129. y = this,
  32130. M = b.p(d),
  32131. m = O(r),
  32132. v = (m.utcOffset() - this.utcOffset()) * e,
  32133. g = this - m,
  32134. D = function () {
  32135. return b.m(y, m);
  32136. };
  32137. switch (M) {
  32138. case h:
  32139. $ = D() / 12;
  32140. break;
  32141. case c:
  32142. $ = D();
  32143. break;
  32144. case f:
  32145. $ = D() / 3;
  32146. break;
  32147. case o:
  32148. $ = (g - v) / 6048e5;
  32149. break;
  32150. case a:
  32151. $ = (g - v) / 864e5;
  32152. break;
  32153. case u:
  32154. $ = g / n;
  32155. break;
  32156. case s:
  32157. $ = g / e;
  32158. break;
  32159. case i:
  32160. $ = g / t;
  32161. break;
  32162. default:
  32163. $ = g;
  32164. }
  32165. return l ? $ : b.a($);
  32166. }, m.daysInMonth = function () {
  32167. return this.endOf(c).$D;
  32168. }, m.$locale = function () {
  32169. return D[this.$L];
  32170. }, m.locale = function (t, e) {
  32171. if (!t) return this.$L;
  32172. var n = this.clone(),
  32173. r = w(t, e, !0);
  32174. return r && (n.$L = r), n;
  32175. }, m.clone = function () {
  32176. return b.w(this.$d, this);
  32177. }, m.toDate = function () {
  32178. return new Date(this.valueOf());
  32179. }, m.toJSON = function () {
  32180. return this.isValid() ? this.toISOString() : null;
  32181. }, m.toISOString = function () {
  32182. return this.$d.toISOString();
  32183. }, m.toString = function () {
  32184. return this.$d.toUTCString();
  32185. }, M;
  32186. }(),
  32187. k = _.prototype;
  32188. return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function (t) {
  32189. k[t[1]] = function (e) {
  32190. return this.$g(e, t[0], t[1]);
  32191. };
  32192. }), O.extend = function (t, e) {
  32193. return t.$i || (t(e, _, O), t.$i = !0), O;
  32194. }, O.locale = w, O.isDayjs = S, O.unix = function (t) {
  32195. return O(1e3 * t);
  32196. }, O.en = D[g], O.Ls = D, O.p = {}, O;
  32197. });
  32198. },{}],392:[function(require,module,exports){
  32199. "use strict";
  32200. !function (e, t) {
  32201. "object" == typeof exports && "undefined" != typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define(t) : (e = "undefined" != typeof globalThis ? globalThis : e || self).dayjs_plugin_customParseFormat = t();
  32202. }(void 0, function () {
  32203. "use strict";
  32204. var e = {
  32205. LTS: "h:mm:ss A",
  32206. LT: "h:mm A",
  32207. L: "MM/DD/YYYY",
  32208. LL: "MMMM D, YYYY",
  32209. LLL: "MMMM D, YYYY h:mm A",
  32210. LLLL: "dddd, MMMM D, YYYY h:mm A"
  32211. },
  32212. t = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|YYYY|YY?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,
  32213. n = /\d\d/,
  32214. r = /\d\d?/,
  32215. i = /\d*[^-_:/,()\s\d]+/,
  32216. o = {},
  32217. s = function (e) {
  32218. return (e = +e) + (e > 68 ? 1900 : 2e3);
  32219. };
  32220. var a = function (e) {
  32221. return function (t) {
  32222. this[e] = +t;
  32223. };
  32224. },
  32225. f = [/[+-]\d\d:?(\d\d)?|Z/, function (e) {
  32226. (this.zone || (this.zone = {})).offset = function (e) {
  32227. if (!e) return 0;
  32228. if ("Z" === e) return 0;
  32229. var t = e.match(/([+-]|\d\d)/g),
  32230. n = 60 * t[1] + (+t[2] || 0);
  32231. return 0 === n ? 0 : "+" === t[0] ? -n : n;
  32232. }(e);
  32233. }],
  32234. h = function (e) {
  32235. var t = o[e];
  32236. return t && (t.indexOf ? t : t.s.concat(t.f));
  32237. },
  32238. u = function (e, t) {
  32239. var n,
  32240. r = o.meridiem;
  32241. if (r) {
  32242. for (var i = 1; i <= 24; i += 1) if (e.indexOf(r(i, 0, t)) > -1) {
  32243. n = i > 12;
  32244. break;
  32245. }
  32246. } else n = e === (t ? "pm" : "PM");
  32247. return n;
  32248. },
  32249. d = {
  32250. A: [i, function (e) {
  32251. this.afternoon = u(e, !1);
  32252. }],
  32253. a: [i, function (e) {
  32254. this.afternoon = u(e, !0);
  32255. }],
  32256. S: [/\d/, function (e) {
  32257. this.milliseconds = 100 * +e;
  32258. }],
  32259. SS: [n, function (e) {
  32260. this.milliseconds = 10 * +e;
  32261. }],
  32262. SSS: [/\d{3}/, function (e) {
  32263. this.milliseconds = +e;
  32264. }],
  32265. s: [r, a("seconds")],
  32266. ss: [r, a("seconds")],
  32267. m: [r, a("minutes")],
  32268. mm: [r, a("minutes")],
  32269. H: [r, a("hours")],
  32270. h: [r, a("hours")],
  32271. HH: [r, a("hours")],
  32272. hh: [r, a("hours")],
  32273. D: [r, a("day")],
  32274. DD: [n, a("day")],
  32275. Do: [i, function (e) {
  32276. var t = o.ordinal,
  32277. n = e.match(/\d+/);
  32278. if (this.day = n[0], t) for (var r = 1; r <= 31; r += 1) t(r).replace(/\[|\]/g, "") === e && (this.day = r);
  32279. }],
  32280. M: [r, a("month")],
  32281. MM: [n, a("month")],
  32282. MMM: [i, function (e) {
  32283. var t = h("months"),
  32284. n = (h("monthsShort") || t.map(function (e) {
  32285. return e.slice(0, 3);
  32286. })).indexOf(e) + 1;
  32287. if (n < 1) throw new Error();
  32288. this.month = n % 12 || n;
  32289. }],
  32290. MMMM: [i, function (e) {
  32291. var t = h("months").indexOf(e) + 1;
  32292. if (t < 1) throw new Error();
  32293. this.month = t % 12 || t;
  32294. }],
  32295. Y: [/[+-]?\d+/, a("year")],
  32296. YY: [n, function (e) {
  32297. this.year = s(e);
  32298. }],
  32299. YYYY: [/\d{4}/, a("year")],
  32300. Z: f,
  32301. ZZ: f
  32302. };
  32303. function c(n) {
  32304. var r, i;
  32305. r = n, i = o && o.formats;
  32306. for (var s = (n = r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function (t, n, r) {
  32307. var o = r && r.toUpperCase();
  32308. return n || i[r] || e[r] || i[o].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function (e, t, n) {
  32309. return t || n.slice(1);
  32310. });
  32311. })).match(t), a = s.length, f = 0; f < a; f += 1) {
  32312. var h = s[f],
  32313. u = d[h],
  32314. c = u && u[0],
  32315. l = u && u[1];
  32316. s[f] = l ? {
  32317. regex: c,
  32318. parser: l
  32319. } : h.replace(/^\[|\]$/g, "");
  32320. }
  32321. return function (e) {
  32322. for (var t = {}, n = 0, r = 0; n < a; n += 1) {
  32323. var i = s[n];
  32324. if ("string" == typeof i) r += i.length;else {
  32325. var o = i.regex,
  32326. f = i.parser,
  32327. h = e.slice(r),
  32328. u = o.exec(h)[0];
  32329. f.call(t, u), e = e.replace(u, "");
  32330. }
  32331. }
  32332. return function (e) {
  32333. var t = e.afternoon;
  32334. if (void 0 !== t) {
  32335. var n = e.hours;
  32336. t ? n < 12 && (e.hours += 12) : 12 === n && (e.hours = 0), delete e.afternoon;
  32337. }
  32338. }(t), t;
  32339. };
  32340. }
  32341. return function (e, t, n) {
  32342. n.p.customParseFormat = !0, e && e.parseTwoDigitYear && (s = e.parseTwoDigitYear);
  32343. var r = t.prototype,
  32344. i = r.parse;
  32345. r.parse = function (e) {
  32346. var t = e.date,
  32347. r = e.utc,
  32348. s = e.args;
  32349. this.$u = r;
  32350. var a = s[1];
  32351. if ("string" == typeof a) {
  32352. var f = !0 === s[2],
  32353. h = !0 === s[3],
  32354. u = f || h,
  32355. d = s[2];
  32356. h && (d = s[2]), o = this.$locale(), !f && d && (o = n.Ls[d]), this.$d = function (e, t, n) {
  32357. try {
  32358. if (["x", "X"].indexOf(t) > -1) return new Date(("X" === t ? 1e3 : 1) * e);
  32359. var r = c(t)(e),
  32360. i = r.year,
  32361. o = r.month,
  32362. s = r.day,
  32363. a = r.hours,
  32364. f = r.minutes,
  32365. h = r.seconds,
  32366. u = r.milliseconds,
  32367. d = r.zone,
  32368. l = new Date(),
  32369. m = s || (i || o ? 1 : l.getDate()),
  32370. M = i || l.getFullYear(),
  32371. Y = 0;
  32372. i && !o || (Y = o > 0 ? o - 1 : l.getMonth());
  32373. var p = a || 0,
  32374. v = f || 0,
  32375. D = h || 0,
  32376. g = u || 0;
  32377. return d ? new Date(Date.UTC(M, Y, m, p, v, D, g + 60 * d.offset * 1e3)) : n ? new Date(Date.UTC(M, Y, m, p, v, D, g)) : new Date(M, Y, m, p, v, D, g);
  32378. } catch (e) {
  32379. return new Date("");
  32380. }
  32381. }(t, a, r), this.init(), d && !0 !== d && (this.$L = this.locale(d).$L), u && t != this.format(a) && (this.$d = new Date("")), o = {};
  32382. } else if (a instanceof Array) for (var l = a.length, m = 1; m <= l; m += 1) {
  32383. s[1] = a[m - 1];
  32384. var M = n.apply(this, s);
  32385. if (M.isValid()) {
  32386. this.$d = M.$d, this.$L = M.$L, this.init();
  32387. break;
  32388. }
  32389. m === l && (this.$d = new Date(""));
  32390. } else i.call(this, e);
  32391. };
  32392. };
  32393. });
  32394. },{}],393:[function(require,module,exports){
  32395. "use strict";
  32396. !function (t, i) {
  32397. "object" == typeof exports && "undefined" != typeof module ? module.exports = i() : "function" == typeof define && define.amd ? define(i) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs_plugin_utc = i();
  32398. }(void 0, function () {
  32399. "use strict";
  32400. var t = "minute",
  32401. i = /[+-]\d\d(?::?\d\d)?/g,
  32402. e = /([+-]|\d\d)/g;
  32403. return function (s, f, n) {
  32404. var u = f.prototype;
  32405. n.utc = function (t) {
  32406. var i = {
  32407. date: t,
  32408. utc: !0,
  32409. args: arguments
  32410. };
  32411. return new f(i);
  32412. }, u.utc = function (i) {
  32413. var e = n(this.toDate(), {
  32414. locale: this.$L,
  32415. utc: !0
  32416. });
  32417. return i ? e.add(this.utcOffset(), t) : e;
  32418. }, u.local = function () {
  32419. return n(this.toDate(), {
  32420. locale: this.$L,
  32421. utc: !1
  32422. });
  32423. };
  32424. var o = u.parse;
  32425. u.parse = function (t) {
  32426. t.utc && (this.$u = !0), this.$utils().u(t.$offset) || (this.$offset = t.$offset), o.call(this, t);
  32427. };
  32428. var r = u.init;
  32429. u.init = function () {
  32430. if (this.$u) {
  32431. var t = this.$d;
  32432. this.$y = t.getUTCFullYear(), this.$M = t.getUTCMonth(), this.$D = t.getUTCDate(), this.$W = t.getUTCDay(), this.$H = t.getUTCHours(), this.$m = t.getUTCMinutes(), this.$s = t.getUTCSeconds(), this.$ms = t.getUTCMilliseconds();
  32433. } else r.call(this);
  32434. };
  32435. var a = u.utcOffset;
  32436. u.utcOffset = function (s, f) {
  32437. var n = this.$utils().u;
  32438. if (n(s)) return this.$u ? 0 : n(this.$offset) ? a.call(this) : this.$offset;
  32439. if ("string" == typeof s && (s = function (t) {
  32440. void 0 === t && (t = "");
  32441. var s = t.match(i);
  32442. if (!s) return null;
  32443. var f = ("" + s[0]).match(e) || ["-", 0, 0],
  32444. n = f[0],
  32445. u = 60 * +f[1] + +f[2];
  32446. return 0 === u ? 0 : "+" === n ? u : -u;
  32447. }(s), null === s)) return this;
  32448. var u = Math.abs(s) <= 16 ? 60 * s : s,
  32449. o = this;
  32450. if (f) return o.$offset = u, o.$u = 0 === s, o;
  32451. if (0 !== s) {
  32452. var r = this.$u ? this.toDate().getTimezoneOffset() : -1 * this.utcOffset();
  32453. (o = this.local().add(u + r, t)).$offset = u, o.$x.$localOffset = r;
  32454. } else o = this.utc();
  32455. return o;
  32456. };
  32457. var h = u.format;
  32458. u.format = function (t) {
  32459. var i = t || (this.$u ? "YYYY-MM-DDTHH:mm:ss[Z]" : "");
  32460. return h.call(this, i);
  32461. }, u.valueOf = function () {
  32462. var t = this.$utils().u(this.$offset) ? 0 : this.$offset + (this.$x.$localOffset || this.$d.getTimezoneOffset());
  32463. return this.$d.valueOf() - 6e4 * t;
  32464. }, u.isUTC = function () {
  32465. return !!this.$u;
  32466. }, u.toISOString = function () {
  32467. return this.toDate().toISOString();
  32468. }, u.toString = function () {
  32469. return this.toDate().toUTCString();
  32470. };
  32471. var l = u.toDate;
  32472. u.toDate = function (t) {
  32473. return "s" === t && this.$offset ? n(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate() : l.call(this);
  32474. };
  32475. var c = u.diff;
  32476. u.diff = function (t, i, e) {
  32477. if (t && this.$u === t.$u) return c.call(this, t, i, e);
  32478. var s = this.local(),
  32479. f = n(t).local();
  32480. return c.call(s, f, i, e);
  32481. };
  32482. };
  32483. });
  32484. },{}],394:[function(require,module,exports){
  32485. 'use strict';
  32486. exports.utils = require('./des/utils');
  32487. exports.Cipher = require('./des/cipher');
  32488. exports.DES = require('./des/des');
  32489. exports.CBC = require('./des/cbc');
  32490. exports.EDE = require('./des/ede');
  32491. },{"./des/cbc":395,"./des/cipher":396,"./des/des":397,"./des/ede":398,"./des/utils":399}],395:[function(require,module,exports){
  32492. 'use strict';
  32493. var assert = require('minimalistic-assert');
  32494. var inherits = require('inherits');
  32495. var proto = {};
  32496. function CBCState(iv) {
  32497. assert.equal(iv.length, 8, 'Invalid IV length');
  32498. this.iv = new Array(8);
  32499. for (var i = 0; i < this.iv.length; i++) this.iv[i] = iv[i];
  32500. }
  32501. function instantiate(Base) {
  32502. function CBC(options) {
  32503. Base.call(this, options);
  32504. this._cbcInit();
  32505. }
  32506. inherits(CBC, Base);
  32507. var keys = Object.keys(proto);
  32508. for (var i = 0; i < keys.length; i++) {
  32509. var key = keys[i];
  32510. CBC.prototype[key] = proto[key];
  32511. }
  32512. CBC.create = function create(options) {
  32513. return new CBC(options);
  32514. };
  32515. return CBC;
  32516. }
  32517. exports.instantiate = instantiate;
  32518. proto._cbcInit = function _cbcInit() {
  32519. var state = new CBCState(this.options.iv);
  32520. this._cbcState = state;
  32521. };
  32522. proto._update = function _update(inp, inOff, out, outOff) {
  32523. var state = this._cbcState;
  32524. var superProto = this.constructor.super_.prototype;
  32525. var iv = state.iv;
  32526. if (this.type === 'encrypt') {
  32527. for (var i = 0; i < this.blockSize; i++) iv[i] ^= inp[inOff + i];
  32528. superProto._update.call(this, iv, 0, out, outOff);
  32529. for (var i = 0; i < this.blockSize; i++) iv[i] = out[outOff + i];
  32530. } else {
  32531. superProto._update.call(this, inp, inOff, out, outOff);
  32532. for (var i = 0; i < this.blockSize; i++) out[outOff + i] ^= iv[i];
  32533. for (var i = 0; i < this.blockSize; i++) iv[i] = inp[inOff + i];
  32534. }
  32535. };
  32536. },{"inherits":440,"minimalistic-assert":453}],396:[function(require,module,exports){
  32537. 'use strict';
  32538. var assert = require('minimalistic-assert');
  32539. function Cipher(options) {
  32540. this.options = options;
  32541. this.type = this.options.type;
  32542. this.blockSize = 8;
  32543. this._init();
  32544. this.buffer = new Array(this.blockSize);
  32545. this.bufferOff = 0;
  32546. this.padding = options.padding !== false;
  32547. }
  32548. module.exports = Cipher;
  32549. Cipher.prototype._init = function _init() {
  32550. // Might be overrided
  32551. };
  32552. Cipher.prototype.update = function update(data) {
  32553. if (data.length === 0) return [];
  32554. if (this.type === 'decrypt') return this._updateDecrypt(data);else return this._updateEncrypt(data);
  32555. };
  32556. Cipher.prototype._buffer = function _buffer(data, off) {
  32557. // Append data to buffer
  32558. var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
  32559. for (var i = 0; i < min; i++) this.buffer[this.bufferOff + i] = data[off + i];
  32560. this.bufferOff += min;
  32561. // Shift next
  32562. return min;
  32563. };
  32564. Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
  32565. this._update(this.buffer, 0, out, off);
  32566. this.bufferOff = 0;
  32567. return this.blockSize;
  32568. };
  32569. Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
  32570. var inputOff = 0;
  32571. var outputOff = 0;
  32572. var count = (this.bufferOff + data.length) / this.blockSize | 0;
  32573. var out = new Array(count * this.blockSize);
  32574. if (this.bufferOff !== 0) {
  32575. inputOff += this._buffer(data, inputOff);
  32576. if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff);
  32577. }
  32578. // Write blocks
  32579. var max = data.length - (data.length - inputOff) % this.blockSize;
  32580. for (; inputOff < max; inputOff += this.blockSize) {
  32581. this._update(data, inputOff, out, outputOff);
  32582. outputOff += this.blockSize;
  32583. }
  32584. // Queue rest
  32585. for (; inputOff < data.length; inputOff++, this.bufferOff++) this.buffer[this.bufferOff] = data[inputOff];
  32586. return out;
  32587. };
  32588. Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
  32589. var inputOff = 0;
  32590. var outputOff = 0;
  32591. var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
  32592. var out = new Array(count * this.blockSize);
  32593. // TODO(indutny): optimize it, this is far from optimal
  32594. for (; count > 0; count--) {
  32595. inputOff += this._buffer(data, inputOff);
  32596. outputOff += this._flushBuffer(out, outputOff);
  32597. }
  32598. // Buffer rest of the input
  32599. inputOff += this._buffer(data, inputOff);
  32600. return out;
  32601. };
  32602. Cipher.prototype.final = function final(buffer) {
  32603. var first;
  32604. if (buffer) first = this.update(buffer);
  32605. var last;
  32606. if (this.type === 'encrypt') last = this._finalEncrypt();else last = this._finalDecrypt();
  32607. if (first) return first.concat(last);else return last;
  32608. };
  32609. Cipher.prototype._pad = function _pad(buffer, off) {
  32610. if (off === 0) return false;
  32611. while (off < buffer.length) buffer[off++] = 0;
  32612. return true;
  32613. };
  32614. Cipher.prototype._finalEncrypt = function _finalEncrypt() {
  32615. if (!this._pad(this.buffer, this.bufferOff)) return [];
  32616. var out = new Array(this.blockSize);
  32617. this._update(this.buffer, 0, out, 0);
  32618. return out;
  32619. };
  32620. Cipher.prototype._unpad = function _unpad(buffer) {
  32621. return buffer;
  32622. };
  32623. Cipher.prototype._finalDecrypt = function _finalDecrypt() {
  32624. assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
  32625. var out = new Array(this.blockSize);
  32626. this._flushBuffer(out, 0);
  32627. return this._unpad(out);
  32628. };
  32629. },{"minimalistic-assert":453}],397:[function(require,module,exports){
  32630. 'use strict';
  32631. var assert = require('minimalistic-assert');
  32632. var inherits = require('inherits');
  32633. var utils = require('./utils');
  32634. var Cipher = require('./cipher');
  32635. function DESState() {
  32636. this.tmp = new Array(2);
  32637. this.keys = null;
  32638. }
  32639. function DES(options) {
  32640. Cipher.call(this, options);
  32641. var state = new DESState();
  32642. this._desState = state;
  32643. this.deriveKeys(state, options.key);
  32644. }
  32645. inherits(DES, Cipher);
  32646. module.exports = DES;
  32647. DES.create = function create(options) {
  32648. return new DES(options);
  32649. };
  32650. var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1];
  32651. DES.prototype.deriveKeys = function deriveKeys(state, key) {
  32652. state.keys = new Array(16 * 2);
  32653. assert.equal(key.length, this.blockSize, 'Invalid key length');
  32654. var kL = utils.readUInt32BE(key, 0);
  32655. var kR = utils.readUInt32BE(key, 4);
  32656. utils.pc1(kL, kR, state.tmp, 0);
  32657. kL = state.tmp[0];
  32658. kR = state.tmp[1];
  32659. for (var i = 0; i < state.keys.length; i += 2) {
  32660. var shift = shiftTable[i >>> 1];
  32661. kL = utils.r28shl(kL, shift);
  32662. kR = utils.r28shl(kR, shift);
  32663. utils.pc2(kL, kR, state.keys, i);
  32664. }
  32665. };
  32666. DES.prototype._update = function _update(inp, inOff, out, outOff) {
  32667. var state = this._desState;
  32668. var l = utils.readUInt32BE(inp, inOff);
  32669. var r = utils.readUInt32BE(inp, inOff + 4);
  32670. // Initial Permutation
  32671. utils.ip(l, r, state.tmp, 0);
  32672. l = state.tmp[0];
  32673. r = state.tmp[1];
  32674. if (this.type === 'encrypt') this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0);
  32675. l = state.tmp[0];
  32676. r = state.tmp[1];
  32677. utils.writeUInt32BE(out, l, outOff);
  32678. utils.writeUInt32BE(out, r, outOff + 4);
  32679. };
  32680. DES.prototype._pad = function _pad(buffer, off) {
  32681. if (this.padding === false) {
  32682. return false;
  32683. }
  32684. var value = buffer.length - off;
  32685. for (var i = off; i < buffer.length; i++) buffer[i] = value;
  32686. return true;
  32687. };
  32688. DES.prototype._unpad = function _unpad(buffer) {
  32689. if (this.padding === false) {
  32690. return buffer;
  32691. }
  32692. var pad = buffer[buffer.length - 1];
  32693. for (var i = buffer.length - pad; i < buffer.length; i++) assert.equal(buffer[i], pad);
  32694. return buffer.slice(0, buffer.length - pad);
  32695. };
  32696. DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
  32697. var l = lStart;
  32698. var r = rStart;
  32699. // Apply f() x16 times
  32700. for (var i = 0; i < state.keys.length; i += 2) {
  32701. var keyL = state.keys[i];
  32702. var keyR = state.keys[i + 1];
  32703. // f(r, k)
  32704. utils.expand(r, state.tmp, 0);
  32705. keyL ^= state.tmp[0];
  32706. keyR ^= state.tmp[1];
  32707. var s = utils.substitute(keyL, keyR);
  32708. var f = utils.permute(s);
  32709. var t = r;
  32710. r = (l ^ f) >>> 0;
  32711. l = t;
  32712. }
  32713. // Reverse Initial Permutation
  32714. utils.rip(r, l, out, off);
  32715. };
  32716. DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
  32717. var l = rStart;
  32718. var r = lStart;
  32719. // Apply f() x16 times
  32720. for (var i = state.keys.length - 2; i >= 0; i -= 2) {
  32721. var keyL = state.keys[i];
  32722. var keyR = state.keys[i + 1];
  32723. // f(r, k)
  32724. utils.expand(l, state.tmp, 0);
  32725. keyL ^= state.tmp[0];
  32726. keyR ^= state.tmp[1];
  32727. var s = utils.substitute(keyL, keyR);
  32728. var f = utils.permute(s);
  32729. var t = l;
  32730. l = (r ^ f) >>> 0;
  32731. r = t;
  32732. }
  32733. // Reverse Initial Permutation
  32734. utils.rip(l, r, out, off);
  32735. };
  32736. },{"./cipher":396,"./utils":399,"inherits":440,"minimalistic-assert":453}],398:[function(require,module,exports){
  32737. 'use strict';
  32738. var assert = require('minimalistic-assert');
  32739. var inherits = require('inherits');
  32740. var Cipher = require('./cipher');
  32741. var DES = require('./des');
  32742. function EDEState(type, key) {
  32743. assert.equal(key.length, 24, 'Invalid key length');
  32744. var k1 = key.slice(0, 8);
  32745. var k2 = key.slice(8, 16);
  32746. var k3 = key.slice(16, 24);
  32747. if (type === 'encrypt') {
  32748. this.ciphers = [DES.create({
  32749. type: 'encrypt',
  32750. key: k1
  32751. }), DES.create({
  32752. type: 'decrypt',
  32753. key: k2
  32754. }), DES.create({
  32755. type: 'encrypt',
  32756. key: k3
  32757. })];
  32758. } else {
  32759. this.ciphers = [DES.create({
  32760. type: 'decrypt',
  32761. key: k3
  32762. }), DES.create({
  32763. type: 'encrypt',
  32764. key: k2
  32765. }), DES.create({
  32766. type: 'decrypt',
  32767. key: k1
  32768. })];
  32769. }
  32770. }
  32771. function EDE(options) {
  32772. Cipher.call(this, options);
  32773. var state = new EDEState(this.type, this.options.key);
  32774. this._edeState = state;
  32775. }
  32776. inherits(EDE, Cipher);
  32777. module.exports = EDE;
  32778. EDE.create = function create(options) {
  32779. return new EDE(options);
  32780. };
  32781. EDE.prototype._update = function _update(inp, inOff, out, outOff) {
  32782. var state = this._edeState;
  32783. state.ciphers[0]._update(inp, inOff, out, outOff);
  32784. state.ciphers[1]._update(out, outOff, out, outOff);
  32785. state.ciphers[2]._update(out, outOff, out, outOff);
  32786. };
  32787. EDE.prototype._pad = DES.prototype._pad;
  32788. EDE.prototype._unpad = DES.prototype._unpad;
  32789. },{"./cipher":396,"./des":397,"inherits":440,"minimalistic-assert":453}],399:[function(require,module,exports){
  32790. 'use strict';
  32791. exports.readUInt32BE = function readUInt32BE(bytes, off) {
  32792. var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off];
  32793. return res >>> 0;
  32794. };
  32795. exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
  32796. bytes[0 + off] = value >>> 24;
  32797. bytes[1 + off] = value >>> 16 & 0xff;
  32798. bytes[2 + off] = value >>> 8 & 0xff;
  32799. bytes[3 + off] = value & 0xff;
  32800. };
  32801. exports.ip = function ip(inL, inR, out, off) {
  32802. var outL = 0;
  32803. var outR = 0;
  32804. for (var i = 6; i >= 0; i -= 2) {
  32805. for (var j = 0; j <= 24; j += 8) {
  32806. outL <<= 1;
  32807. outL |= inR >>> j + i & 1;
  32808. }
  32809. for (var j = 0; j <= 24; j += 8) {
  32810. outL <<= 1;
  32811. outL |= inL >>> j + i & 1;
  32812. }
  32813. }
  32814. for (var i = 6; i >= 0; i -= 2) {
  32815. for (var j = 1; j <= 25; j += 8) {
  32816. outR <<= 1;
  32817. outR |= inR >>> j + i & 1;
  32818. }
  32819. for (var j = 1; j <= 25; j += 8) {
  32820. outR <<= 1;
  32821. outR |= inL >>> j + i & 1;
  32822. }
  32823. }
  32824. out[off + 0] = outL >>> 0;
  32825. out[off + 1] = outR >>> 0;
  32826. };
  32827. exports.rip = function rip(inL, inR, out, off) {
  32828. var outL = 0;
  32829. var outR = 0;
  32830. for (var i = 0; i < 4; i++) {
  32831. for (var j = 24; j >= 0; j -= 8) {
  32832. outL <<= 1;
  32833. outL |= inR >>> j + i & 1;
  32834. outL <<= 1;
  32835. outL |= inL >>> j + i & 1;
  32836. }
  32837. }
  32838. for (var i = 4; i < 8; i++) {
  32839. for (var j = 24; j >= 0; j -= 8) {
  32840. outR <<= 1;
  32841. outR |= inR >>> j + i & 1;
  32842. outR <<= 1;
  32843. outR |= inL >>> j + i & 1;
  32844. }
  32845. }
  32846. out[off + 0] = outL >>> 0;
  32847. out[off + 1] = outR >>> 0;
  32848. };
  32849. exports.pc1 = function pc1(inL, inR, out, off) {
  32850. var outL = 0;
  32851. var outR = 0;
  32852. // 7, 15, 23, 31, 39, 47, 55, 63
  32853. // 6, 14, 22, 30, 39, 47, 55, 63
  32854. // 5, 13, 21, 29, 39, 47, 55, 63
  32855. // 4, 12, 20, 28
  32856. for (var i = 7; i >= 5; i--) {
  32857. for (var j = 0; j <= 24; j += 8) {
  32858. outL <<= 1;
  32859. outL |= inR >> j + i & 1;
  32860. }
  32861. for (var j = 0; j <= 24; j += 8) {
  32862. outL <<= 1;
  32863. outL |= inL >> j + i & 1;
  32864. }
  32865. }
  32866. for (var j = 0; j <= 24; j += 8) {
  32867. outL <<= 1;
  32868. outL |= inR >> j + i & 1;
  32869. }
  32870. // 1, 9, 17, 25, 33, 41, 49, 57
  32871. // 2, 10, 18, 26, 34, 42, 50, 58
  32872. // 3, 11, 19, 27, 35, 43, 51, 59
  32873. // 36, 44, 52, 60
  32874. for (var i = 1; i <= 3; i++) {
  32875. for (var j = 0; j <= 24; j += 8) {
  32876. outR <<= 1;
  32877. outR |= inR >> j + i & 1;
  32878. }
  32879. for (var j = 0; j <= 24; j += 8) {
  32880. outR <<= 1;
  32881. outR |= inL >> j + i & 1;
  32882. }
  32883. }
  32884. for (var j = 0; j <= 24; j += 8) {
  32885. outR <<= 1;
  32886. outR |= inL >> j + i & 1;
  32887. }
  32888. out[off + 0] = outL >>> 0;
  32889. out[off + 1] = outR >>> 0;
  32890. };
  32891. exports.r28shl = function r28shl(num, shift) {
  32892. return num << shift & 0xfffffff | num >>> 28 - shift;
  32893. };
  32894. var pc2table = [
  32895. // inL => outL
  32896. 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26,
  32897. // inR => outR
  32898. 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24];
  32899. exports.pc2 = function pc2(inL, inR, out, off) {
  32900. var outL = 0;
  32901. var outR = 0;
  32902. var len = pc2table.length >>> 1;
  32903. for (var i = 0; i < len; i++) {
  32904. outL <<= 1;
  32905. outL |= inL >>> pc2table[i] & 0x1;
  32906. }
  32907. for (var i = len; i < pc2table.length; i++) {
  32908. outR <<= 1;
  32909. outR |= inR >>> pc2table[i] & 0x1;
  32910. }
  32911. out[off + 0] = outL >>> 0;
  32912. out[off + 1] = outR >>> 0;
  32913. };
  32914. exports.expand = function expand(r, out, off) {
  32915. var outL = 0;
  32916. var outR = 0;
  32917. outL = (r & 1) << 5 | r >>> 27;
  32918. for (var i = 23; i >= 15; i -= 4) {
  32919. outL <<= 6;
  32920. outL |= r >>> i & 0x3f;
  32921. }
  32922. for (var i = 11; i >= 3; i -= 4) {
  32923. outR |= r >>> i & 0x3f;
  32924. outR <<= 6;
  32925. }
  32926. outR |= (r & 0x1f) << 1 | r >>> 31;
  32927. out[off + 0] = outL >>> 0;
  32928. out[off + 1] = outR >>> 0;
  32929. };
  32930. var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11];
  32931. exports.substitute = function substitute(inL, inR) {
  32932. var out = 0;
  32933. for (var i = 0; i < 4; i++) {
  32934. var b = inL >>> 18 - i * 6 & 0x3f;
  32935. var sb = sTable[i * 0x40 + b];
  32936. out <<= 4;
  32937. out |= sb;
  32938. }
  32939. for (var i = 0; i < 4; i++) {
  32940. var b = inR >>> 18 - i * 6 & 0x3f;
  32941. var sb = sTable[4 * 0x40 + i * 0x40 + b];
  32942. out <<= 4;
  32943. out |= sb;
  32944. }
  32945. return out >>> 0;
  32946. };
  32947. var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7];
  32948. exports.permute = function permute(num) {
  32949. var out = 0;
  32950. for (var i = 0; i < permuteTable.length; i++) {
  32951. out <<= 1;
  32952. out |= num >>> permuteTable[i] & 0x1;
  32953. }
  32954. return out >>> 0;
  32955. };
  32956. exports.padSplit = function padSplit(num, size, group) {
  32957. var str = num.toString(2);
  32958. while (str.length < size) str = '0' + str;
  32959. var out = [];
  32960. for (var i = 0; i < size; i += group) out.push(str.slice(i, i + group));
  32961. return out.join(' ');
  32962. };
  32963. },{}],400:[function(require,module,exports){
  32964. (function (Buffer){(function (){
  32965. "use strict";
  32966. var generatePrime = require('./lib/generatePrime');
  32967. var primes = require('./lib/primes.json');
  32968. var DH = require('./lib/dh');
  32969. function getDiffieHellman(mod) {
  32970. var prime = new Buffer(primes[mod].prime, 'hex');
  32971. var gen = new Buffer(primes[mod].gen, 'hex');
  32972. return new DH(prime, gen);
  32973. }
  32974. var ENCODINGS = {
  32975. 'binary': true,
  32976. 'hex': true,
  32977. 'base64': true
  32978. };
  32979. function createDiffieHellman(prime, enc, generator, genc) {
  32980. if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
  32981. return createDiffieHellman(prime, 'binary', enc, generator);
  32982. }
  32983. enc = enc || 'binary';
  32984. genc = genc || 'binary';
  32985. generator = generator || new Buffer([2]);
  32986. if (!Buffer.isBuffer(generator)) {
  32987. generator = new Buffer(generator, genc);
  32988. }
  32989. if (typeof prime === 'number') {
  32990. return new DH(generatePrime(prime, generator), generator, true);
  32991. }
  32992. if (!Buffer.isBuffer(prime)) {
  32993. prime = new Buffer(prime, enc);
  32994. }
  32995. return new DH(prime, generator, true);
  32996. }
  32997. exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman;
  32998. exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman;
  32999. }).call(this)}).call(this,require("buffer").Buffer)
  33000. },{"./lib/dh":401,"./lib/generatePrime":402,"./lib/primes.json":403,"buffer":220}],401:[function(require,module,exports){
  33001. (function (Buffer){(function (){
  33002. "use strict";
  33003. var BN = require('bn.js');
  33004. var MillerRabin = require('miller-rabin');
  33005. var millerRabin = new MillerRabin();
  33006. var TWENTYFOUR = new BN(24);
  33007. var ELEVEN = new BN(11);
  33008. var TEN = new BN(10);
  33009. var THREE = new BN(3);
  33010. var SEVEN = new BN(7);
  33011. var primes = require('./generatePrime');
  33012. var randomBytes = require('randombytes');
  33013. module.exports = DH;
  33014. function setPublicKey(pub, enc) {
  33015. enc = enc || 'utf8';
  33016. if (!Buffer.isBuffer(pub)) {
  33017. pub = new Buffer(pub, enc);
  33018. }
  33019. this._pub = new BN(pub);
  33020. return this;
  33021. }
  33022. function setPrivateKey(priv, enc) {
  33023. enc = enc || 'utf8';
  33024. if (!Buffer.isBuffer(priv)) {
  33025. priv = new Buffer(priv, enc);
  33026. }
  33027. this._priv = new BN(priv);
  33028. return this;
  33029. }
  33030. var primeCache = {};
  33031. function checkPrime(prime, generator) {
  33032. var gen = generator.toString('hex');
  33033. var hex = [gen, prime.toString(16)].join('_');
  33034. if (hex in primeCache) {
  33035. return primeCache[hex];
  33036. }
  33037. var error = 0;
  33038. if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) {
  33039. //not a prime so +1
  33040. error += 1;
  33041. if (gen === '02' || gen === '05') {
  33042. // we'd be able to check the generator
  33043. // it would fail so +8
  33044. error += 8;
  33045. } else {
  33046. //we wouldn't be able to test the generator
  33047. // so +4
  33048. error += 4;
  33049. }
  33050. primeCache[hex] = error;
  33051. return error;
  33052. }
  33053. if (!millerRabin.test(prime.shrn(1))) {
  33054. //not a safe prime
  33055. error += 2;
  33056. }
  33057. var rem;
  33058. switch (gen) {
  33059. case '02':
  33060. if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
  33061. // unsuidable generator
  33062. error += 8;
  33063. }
  33064. break;
  33065. case '05':
  33066. rem = prime.mod(TEN);
  33067. if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
  33068. // prime mod 10 needs to equal 3 or 7
  33069. error += 8;
  33070. }
  33071. break;
  33072. default:
  33073. error += 4;
  33074. }
  33075. primeCache[hex] = error;
  33076. return error;
  33077. }
  33078. function DH(prime, generator, malleable) {
  33079. this.setGenerator(generator);
  33080. this.__prime = new BN(prime);
  33081. this._prime = BN.mont(this.__prime);
  33082. this._primeLen = prime.length;
  33083. this._pub = undefined;
  33084. this._priv = undefined;
  33085. this._primeCode = undefined;
  33086. if (malleable) {
  33087. this.setPublicKey = setPublicKey;
  33088. this.setPrivateKey = setPrivateKey;
  33089. } else {
  33090. this._primeCode = 8;
  33091. }
  33092. }
  33093. Object.defineProperty(DH.prototype, 'verifyError', {
  33094. enumerable: true,
  33095. get: function () {
  33096. if (typeof this._primeCode !== 'number') {
  33097. this._primeCode = checkPrime(this.__prime, this.__gen);
  33098. }
  33099. return this._primeCode;
  33100. }
  33101. });
  33102. DH.prototype.generateKeys = function () {
  33103. if (!this._priv) {
  33104. this._priv = new BN(randomBytes(this._primeLen));
  33105. }
  33106. this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
  33107. return this.getPublicKey();
  33108. };
  33109. DH.prototype.computeSecret = function (other) {
  33110. other = new BN(other);
  33111. other = other.toRed(this._prime);
  33112. var secret = other.redPow(this._priv).fromRed();
  33113. var out = new Buffer(secret.toArray());
  33114. var prime = this.getPrime();
  33115. if (out.length < prime.length) {
  33116. var front = new Buffer(prime.length - out.length);
  33117. front.fill(0);
  33118. out = Buffer.concat([front, out]);
  33119. }
  33120. return out;
  33121. };
  33122. DH.prototype.getPublicKey = function getPublicKey(enc) {
  33123. return formatReturnValue(this._pub, enc);
  33124. };
  33125. DH.prototype.getPrivateKey = function getPrivateKey(enc) {
  33126. return formatReturnValue(this._priv, enc);
  33127. };
  33128. DH.prototype.getPrime = function (enc) {
  33129. return formatReturnValue(this.__prime, enc);
  33130. };
  33131. DH.prototype.getGenerator = function (enc) {
  33132. return formatReturnValue(this._gen, enc);
  33133. };
  33134. DH.prototype.setGenerator = function (gen, enc) {
  33135. enc = enc || 'utf8';
  33136. if (!Buffer.isBuffer(gen)) {
  33137. gen = new Buffer(gen, enc);
  33138. }
  33139. this.__gen = gen;
  33140. this._gen = new BN(gen);
  33141. return this;
  33142. };
  33143. function formatReturnValue(bn, enc) {
  33144. var buf = new Buffer(bn.toArray());
  33145. if (!enc) {
  33146. return buf;
  33147. } else {
  33148. return buf.toString(enc);
  33149. }
  33150. }
  33151. }).call(this)}).call(this,require("buffer").Buffer)
  33152. },{"./generatePrime":402,"bn.js":404,"buffer":220,"miller-rabin":451,"randombytes":475}],402:[function(require,module,exports){
  33153. "use strict";
  33154. var randomBytes = require('randombytes');
  33155. module.exports = findPrime;
  33156. findPrime.simpleSieve = simpleSieve;
  33157. findPrime.fermatTest = fermatTest;
  33158. var BN = require('bn.js');
  33159. var TWENTYFOUR = new BN(24);
  33160. var MillerRabin = require('miller-rabin');
  33161. var millerRabin = new MillerRabin();
  33162. var ONE = new BN(1);
  33163. var TWO = new BN(2);
  33164. var FIVE = new BN(5);
  33165. var SIXTEEN = new BN(16);
  33166. var EIGHT = new BN(8);
  33167. var TEN = new BN(10);
  33168. var THREE = new BN(3);
  33169. var SEVEN = new BN(7);
  33170. var ELEVEN = new BN(11);
  33171. var FOUR = new BN(4);
  33172. var TWELVE = new BN(12);
  33173. var primes = null;
  33174. function _getPrimes() {
  33175. if (primes !== null) return primes;
  33176. var limit = 0x100000;
  33177. var res = [];
  33178. res[0] = 2;
  33179. for (var i = 1, k = 3; k < limit; k += 2) {
  33180. var sqrt = Math.ceil(Math.sqrt(k));
  33181. for (var j = 0; j < i && res[j] <= sqrt; j++) if (k % res[j] === 0) break;
  33182. if (i !== j && res[j] <= sqrt) continue;
  33183. res[i++] = k;
  33184. }
  33185. primes = res;
  33186. return res;
  33187. }
  33188. function simpleSieve(p) {
  33189. var primes = _getPrimes();
  33190. for (var i = 0; i < primes.length; i++) if (p.modn(primes[i]) === 0) {
  33191. if (p.cmpn(primes[i]) === 0) {
  33192. return true;
  33193. } else {
  33194. return false;
  33195. }
  33196. }
  33197. return true;
  33198. }
  33199. function fermatTest(p) {
  33200. var red = BN.mont(p);
  33201. return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
  33202. }
  33203. function findPrime(bits, gen) {
  33204. if (bits < 16) {
  33205. // this is what openssl does
  33206. if (gen === 2 || gen === 5) {
  33207. return new BN([0x8c, 0x7b]);
  33208. } else {
  33209. return new BN([0x8c, 0x27]);
  33210. }
  33211. }
  33212. gen = new BN(gen);
  33213. var num, n2;
  33214. while (true) {
  33215. num = new BN(randomBytes(Math.ceil(bits / 8)));
  33216. while (num.bitLength() > bits) {
  33217. num.ishrn(1);
  33218. }
  33219. if (num.isEven()) {
  33220. num.iadd(ONE);
  33221. }
  33222. if (!num.testn(1)) {
  33223. num.iadd(TWO);
  33224. }
  33225. if (!gen.cmp(TWO)) {
  33226. while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
  33227. num.iadd(FOUR);
  33228. }
  33229. } else if (!gen.cmp(FIVE)) {
  33230. while (num.mod(TEN).cmp(THREE)) {
  33231. num.iadd(FOUR);
  33232. }
  33233. }
  33234. n2 = num.shrn(1);
  33235. if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) {
  33236. return num;
  33237. }
  33238. }
  33239. }
  33240. },{"bn.js":404,"miller-rabin":451,"randombytes":475}],403:[function(require,module,exports){
  33241. module.exports={
  33242. "modp1": {
  33243. "gen": "02",
  33244. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"
  33245. },
  33246. "modp2": {
  33247. "gen": "02",
  33248. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"
  33249. },
  33250. "modp5": {
  33251. "gen": "02",
  33252. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"
  33253. },
  33254. "modp14": {
  33255. "gen": "02",
  33256. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"
  33257. },
  33258. "modp15": {
  33259. "gen": "02",
  33260. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"
  33261. },
  33262. "modp16": {
  33263. "gen": "02",
  33264. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"
  33265. },
  33266. "modp17": {
  33267. "gen": "02",
  33268. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"
  33269. },
  33270. "modp18": {
  33271. "gen": "02",
  33272. "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"
  33273. }
  33274. }
  33275. },{}],404:[function(require,module,exports){
  33276. arguments[4][184][0].apply(exports,arguments)
  33277. },{"buffer":188,"dup":184}],405:[function(require,module,exports){
  33278. 'use strict';
  33279. var elliptic = exports;
  33280. elliptic.version = require('../package.json').version;
  33281. elliptic.utils = require('./elliptic/utils');
  33282. elliptic.rand = require('brorand');
  33283. elliptic.curve = require('./elliptic/curve');
  33284. elliptic.curves = require('./elliptic/curves');
  33285. // Protocols
  33286. elliptic.ec = require('./elliptic/ec');
  33287. elliptic.eddsa = require('./elliptic/eddsa');
  33288. },{"../package.json":421,"./elliptic/curve":408,"./elliptic/curves":411,"./elliptic/ec":412,"./elliptic/eddsa":415,"./elliptic/utils":419,"brorand":187}],406:[function(require,module,exports){
  33289. 'use strict';
  33290. var BN = require('bn.js');
  33291. var utils = require('../utils');
  33292. var getNAF = utils.getNAF;
  33293. var getJSF = utils.getJSF;
  33294. var assert = utils.assert;
  33295. function BaseCurve(type, conf) {
  33296. this.type = type;
  33297. this.p = new BN(conf.p, 16);
  33298. // Use Montgomery, when there is no fast reduction for the prime
  33299. this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
  33300. // Useful for many curves
  33301. this.zero = new BN(0).toRed(this.red);
  33302. this.one = new BN(1).toRed(this.red);
  33303. this.two = new BN(2).toRed(this.red);
  33304. // Curve configuration, optional
  33305. this.n = conf.n && new BN(conf.n, 16);
  33306. this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
  33307. // Temporary arrays
  33308. this._wnafT1 = new Array(4);
  33309. this._wnafT2 = new Array(4);
  33310. this._wnafT3 = new Array(4);
  33311. this._wnafT4 = new Array(4);
  33312. this._bitLength = this.n ? this.n.bitLength() : 0;
  33313. // Generalized Greg Maxwell's trick
  33314. var adjustCount = this.n && this.p.div(this.n);
  33315. if (!adjustCount || adjustCount.cmpn(100) > 0) {
  33316. this.redN = null;
  33317. } else {
  33318. this._maxwellTrick = true;
  33319. this.redN = this.n.toRed(this.red);
  33320. }
  33321. }
  33322. module.exports = BaseCurve;
  33323. BaseCurve.prototype.point = function point() {
  33324. throw new Error('Not implemented');
  33325. };
  33326. BaseCurve.prototype.validate = function validate() {
  33327. throw new Error('Not implemented');
  33328. };
  33329. BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
  33330. assert(p.precomputed);
  33331. var doubles = p._getDoubles();
  33332. var naf = getNAF(k, 1, this._bitLength);
  33333. var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1);
  33334. I /= 3;
  33335. // Translate into more windowed form
  33336. var repr = [];
  33337. var j;
  33338. var nafW;
  33339. for (j = 0; j < naf.length; j += doubles.step) {
  33340. nafW = 0;
  33341. for (var l = j + doubles.step - 1; l >= j; l--) nafW = (nafW << 1) + naf[l];
  33342. repr.push(nafW);
  33343. }
  33344. var a = this.jpoint(null, null, null);
  33345. var b = this.jpoint(null, null, null);
  33346. for (var i = I; i > 0; i--) {
  33347. for (j = 0; j < repr.length; j++) {
  33348. nafW = repr[j];
  33349. if (nafW === i) b = b.mixedAdd(doubles.points[j]);else if (nafW === -i) b = b.mixedAdd(doubles.points[j].neg());
  33350. }
  33351. a = a.add(b);
  33352. }
  33353. return a.toP();
  33354. };
  33355. BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
  33356. var w = 4;
  33357. // Precompute window
  33358. var nafPoints = p._getNAFPoints(w);
  33359. w = nafPoints.wnd;
  33360. var wnd = nafPoints.points;
  33361. // Get NAF form
  33362. var naf = getNAF(k, w, this._bitLength);
  33363. // Add `this`*(N+1) for every w-NAF index
  33364. var acc = this.jpoint(null, null, null);
  33365. for (var i = naf.length - 1; i >= 0; i--) {
  33366. // Count zeroes
  33367. for (var l = 0; i >= 0 && naf[i] === 0; i--) l++;
  33368. if (i >= 0) l++;
  33369. acc = acc.dblp(l);
  33370. if (i < 0) break;
  33371. var z = naf[i];
  33372. assert(z !== 0);
  33373. if (p.type === 'affine') {
  33374. // J +- P
  33375. if (z > 0) acc = acc.mixedAdd(wnd[z - 1 >> 1]);else acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg());
  33376. } else {
  33377. // J +- J
  33378. if (z > 0) acc = acc.add(wnd[z - 1 >> 1]);else acc = acc.add(wnd[-z - 1 >> 1].neg());
  33379. }
  33380. }
  33381. return p.type === 'affine' ? acc.toP() : acc;
  33382. };
  33383. BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) {
  33384. var wndWidth = this._wnafT1;
  33385. var wnd = this._wnafT2;
  33386. var naf = this._wnafT3;
  33387. // Fill all arrays
  33388. var max = 0;
  33389. var i;
  33390. var j;
  33391. var p;
  33392. for (i = 0; i < len; i++) {
  33393. p = points[i];
  33394. var nafPoints = p._getNAFPoints(defW);
  33395. wndWidth[i] = nafPoints.wnd;
  33396. wnd[i] = nafPoints.points;
  33397. }
  33398. // Comb small window NAFs
  33399. for (i = len - 1; i >= 1; i -= 2) {
  33400. var a = i - 1;
  33401. var b = i;
  33402. if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
  33403. naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength);
  33404. naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength);
  33405. max = Math.max(naf[a].length, max);
  33406. max = Math.max(naf[b].length, max);
  33407. continue;
  33408. }
  33409. var comb = [points[a], /* 1 */
  33410. null, /* 3 */
  33411. null, /* 5 */
  33412. points[b] /* 7 */];
  33413. // Try to avoid Projective points, if possible
  33414. if (points[a].y.cmp(points[b].y) === 0) {
  33415. comb[1] = points[a].add(points[b]);
  33416. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  33417. } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
  33418. comb[1] = points[a].toJ().mixedAdd(points[b]);
  33419. comb[2] = points[a].add(points[b].neg());
  33420. } else {
  33421. comb[1] = points[a].toJ().mixedAdd(points[b]);
  33422. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  33423. }
  33424. var index = [-3, /* -1 -1 */
  33425. -1, /* -1 0 */
  33426. -5, /* -1 1 */
  33427. -7, /* 0 -1 */
  33428. 0, /* 0 0 */
  33429. 7, /* 0 1 */
  33430. 5, /* 1 -1 */
  33431. 1, /* 1 0 */
  33432. 3 /* 1 1 */];
  33433. var jsf = getJSF(coeffs[a], coeffs[b]);
  33434. max = Math.max(jsf[0].length, max);
  33435. naf[a] = new Array(max);
  33436. naf[b] = new Array(max);
  33437. for (j = 0; j < max; j++) {
  33438. var ja = jsf[0][j] | 0;
  33439. var jb = jsf[1][j] | 0;
  33440. naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
  33441. naf[b][j] = 0;
  33442. wnd[a] = comb;
  33443. }
  33444. }
  33445. var acc = this.jpoint(null, null, null);
  33446. var tmp = this._wnafT4;
  33447. for (i = max; i >= 0; i--) {
  33448. var k = 0;
  33449. while (i >= 0) {
  33450. var zero = true;
  33451. for (j = 0; j < len; j++) {
  33452. tmp[j] = naf[j][i] | 0;
  33453. if (tmp[j] !== 0) zero = false;
  33454. }
  33455. if (!zero) break;
  33456. k++;
  33457. i--;
  33458. }
  33459. if (i >= 0) k++;
  33460. acc = acc.dblp(k);
  33461. if (i < 0) break;
  33462. for (j = 0; j < len; j++) {
  33463. var z = tmp[j];
  33464. p;
  33465. if (z === 0) continue;else if (z > 0) p = wnd[j][z - 1 >> 1];else if (z < 0) p = wnd[j][-z - 1 >> 1].neg();
  33466. if (p.type === 'affine') acc = acc.mixedAdd(p);else acc = acc.add(p);
  33467. }
  33468. }
  33469. // Zeroify references
  33470. for (i = 0; i < len; i++) wnd[i] = null;
  33471. if (jacobianResult) return acc;else return acc.toP();
  33472. };
  33473. function BasePoint(curve, type) {
  33474. this.curve = curve;
  33475. this.type = type;
  33476. this.precomputed = null;
  33477. }
  33478. BaseCurve.BasePoint = BasePoint;
  33479. BasePoint.prototype.eq = function eq( /*other*/
  33480. ) {
  33481. throw new Error('Not implemented');
  33482. };
  33483. BasePoint.prototype.validate = function validate() {
  33484. return this.curve.validate(this);
  33485. };
  33486. BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  33487. bytes = utils.toArray(bytes, enc);
  33488. var len = this.p.byteLength();
  33489. // uncompressed, hybrid-odd, hybrid-even
  33490. if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) && bytes.length - 1 === 2 * len) {
  33491. if (bytes[0] === 0x06) assert(bytes[bytes.length - 1] % 2 === 0);else if (bytes[0] === 0x07) assert(bytes[bytes.length - 1] % 2 === 1);
  33492. var res = this.point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len));
  33493. return res;
  33494. } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) && bytes.length - 1 === len) {
  33495. return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
  33496. }
  33497. throw new Error('Unknown point format');
  33498. };
  33499. BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
  33500. return this.encode(enc, true);
  33501. };
  33502. BasePoint.prototype._encode = function _encode(compact) {
  33503. var len = this.curve.p.byteLength();
  33504. var x = this.getX().toArray('be', len);
  33505. if (compact) return [this.getY().isEven() ? 0x02 : 0x03].concat(x);
  33506. return [0x04].concat(x, this.getY().toArray('be', len));
  33507. };
  33508. BasePoint.prototype.encode = function encode(enc, compact) {
  33509. return utils.encode(this._encode(compact), enc);
  33510. };
  33511. BasePoint.prototype.precompute = function precompute(power) {
  33512. if (this.precomputed) return this;
  33513. var precomputed = {
  33514. doubles: null,
  33515. naf: null,
  33516. beta: null
  33517. };
  33518. precomputed.naf = this._getNAFPoints(8);
  33519. precomputed.doubles = this._getDoubles(4, power);
  33520. precomputed.beta = this._getBeta();
  33521. this.precomputed = precomputed;
  33522. return this;
  33523. };
  33524. BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
  33525. if (!this.precomputed) return false;
  33526. var doubles = this.precomputed.doubles;
  33527. if (!doubles) return false;
  33528. return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
  33529. };
  33530. BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
  33531. if (this.precomputed && this.precomputed.doubles) return this.precomputed.doubles;
  33532. var doubles = [this];
  33533. var acc = this;
  33534. for (var i = 0; i < power; i += step) {
  33535. for (var j = 0; j < step; j++) acc = acc.dbl();
  33536. doubles.push(acc);
  33537. }
  33538. return {
  33539. step: step,
  33540. points: doubles
  33541. };
  33542. };
  33543. BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
  33544. if (this.precomputed && this.precomputed.naf) return this.precomputed.naf;
  33545. var res = [this];
  33546. var max = (1 << wnd) - 1;
  33547. var dbl = max === 1 ? null : this.dbl();
  33548. for (var i = 1; i < max; i++) res[i] = res[i - 1].add(dbl);
  33549. return {
  33550. wnd: wnd,
  33551. points: res
  33552. };
  33553. };
  33554. BasePoint.prototype._getBeta = function _getBeta() {
  33555. return null;
  33556. };
  33557. BasePoint.prototype.dblp = function dblp(k) {
  33558. var r = this;
  33559. for (var i = 0; i < k; i++) r = r.dbl();
  33560. return r;
  33561. };
  33562. },{"../utils":419,"bn.js":420}],407:[function(require,module,exports){
  33563. 'use strict';
  33564. var utils = require('../utils');
  33565. var BN = require('bn.js');
  33566. var inherits = require('inherits');
  33567. var Base = require('./base');
  33568. var assert = utils.assert;
  33569. function EdwardsCurve(conf) {
  33570. // NOTE: Important as we are creating point in Base.call()
  33571. this.twisted = (conf.a | 0) !== 1;
  33572. this.mOneA = this.twisted && (conf.a | 0) === -1;
  33573. this.extended = this.mOneA;
  33574. Base.call(this, 'edwards', conf);
  33575. this.a = new BN(conf.a, 16).umod(this.red.m);
  33576. this.a = this.a.toRed(this.red);
  33577. this.c = new BN(conf.c, 16).toRed(this.red);
  33578. this.c2 = this.c.redSqr();
  33579. this.d = new BN(conf.d, 16).toRed(this.red);
  33580. this.dd = this.d.redAdd(this.d);
  33581. assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
  33582. this.oneC = (conf.c | 0) === 1;
  33583. }
  33584. inherits(EdwardsCurve, Base);
  33585. module.exports = EdwardsCurve;
  33586. EdwardsCurve.prototype._mulA = function _mulA(num) {
  33587. if (this.mOneA) return num.redNeg();else return this.a.redMul(num);
  33588. };
  33589. EdwardsCurve.prototype._mulC = function _mulC(num) {
  33590. if (this.oneC) return num;else return this.c.redMul(num);
  33591. };
  33592. // Just for compatibility with Short curve
  33593. EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
  33594. return this.point(x, y, z, t);
  33595. };
  33596. EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
  33597. x = new BN(x, 16);
  33598. if (!x.red) x = x.toRed(this.red);
  33599. var x2 = x.redSqr();
  33600. var rhs = this.c2.redSub(this.a.redMul(x2));
  33601. var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
  33602. var y2 = rhs.redMul(lhs.redInvm());
  33603. var y = y2.redSqrt();
  33604. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point');
  33605. var isOdd = y.fromRed().isOdd();
  33606. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  33607. return this.point(x, y);
  33608. };
  33609. EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
  33610. y = new BN(y, 16);
  33611. if (!y.red) y = y.toRed(this.red);
  33612. // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
  33613. var y2 = y.redSqr();
  33614. var lhs = y2.redSub(this.c2);
  33615. var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
  33616. var x2 = lhs.redMul(rhs.redInvm());
  33617. if (x2.cmp(this.zero) === 0) {
  33618. if (odd) throw new Error('invalid point');else return this.point(this.zero, y);
  33619. }
  33620. var x = x2.redSqrt();
  33621. if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error('invalid point');
  33622. if (x.fromRed().isOdd() !== odd) x = x.redNeg();
  33623. return this.point(x, y);
  33624. };
  33625. EdwardsCurve.prototype.validate = function validate(point) {
  33626. if (point.isInfinity()) return true;
  33627. // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
  33628. point.normalize();
  33629. var x2 = point.x.redSqr();
  33630. var y2 = point.y.redSqr();
  33631. var lhs = x2.redMul(this.a).redAdd(y2);
  33632. var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
  33633. return lhs.cmp(rhs) === 0;
  33634. };
  33635. function Point(curve, x, y, z, t) {
  33636. Base.BasePoint.call(this, curve, 'projective');
  33637. if (x === null && y === null && z === null) {
  33638. this.x = this.curve.zero;
  33639. this.y = this.curve.one;
  33640. this.z = this.curve.one;
  33641. this.t = this.curve.zero;
  33642. this.zOne = true;
  33643. } else {
  33644. this.x = new BN(x, 16);
  33645. this.y = new BN(y, 16);
  33646. this.z = z ? new BN(z, 16) : this.curve.one;
  33647. this.t = t && new BN(t, 16);
  33648. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  33649. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  33650. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  33651. if (this.t && !this.t.red) this.t = this.t.toRed(this.curve.red);
  33652. this.zOne = this.z === this.curve.one;
  33653. // Use extended coordinates
  33654. if (this.curve.extended && !this.t) {
  33655. this.t = this.x.redMul(this.y);
  33656. if (!this.zOne) this.t = this.t.redMul(this.z.redInvm());
  33657. }
  33658. }
  33659. }
  33660. inherits(Point, Base.BasePoint);
  33661. EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  33662. return Point.fromJSON(this, obj);
  33663. };
  33664. EdwardsCurve.prototype.point = function point(x, y, z, t) {
  33665. return new Point(this, x, y, z, t);
  33666. };
  33667. Point.fromJSON = function fromJSON(curve, obj) {
  33668. return new Point(curve, obj[0], obj[1], obj[2]);
  33669. };
  33670. Point.prototype.inspect = function inspect() {
  33671. if (this.isInfinity()) return '<EC Point Infinity>';
  33672. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  33673. };
  33674. Point.prototype.isInfinity = function isInfinity() {
  33675. // XXX This code assumes that zero is always zero in red
  33676. return this.x.cmpn(0) === 0 && (this.y.cmp(this.z) === 0 || this.zOne && this.y.cmp(this.curve.c) === 0);
  33677. };
  33678. Point.prototype._extDbl = function _extDbl() {
  33679. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  33680. // #doubling-dbl-2008-hwcd
  33681. // 4M + 4S
  33682. // A = X1^2
  33683. var a = this.x.redSqr();
  33684. // B = Y1^2
  33685. var b = this.y.redSqr();
  33686. // C = 2 * Z1^2
  33687. var c = this.z.redSqr();
  33688. c = c.redIAdd(c);
  33689. // D = a * A
  33690. var d = this.curve._mulA(a);
  33691. // E = (X1 + Y1)^2 - A - B
  33692. var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
  33693. // G = D + B
  33694. var g = d.redAdd(b);
  33695. // F = G - C
  33696. var f = g.redSub(c);
  33697. // H = D - B
  33698. var h = d.redSub(b);
  33699. // X3 = E * F
  33700. var nx = e.redMul(f);
  33701. // Y3 = G * H
  33702. var ny = g.redMul(h);
  33703. // T3 = E * H
  33704. var nt = e.redMul(h);
  33705. // Z3 = F * G
  33706. var nz = f.redMul(g);
  33707. return this.curve.point(nx, ny, nz, nt);
  33708. };
  33709. Point.prototype._projDbl = function _projDbl() {
  33710. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  33711. // #doubling-dbl-2008-bbjlp
  33712. // #doubling-dbl-2007-bl
  33713. // and others
  33714. // Generally 3M + 4S or 2M + 4S
  33715. // B = (X1 + Y1)^2
  33716. var b = this.x.redAdd(this.y).redSqr();
  33717. // C = X1^2
  33718. var c = this.x.redSqr();
  33719. // D = Y1^2
  33720. var d = this.y.redSqr();
  33721. var nx;
  33722. var ny;
  33723. var nz;
  33724. var e;
  33725. var h;
  33726. var j;
  33727. if (this.curve.twisted) {
  33728. // E = a * C
  33729. e = this.curve._mulA(c);
  33730. // F = E + D
  33731. var f = e.redAdd(d);
  33732. if (this.zOne) {
  33733. // X3 = (B - C - D) * (F - 2)
  33734. nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
  33735. // Y3 = F * (E - D)
  33736. ny = f.redMul(e.redSub(d));
  33737. // Z3 = F^2 - 2 * F
  33738. nz = f.redSqr().redSub(f).redSub(f);
  33739. } else {
  33740. // H = Z1^2
  33741. h = this.z.redSqr();
  33742. // J = F - 2 * H
  33743. j = f.redSub(h).redISub(h);
  33744. // X3 = (B-C-D)*J
  33745. nx = b.redSub(c).redISub(d).redMul(j);
  33746. // Y3 = F * (E - D)
  33747. ny = f.redMul(e.redSub(d));
  33748. // Z3 = F * J
  33749. nz = f.redMul(j);
  33750. }
  33751. } else {
  33752. // E = C + D
  33753. e = c.redAdd(d);
  33754. // H = (c * Z1)^2
  33755. h = this.curve._mulC(this.z).redSqr();
  33756. // J = E - 2 * H
  33757. j = e.redSub(h).redSub(h);
  33758. // X3 = c * (B - E) * J
  33759. nx = this.curve._mulC(b.redISub(e)).redMul(j);
  33760. // Y3 = c * E * (C - D)
  33761. ny = this.curve._mulC(e).redMul(c.redISub(d));
  33762. // Z3 = E * J
  33763. nz = e.redMul(j);
  33764. }
  33765. return this.curve.point(nx, ny, nz);
  33766. };
  33767. Point.prototype.dbl = function dbl() {
  33768. if (this.isInfinity()) return this;
  33769. // Double in extended coordinates
  33770. if (this.curve.extended) return this._extDbl();else return this._projDbl();
  33771. };
  33772. Point.prototype._extAdd = function _extAdd(p) {
  33773. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  33774. // #addition-add-2008-hwcd-3
  33775. // 8M
  33776. // A = (Y1 - X1) * (Y2 - X2)
  33777. var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
  33778. // B = (Y1 + X1) * (Y2 + X2)
  33779. var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
  33780. // C = T1 * k * T2
  33781. var c = this.t.redMul(this.curve.dd).redMul(p.t);
  33782. // D = Z1 * 2 * Z2
  33783. var d = this.z.redMul(p.z.redAdd(p.z));
  33784. // E = B - A
  33785. var e = b.redSub(a);
  33786. // F = D - C
  33787. var f = d.redSub(c);
  33788. // G = D + C
  33789. var g = d.redAdd(c);
  33790. // H = B + A
  33791. var h = b.redAdd(a);
  33792. // X3 = E * F
  33793. var nx = e.redMul(f);
  33794. // Y3 = G * H
  33795. var ny = g.redMul(h);
  33796. // T3 = E * H
  33797. var nt = e.redMul(h);
  33798. // Z3 = F * G
  33799. var nz = f.redMul(g);
  33800. return this.curve.point(nx, ny, nz, nt);
  33801. };
  33802. Point.prototype._projAdd = function _projAdd(p) {
  33803. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  33804. // #addition-add-2008-bbjlp
  33805. // #addition-add-2007-bl
  33806. // 10M + 1S
  33807. // A = Z1 * Z2
  33808. var a = this.z.redMul(p.z);
  33809. // B = A^2
  33810. var b = a.redSqr();
  33811. // C = X1 * X2
  33812. var c = this.x.redMul(p.x);
  33813. // D = Y1 * Y2
  33814. var d = this.y.redMul(p.y);
  33815. // E = d * C * D
  33816. var e = this.curve.d.redMul(c).redMul(d);
  33817. // F = B - E
  33818. var f = b.redSub(e);
  33819. // G = B + E
  33820. var g = b.redAdd(e);
  33821. // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
  33822. var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
  33823. var nx = a.redMul(f).redMul(tmp);
  33824. var ny;
  33825. var nz;
  33826. if (this.curve.twisted) {
  33827. // Y3 = A * G * (D - a * C)
  33828. ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
  33829. // Z3 = F * G
  33830. nz = f.redMul(g);
  33831. } else {
  33832. // Y3 = A * G * (D - C)
  33833. ny = a.redMul(g).redMul(d.redSub(c));
  33834. // Z3 = c * F * G
  33835. nz = this.curve._mulC(f).redMul(g);
  33836. }
  33837. return this.curve.point(nx, ny, nz);
  33838. };
  33839. Point.prototype.add = function add(p) {
  33840. if (this.isInfinity()) return p;
  33841. if (p.isInfinity()) return this;
  33842. if (this.curve.extended) return this._extAdd(p);else return this._projAdd(p);
  33843. };
  33844. Point.prototype.mul = function mul(k) {
  33845. if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else return this.curve._wnafMul(this, k);
  33846. };
  33847. Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
  33848. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, false);
  33849. };
  33850. Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
  33851. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, true);
  33852. };
  33853. Point.prototype.normalize = function normalize() {
  33854. if (this.zOne) return this;
  33855. // Normalize coordinates
  33856. var zi = this.z.redInvm();
  33857. this.x = this.x.redMul(zi);
  33858. this.y = this.y.redMul(zi);
  33859. if (this.t) this.t = this.t.redMul(zi);
  33860. this.z = this.curve.one;
  33861. this.zOne = true;
  33862. return this;
  33863. };
  33864. Point.prototype.neg = function neg() {
  33865. return this.curve.point(this.x.redNeg(), this.y, this.z, this.t && this.t.redNeg());
  33866. };
  33867. Point.prototype.getX = function getX() {
  33868. this.normalize();
  33869. return this.x.fromRed();
  33870. };
  33871. Point.prototype.getY = function getY() {
  33872. this.normalize();
  33873. return this.y.fromRed();
  33874. };
  33875. Point.prototype.eq = function eq(other) {
  33876. return this === other || this.getX().cmp(other.getX()) === 0 && this.getY().cmp(other.getY()) === 0;
  33877. };
  33878. Point.prototype.eqXToP = function eqXToP(x) {
  33879. var rx = x.toRed(this.curve.red).redMul(this.z);
  33880. if (this.x.cmp(rx) === 0) return true;
  33881. var xc = x.clone();
  33882. var t = this.curve.redN.redMul(this.z);
  33883. for (;;) {
  33884. xc.iadd(this.curve.n);
  33885. if (xc.cmp(this.curve.p) >= 0) return false;
  33886. rx.redIAdd(t);
  33887. if (this.x.cmp(rx) === 0) return true;
  33888. }
  33889. };
  33890. // Compatibility with BaseCurve
  33891. Point.prototype.toP = Point.prototype.normalize;
  33892. Point.prototype.mixedAdd = Point.prototype.add;
  33893. },{"../utils":419,"./base":406,"bn.js":420,"inherits":440}],408:[function(require,module,exports){
  33894. 'use strict';
  33895. var curve = exports;
  33896. curve.base = require('./base');
  33897. curve.short = require('./short');
  33898. curve.mont = require('./mont');
  33899. curve.edwards = require('./edwards');
  33900. },{"./base":406,"./edwards":407,"./mont":409,"./short":410}],409:[function(require,module,exports){
  33901. 'use strict';
  33902. var BN = require('bn.js');
  33903. var inherits = require('inherits');
  33904. var Base = require('./base');
  33905. var utils = require('../utils');
  33906. function MontCurve(conf) {
  33907. Base.call(this, 'mont', conf);
  33908. this.a = new BN(conf.a, 16).toRed(this.red);
  33909. this.b = new BN(conf.b, 16).toRed(this.red);
  33910. this.i4 = new BN(4).toRed(this.red).redInvm();
  33911. this.two = new BN(2).toRed(this.red);
  33912. this.a24 = this.i4.redMul(this.a.redAdd(this.two));
  33913. }
  33914. inherits(MontCurve, Base);
  33915. module.exports = MontCurve;
  33916. MontCurve.prototype.validate = function validate(point) {
  33917. var x = point.normalize().x;
  33918. var x2 = x.redSqr();
  33919. var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
  33920. var y = rhs.redSqrt();
  33921. return y.redSqr().cmp(rhs) === 0;
  33922. };
  33923. function Point(curve, x, z) {
  33924. Base.BasePoint.call(this, curve, 'projective');
  33925. if (x === null && z === null) {
  33926. this.x = this.curve.one;
  33927. this.z = this.curve.zero;
  33928. } else {
  33929. this.x = new BN(x, 16);
  33930. this.z = new BN(z, 16);
  33931. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  33932. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  33933. }
  33934. }
  33935. inherits(Point, Base.BasePoint);
  33936. MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  33937. return this.point(utils.toArray(bytes, enc), 1);
  33938. };
  33939. MontCurve.prototype.point = function point(x, z) {
  33940. return new Point(this, x, z);
  33941. };
  33942. MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  33943. return Point.fromJSON(this, obj);
  33944. };
  33945. Point.prototype.precompute = function precompute() {
  33946. // No-op
  33947. };
  33948. Point.prototype._encode = function _encode() {
  33949. return this.getX().toArray('be', this.curve.p.byteLength());
  33950. };
  33951. Point.fromJSON = function fromJSON(curve, obj) {
  33952. return new Point(curve, obj[0], obj[1] || curve.one);
  33953. };
  33954. Point.prototype.inspect = function inspect() {
  33955. if (this.isInfinity()) return '<EC Point Infinity>';
  33956. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  33957. };
  33958. Point.prototype.isInfinity = function isInfinity() {
  33959. // XXX This code assumes that zero is always zero in red
  33960. return this.z.cmpn(0) === 0;
  33961. };
  33962. Point.prototype.dbl = function dbl() {
  33963. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
  33964. // 2M + 2S + 4A
  33965. // A = X1 + Z1
  33966. var a = this.x.redAdd(this.z);
  33967. // AA = A^2
  33968. var aa = a.redSqr();
  33969. // B = X1 - Z1
  33970. var b = this.x.redSub(this.z);
  33971. // BB = B^2
  33972. var bb = b.redSqr();
  33973. // C = AA - BB
  33974. var c = aa.redSub(bb);
  33975. // X3 = AA * BB
  33976. var nx = aa.redMul(bb);
  33977. // Z3 = C * (BB + A24 * C)
  33978. var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
  33979. return this.curve.point(nx, nz);
  33980. };
  33981. Point.prototype.add = function add() {
  33982. throw new Error('Not supported on Montgomery curve');
  33983. };
  33984. Point.prototype.diffAdd = function diffAdd(p, diff) {
  33985. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
  33986. // 4M + 2S + 6A
  33987. // A = X2 + Z2
  33988. var a = this.x.redAdd(this.z);
  33989. // B = X2 - Z2
  33990. var b = this.x.redSub(this.z);
  33991. // C = X3 + Z3
  33992. var c = p.x.redAdd(p.z);
  33993. // D = X3 - Z3
  33994. var d = p.x.redSub(p.z);
  33995. // DA = D * A
  33996. var da = d.redMul(a);
  33997. // CB = C * B
  33998. var cb = c.redMul(b);
  33999. // X5 = Z1 * (DA + CB)^2
  34000. var nx = diff.z.redMul(da.redAdd(cb).redSqr());
  34001. // Z5 = X1 * (DA - CB)^2
  34002. var nz = diff.x.redMul(da.redISub(cb).redSqr());
  34003. return this.curve.point(nx, nz);
  34004. };
  34005. Point.prototype.mul = function mul(k) {
  34006. var t = k.clone();
  34007. var a = this; // (N / 2) * Q + Q
  34008. var b = this.curve.point(null, null); // (N / 2) * Q
  34009. var c = this; // Q
  34010. for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) bits.push(t.andln(1));
  34011. for (var i = bits.length - 1; i >= 0; i--) {
  34012. if (bits[i] === 0) {
  34013. // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
  34014. a = a.diffAdd(b, c);
  34015. // N * Q = 2 * ((N / 2) * Q + Q))
  34016. b = b.dbl();
  34017. } else {
  34018. // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
  34019. b = a.diffAdd(b, c);
  34020. // N * Q + Q = 2 * ((N / 2) * Q + Q)
  34021. a = a.dbl();
  34022. }
  34023. }
  34024. return b;
  34025. };
  34026. Point.prototype.mulAdd = function mulAdd() {
  34027. throw new Error('Not supported on Montgomery curve');
  34028. };
  34029. Point.prototype.jumlAdd = function jumlAdd() {
  34030. throw new Error('Not supported on Montgomery curve');
  34031. };
  34032. Point.prototype.eq = function eq(other) {
  34033. return this.getX().cmp(other.getX()) === 0;
  34034. };
  34035. Point.prototype.normalize = function normalize() {
  34036. this.x = this.x.redMul(this.z.redInvm());
  34037. this.z = this.curve.one;
  34038. return this;
  34039. };
  34040. Point.prototype.getX = function getX() {
  34041. // Normalize coordinates
  34042. this.normalize();
  34043. return this.x.fromRed();
  34044. };
  34045. },{"../utils":419,"./base":406,"bn.js":420,"inherits":440}],410:[function(require,module,exports){
  34046. 'use strict';
  34047. var utils = require('../utils');
  34048. var BN = require('bn.js');
  34049. var inherits = require('inherits');
  34050. var Base = require('./base');
  34051. var assert = utils.assert;
  34052. function ShortCurve(conf) {
  34053. Base.call(this, 'short', conf);
  34054. this.a = new BN(conf.a, 16).toRed(this.red);
  34055. this.b = new BN(conf.b, 16).toRed(this.red);
  34056. this.tinv = this.two.redInvm();
  34057. this.zeroA = this.a.fromRed().cmpn(0) === 0;
  34058. this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
  34059. // If the curve is endomorphic, precalculate beta and lambda
  34060. this.endo = this._getEndomorphism(conf);
  34061. this._endoWnafT1 = new Array(4);
  34062. this._endoWnafT2 = new Array(4);
  34063. }
  34064. inherits(ShortCurve, Base);
  34065. module.exports = ShortCurve;
  34066. ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
  34067. // No efficient endomorphism
  34068. if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return;
  34069. // Compute beta and lambda, that lambda * P = (beta * Px; Py)
  34070. var beta;
  34071. var lambda;
  34072. if (conf.beta) {
  34073. beta = new BN(conf.beta, 16).toRed(this.red);
  34074. } else {
  34075. var betas = this._getEndoRoots(this.p);
  34076. // Choose the smallest beta
  34077. beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
  34078. beta = beta.toRed(this.red);
  34079. }
  34080. if (conf.lambda) {
  34081. lambda = new BN(conf.lambda, 16);
  34082. } else {
  34083. // Choose the lambda that is matching selected beta
  34084. var lambdas = this._getEndoRoots(this.n);
  34085. if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
  34086. lambda = lambdas[0];
  34087. } else {
  34088. lambda = lambdas[1];
  34089. assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
  34090. }
  34091. }
  34092. // Get basis vectors, used for balanced length-two representation
  34093. var basis;
  34094. if (conf.basis) {
  34095. basis = conf.basis.map(function (vec) {
  34096. return {
  34097. a: new BN(vec.a, 16),
  34098. b: new BN(vec.b, 16)
  34099. };
  34100. });
  34101. } else {
  34102. basis = this._getEndoBasis(lambda);
  34103. }
  34104. return {
  34105. beta: beta,
  34106. lambda: lambda,
  34107. basis: basis
  34108. };
  34109. };
  34110. ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  34111. // Find roots of for x^2 + x + 1 in F
  34112. // Root = (-1 +- Sqrt(-3)) / 2
  34113. //
  34114. var red = num === this.p ? this.red : BN.mont(num);
  34115. var tinv = new BN(2).toRed(red).redInvm();
  34116. var ntinv = tinv.redNeg();
  34117. var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
  34118. var l1 = ntinv.redAdd(s).fromRed();
  34119. var l2 = ntinv.redSub(s).fromRed();
  34120. return [l1, l2];
  34121. };
  34122. ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
  34123. // aprxSqrt >= sqrt(this.n)
  34124. var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
  34125. // 3.74
  34126. // Run EGCD, until r(L + 1) < aprxSqrt
  34127. var u = lambda;
  34128. var v = this.n.clone();
  34129. var x1 = new BN(1);
  34130. var y1 = new BN(0);
  34131. var x2 = new BN(0);
  34132. var y2 = new BN(1);
  34133. // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
  34134. var a0;
  34135. var b0;
  34136. // First vector
  34137. var a1;
  34138. var b1;
  34139. // Second vector
  34140. var a2;
  34141. var b2;
  34142. var prevR;
  34143. var i = 0;
  34144. var r;
  34145. var x;
  34146. while (u.cmpn(0) !== 0) {
  34147. var q = v.div(u);
  34148. r = v.sub(q.mul(u));
  34149. x = x2.sub(q.mul(x1));
  34150. var y = y2.sub(q.mul(y1));
  34151. if (!a1 && r.cmp(aprxSqrt) < 0) {
  34152. a0 = prevR.neg();
  34153. b0 = x1;
  34154. a1 = r.neg();
  34155. b1 = x;
  34156. } else if (a1 && ++i === 2) {
  34157. break;
  34158. }
  34159. prevR = r;
  34160. v = u;
  34161. u = r;
  34162. x2 = x1;
  34163. x1 = x;
  34164. y2 = y1;
  34165. y1 = y;
  34166. }
  34167. a2 = r.neg();
  34168. b2 = x;
  34169. var len1 = a1.sqr().add(b1.sqr());
  34170. var len2 = a2.sqr().add(b2.sqr());
  34171. if (len2.cmp(len1) >= 0) {
  34172. a2 = a0;
  34173. b2 = b0;
  34174. }
  34175. // Normalize signs
  34176. if (a1.negative) {
  34177. a1 = a1.neg();
  34178. b1 = b1.neg();
  34179. }
  34180. if (a2.negative) {
  34181. a2 = a2.neg();
  34182. b2 = b2.neg();
  34183. }
  34184. return [{
  34185. a: a1,
  34186. b: b1
  34187. }, {
  34188. a: a2,
  34189. b: b2
  34190. }];
  34191. };
  34192. ShortCurve.prototype._endoSplit = function _endoSplit(k) {
  34193. var basis = this.endo.basis;
  34194. var v1 = basis[0];
  34195. var v2 = basis[1];
  34196. var c1 = v2.b.mul(k).divRound(this.n);
  34197. var c2 = v1.b.neg().mul(k).divRound(this.n);
  34198. var p1 = c1.mul(v1.a);
  34199. var p2 = c2.mul(v2.a);
  34200. var q1 = c1.mul(v1.b);
  34201. var q2 = c2.mul(v2.b);
  34202. // Calculate answer
  34203. var k1 = k.sub(p1).sub(p2);
  34204. var k2 = q1.add(q2).neg();
  34205. return {
  34206. k1: k1,
  34207. k2: k2
  34208. };
  34209. };
  34210. ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
  34211. x = new BN(x, 16);
  34212. if (!x.red) x = x.toRed(this.red);
  34213. var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
  34214. var y = y2.redSqrt();
  34215. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point');
  34216. // XXX Is there any way to tell if the number is odd without converting it
  34217. // to non-red form?
  34218. var isOdd = y.fromRed().isOdd();
  34219. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  34220. return this.point(x, y);
  34221. };
  34222. ShortCurve.prototype.validate = function validate(point) {
  34223. if (point.inf) return true;
  34224. var x = point.x;
  34225. var y = point.y;
  34226. var ax = this.a.redMul(x);
  34227. var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
  34228. return y.redSqr().redISub(rhs).cmpn(0) === 0;
  34229. };
  34230. ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) {
  34231. var npoints = this._endoWnafT1;
  34232. var ncoeffs = this._endoWnafT2;
  34233. for (var i = 0; i < points.length; i++) {
  34234. var split = this._endoSplit(coeffs[i]);
  34235. var p = points[i];
  34236. var beta = p._getBeta();
  34237. if (split.k1.negative) {
  34238. split.k1.ineg();
  34239. p = p.neg(true);
  34240. }
  34241. if (split.k2.negative) {
  34242. split.k2.ineg();
  34243. beta = beta.neg(true);
  34244. }
  34245. npoints[i * 2] = p;
  34246. npoints[i * 2 + 1] = beta;
  34247. ncoeffs[i * 2] = split.k1;
  34248. ncoeffs[i * 2 + 1] = split.k2;
  34249. }
  34250. var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
  34251. // Clean-up references to points and coefficients
  34252. for (var j = 0; j < i * 2; j++) {
  34253. npoints[j] = null;
  34254. ncoeffs[j] = null;
  34255. }
  34256. return res;
  34257. };
  34258. function Point(curve, x, y, isRed) {
  34259. Base.BasePoint.call(this, curve, 'affine');
  34260. if (x === null && y === null) {
  34261. this.x = null;
  34262. this.y = null;
  34263. this.inf = true;
  34264. } else {
  34265. this.x = new BN(x, 16);
  34266. this.y = new BN(y, 16);
  34267. // Force redgomery representation when loading from JSON
  34268. if (isRed) {
  34269. this.x.forceRed(this.curve.red);
  34270. this.y.forceRed(this.curve.red);
  34271. }
  34272. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  34273. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  34274. this.inf = false;
  34275. }
  34276. }
  34277. inherits(Point, Base.BasePoint);
  34278. ShortCurve.prototype.point = function point(x, y, isRed) {
  34279. return new Point(this, x, y, isRed);
  34280. };
  34281. ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
  34282. return Point.fromJSON(this, obj, red);
  34283. };
  34284. Point.prototype._getBeta = function _getBeta() {
  34285. if (!this.curve.endo) return;
  34286. var pre = this.precomputed;
  34287. if (pre && pre.beta) return pre.beta;
  34288. var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
  34289. if (pre) {
  34290. var curve = this.curve;
  34291. var endoMul = function (p) {
  34292. return curve.point(p.x.redMul(curve.endo.beta), p.y);
  34293. };
  34294. pre.beta = beta;
  34295. beta.precomputed = {
  34296. beta: null,
  34297. naf: pre.naf && {
  34298. wnd: pre.naf.wnd,
  34299. points: pre.naf.points.map(endoMul)
  34300. },
  34301. doubles: pre.doubles && {
  34302. step: pre.doubles.step,
  34303. points: pre.doubles.points.map(endoMul)
  34304. }
  34305. };
  34306. }
  34307. return beta;
  34308. };
  34309. Point.prototype.toJSON = function toJSON() {
  34310. if (!this.precomputed) return [this.x, this.y];
  34311. return [this.x, this.y, this.precomputed && {
  34312. doubles: this.precomputed.doubles && {
  34313. step: this.precomputed.doubles.step,
  34314. points: this.precomputed.doubles.points.slice(1)
  34315. },
  34316. naf: this.precomputed.naf && {
  34317. wnd: this.precomputed.naf.wnd,
  34318. points: this.precomputed.naf.points.slice(1)
  34319. }
  34320. }];
  34321. };
  34322. Point.fromJSON = function fromJSON(curve, obj, red) {
  34323. if (typeof obj === 'string') obj = JSON.parse(obj);
  34324. var res = curve.point(obj[0], obj[1], red);
  34325. if (!obj[2]) return res;
  34326. function obj2point(obj) {
  34327. return curve.point(obj[0], obj[1], red);
  34328. }
  34329. var pre = obj[2];
  34330. res.precomputed = {
  34331. beta: null,
  34332. doubles: pre.doubles && {
  34333. step: pre.doubles.step,
  34334. points: [res].concat(pre.doubles.points.map(obj2point))
  34335. },
  34336. naf: pre.naf && {
  34337. wnd: pre.naf.wnd,
  34338. points: [res].concat(pre.naf.points.map(obj2point))
  34339. }
  34340. };
  34341. return res;
  34342. };
  34343. Point.prototype.inspect = function inspect() {
  34344. if (this.isInfinity()) return '<EC Point Infinity>';
  34345. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + '>';
  34346. };
  34347. Point.prototype.isInfinity = function isInfinity() {
  34348. return this.inf;
  34349. };
  34350. Point.prototype.add = function add(p) {
  34351. // O + P = P
  34352. if (this.inf) return p;
  34353. // P + O = P
  34354. if (p.inf) return this;
  34355. // P + P = 2P
  34356. if (this.eq(p)) return this.dbl();
  34357. // P + (-P) = O
  34358. if (this.neg().eq(p)) return this.curve.point(null, null);
  34359. // P + Q = O
  34360. if (this.x.cmp(p.x) === 0) return this.curve.point(null, null);
  34361. var c = this.y.redSub(p.y);
  34362. if (c.cmpn(0) !== 0) c = c.redMul(this.x.redSub(p.x).redInvm());
  34363. var nx = c.redSqr().redISub(this.x).redISub(p.x);
  34364. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  34365. return this.curve.point(nx, ny);
  34366. };
  34367. Point.prototype.dbl = function dbl() {
  34368. if (this.inf) return this;
  34369. // 2P = O
  34370. var ys1 = this.y.redAdd(this.y);
  34371. if (ys1.cmpn(0) === 0) return this.curve.point(null, null);
  34372. var a = this.curve.a;
  34373. var x2 = this.x.redSqr();
  34374. var dyinv = ys1.redInvm();
  34375. var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
  34376. var nx = c.redSqr().redISub(this.x.redAdd(this.x));
  34377. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  34378. return this.curve.point(nx, ny);
  34379. };
  34380. Point.prototype.getX = function getX() {
  34381. return this.x.fromRed();
  34382. };
  34383. Point.prototype.getY = function getY() {
  34384. return this.y.fromRed();
  34385. };
  34386. Point.prototype.mul = function mul(k) {
  34387. k = new BN(k, 16);
  34388. if (this.isInfinity()) return this;else if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else if (this.curve.endo) return this.curve._endoWnafMulAdd([this], [k]);else return this.curve._wnafMul(this, k);
  34389. };
  34390. Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
  34391. var points = [this, p2];
  34392. var coeffs = [k1, k2];
  34393. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs);else return this.curve._wnafMulAdd(1, points, coeffs, 2);
  34394. };
  34395. Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
  34396. var points = [this, p2];
  34397. var coeffs = [k1, k2];
  34398. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs, true);else return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
  34399. };
  34400. Point.prototype.eq = function eq(p) {
  34401. return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
  34402. };
  34403. Point.prototype.neg = function neg(_precompute) {
  34404. if (this.inf) return this;
  34405. var res = this.curve.point(this.x, this.y.redNeg());
  34406. if (_precompute && this.precomputed) {
  34407. var pre = this.precomputed;
  34408. var negate = function (p) {
  34409. return p.neg();
  34410. };
  34411. res.precomputed = {
  34412. naf: pre.naf && {
  34413. wnd: pre.naf.wnd,
  34414. points: pre.naf.points.map(negate)
  34415. },
  34416. doubles: pre.doubles && {
  34417. step: pre.doubles.step,
  34418. points: pre.doubles.points.map(negate)
  34419. }
  34420. };
  34421. }
  34422. return res;
  34423. };
  34424. Point.prototype.toJ = function toJ() {
  34425. if (this.inf) return this.curve.jpoint(null, null, null);
  34426. var res = this.curve.jpoint(this.x, this.y, this.curve.one);
  34427. return res;
  34428. };
  34429. function JPoint(curve, x, y, z) {
  34430. Base.BasePoint.call(this, curve, 'jacobian');
  34431. if (x === null && y === null && z === null) {
  34432. this.x = this.curve.one;
  34433. this.y = this.curve.one;
  34434. this.z = new BN(0);
  34435. } else {
  34436. this.x = new BN(x, 16);
  34437. this.y = new BN(y, 16);
  34438. this.z = new BN(z, 16);
  34439. }
  34440. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  34441. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  34442. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  34443. this.zOne = this.z === this.curve.one;
  34444. }
  34445. inherits(JPoint, Base.BasePoint);
  34446. ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
  34447. return new JPoint(this, x, y, z);
  34448. };
  34449. JPoint.prototype.toP = function toP() {
  34450. if (this.isInfinity()) return this.curve.point(null, null);
  34451. var zinv = this.z.redInvm();
  34452. var zinv2 = zinv.redSqr();
  34453. var ax = this.x.redMul(zinv2);
  34454. var ay = this.y.redMul(zinv2).redMul(zinv);
  34455. return this.curve.point(ax, ay);
  34456. };
  34457. JPoint.prototype.neg = function neg() {
  34458. return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
  34459. };
  34460. JPoint.prototype.add = function add(p) {
  34461. // O + P = P
  34462. if (this.isInfinity()) return p;
  34463. // P + O = P
  34464. if (p.isInfinity()) return this;
  34465. // 12M + 4S + 7A
  34466. var pz2 = p.z.redSqr();
  34467. var z2 = this.z.redSqr();
  34468. var u1 = this.x.redMul(pz2);
  34469. var u2 = p.x.redMul(z2);
  34470. var s1 = this.y.redMul(pz2.redMul(p.z));
  34471. var s2 = p.y.redMul(z2.redMul(this.z));
  34472. var h = u1.redSub(u2);
  34473. var r = s1.redSub(s2);
  34474. if (h.cmpn(0) === 0) {
  34475. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  34476. }
  34477. var h2 = h.redSqr();
  34478. var h3 = h2.redMul(h);
  34479. var v = u1.redMul(h2);
  34480. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  34481. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  34482. var nz = this.z.redMul(p.z).redMul(h);
  34483. return this.curve.jpoint(nx, ny, nz);
  34484. };
  34485. JPoint.prototype.mixedAdd = function mixedAdd(p) {
  34486. // O + P = P
  34487. if (this.isInfinity()) return p.toJ();
  34488. // P + O = P
  34489. if (p.isInfinity()) return this;
  34490. // 8M + 3S + 7A
  34491. var z2 = this.z.redSqr();
  34492. var u1 = this.x;
  34493. var u2 = p.x.redMul(z2);
  34494. var s1 = this.y;
  34495. var s2 = p.y.redMul(z2).redMul(this.z);
  34496. var h = u1.redSub(u2);
  34497. var r = s1.redSub(s2);
  34498. if (h.cmpn(0) === 0) {
  34499. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  34500. }
  34501. var h2 = h.redSqr();
  34502. var h3 = h2.redMul(h);
  34503. var v = u1.redMul(h2);
  34504. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  34505. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  34506. var nz = this.z.redMul(h);
  34507. return this.curve.jpoint(nx, ny, nz);
  34508. };
  34509. JPoint.prototype.dblp = function dblp(pow) {
  34510. if (pow === 0) return this;
  34511. if (this.isInfinity()) return this;
  34512. if (!pow) return this.dbl();
  34513. var i;
  34514. if (this.curve.zeroA || this.curve.threeA) {
  34515. var r = this;
  34516. for (i = 0; i < pow; i++) r = r.dbl();
  34517. return r;
  34518. }
  34519. // 1M + 2S + 1A + N * (4S + 5M + 8A)
  34520. // N = 1 => 6M + 6S + 9A
  34521. var a = this.curve.a;
  34522. var tinv = this.curve.tinv;
  34523. var jx = this.x;
  34524. var jy = this.y;
  34525. var jz = this.z;
  34526. var jz4 = jz.redSqr().redSqr();
  34527. // Reuse results
  34528. var jyd = jy.redAdd(jy);
  34529. for (i = 0; i < pow; i++) {
  34530. var jx2 = jx.redSqr();
  34531. var jyd2 = jyd.redSqr();
  34532. var jyd4 = jyd2.redSqr();
  34533. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  34534. var t1 = jx.redMul(jyd2);
  34535. var nx = c.redSqr().redISub(t1.redAdd(t1));
  34536. var t2 = t1.redISub(nx);
  34537. var dny = c.redMul(t2);
  34538. dny = dny.redIAdd(dny).redISub(jyd4);
  34539. var nz = jyd.redMul(jz);
  34540. if (i + 1 < pow) jz4 = jz4.redMul(jyd4);
  34541. jx = nx;
  34542. jz = nz;
  34543. jyd = dny;
  34544. }
  34545. return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
  34546. };
  34547. JPoint.prototype.dbl = function dbl() {
  34548. if (this.isInfinity()) return this;
  34549. if (this.curve.zeroA) return this._zeroDbl();else if (this.curve.threeA) return this._threeDbl();else return this._dbl();
  34550. };
  34551. JPoint.prototype._zeroDbl = function _zeroDbl() {
  34552. var nx;
  34553. var ny;
  34554. var nz;
  34555. // Z = 1
  34556. if (this.zOne) {
  34557. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  34558. // #doubling-mdbl-2007-bl
  34559. // 1M + 5S + 14A
  34560. // XX = X1^2
  34561. var xx = this.x.redSqr();
  34562. // YY = Y1^2
  34563. var yy = this.y.redSqr();
  34564. // YYYY = YY^2
  34565. var yyyy = yy.redSqr();
  34566. // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  34567. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  34568. s = s.redIAdd(s);
  34569. // M = 3 * XX + a; a = 0
  34570. var m = xx.redAdd(xx).redIAdd(xx);
  34571. // T = M ^ 2 - 2*S
  34572. var t = m.redSqr().redISub(s).redISub(s);
  34573. // 8 * YYYY
  34574. var yyyy8 = yyyy.redIAdd(yyyy);
  34575. yyyy8 = yyyy8.redIAdd(yyyy8);
  34576. yyyy8 = yyyy8.redIAdd(yyyy8);
  34577. // X3 = T
  34578. nx = t;
  34579. // Y3 = M * (S - T) - 8 * YYYY
  34580. ny = m.redMul(s.redISub(t)).redISub(yyyy8);
  34581. // Z3 = 2*Y1
  34582. nz = this.y.redAdd(this.y);
  34583. } else {
  34584. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  34585. // #doubling-dbl-2009-l
  34586. // 2M + 5S + 13A
  34587. // A = X1^2
  34588. var a = this.x.redSqr();
  34589. // B = Y1^2
  34590. var b = this.y.redSqr();
  34591. // C = B^2
  34592. var c = b.redSqr();
  34593. // D = 2 * ((X1 + B)^2 - A - C)
  34594. var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
  34595. d = d.redIAdd(d);
  34596. // E = 3 * A
  34597. var e = a.redAdd(a).redIAdd(a);
  34598. // F = E^2
  34599. var f = e.redSqr();
  34600. // 8 * C
  34601. var c8 = c.redIAdd(c);
  34602. c8 = c8.redIAdd(c8);
  34603. c8 = c8.redIAdd(c8);
  34604. // X3 = F - 2 * D
  34605. nx = f.redISub(d).redISub(d);
  34606. // Y3 = E * (D - X3) - 8 * C
  34607. ny = e.redMul(d.redISub(nx)).redISub(c8);
  34608. // Z3 = 2 * Y1 * Z1
  34609. nz = this.y.redMul(this.z);
  34610. nz = nz.redIAdd(nz);
  34611. }
  34612. return this.curve.jpoint(nx, ny, nz);
  34613. };
  34614. JPoint.prototype._threeDbl = function _threeDbl() {
  34615. var nx;
  34616. var ny;
  34617. var nz;
  34618. // Z = 1
  34619. if (this.zOne) {
  34620. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
  34621. // #doubling-mdbl-2007-bl
  34622. // 1M + 5S + 15A
  34623. // XX = X1^2
  34624. var xx = this.x.redSqr();
  34625. // YY = Y1^2
  34626. var yy = this.y.redSqr();
  34627. // YYYY = YY^2
  34628. var yyyy = yy.redSqr();
  34629. // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  34630. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  34631. s = s.redIAdd(s);
  34632. // M = 3 * XX + a
  34633. var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
  34634. // T = M^2 - 2 * S
  34635. var t = m.redSqr().redISub(s).redISub(s);
  34636. // X3 = T
  34637. nx = t;
  34638. // Y3 = M * (S - T) - 8 * YYYY
  34639. var yyyy8 = yyyy.redIAdd(yyyy);
  34640. yyyy8 = yyyy8.redIAdd(yyyy8);
  34641. yyyy8 = yyyy8.redIAdd(yyyy8);
  34642. ny = m.redMul(s.redISub(t)).redISub(yyyy8);
  34643. // Z3 = 2 * Y1
  34644. nz = this.y.redAdd(this.y);
  34645. } else {
  34646. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
  34647. // 3M + 5S
  34648. // delta = Z1^2
  34649. var delta = this.z.redSqr();
  34650. // gamma = Y1^2
  34651. var gamma = this.y.redSqr();
  34652. // beta = X1 * gamma
  34653. var beta = this.x.redMul(gamma);
  34654. // alpha = 3 * (X1 - delta) * (X1 + delta)
  34655. var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
  34656. alpha = alpha.redAdd(alpha).redIAdd(alpha);
  34657. // X3 = alpha^2 - 8 * beta
  34658. var beta4 = beta.redIAdd(beta);
  34659. beta4 = beta4.redIAdd(beta4);
  34660. var beta8 = beta4.redAdd(beta4);
  34661. nx = alpha.redSqr().redISub(beta8);
  34662. // Z3 = (Y1 + Z1)^2 - gamma - delta
  34663. nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
  34664. // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
  34665. var ggamma8 = gamma.redSqr();
  34666. ggamma8 = ggamma8.redIAdd(ggamma8);
  34667. ggamma8 = ggamma8.redIAdd(ggamma8);
  34668. ggamma8 = ggamma8.redIAdd(ggamma8);
  34669. ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
  34670. }
  34671. return this.curve.jpoint(nx, ny, nz);
  34672. };
  34673. JPoint.prototype._dbl = function _dbl() {
  34674. var a = this.curve.a;
  34675. // 4M + 6S + 10A
  34676. var jx = this.x;
  34677. var jy = this.y;
  34678. var jz = this.z;
  34679. var jz4 = jz.redSqr().redSqr();
  34680. var jx2 = jx.redSqr();
  34681. var jy2 = jy.redSqr();
  34682. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  34683. var jxd4 = jx.redAdd(jx);
  34684. jxd4 = jxd4.redIAdd(jxd4);
  34685. var t1 = jxd4.redMul(jy2);
  34686. var nx = c.redSqr().redISub(t1.redAdd(t1));
  34687. var t2 = t1.redISub(nx);
  34688. var jyd8 = jy2.redSqr();
  34689. jyd8 = jyd8.redIAdd(jyd8);
  34690. jyd8 = jyd8.redIAdd(jyd8);
  34691. jyd8 = jyd8.redIAdd(jyd8);
  34692. var ny = c.redMul(t2).redISub(jyd8);
  34693. var nz = jy.redAdd(jy).redMul(jz);
  34694. return this.curve.jpoint(nx, ny, nz);
  34695. };
  34696. JPoint.prototype.trpl = function trpl() {
  34697. if (!this.curve.zeroA) return this.dbl().add(this);
  34698. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
  34699. // 5M + 10S + ...
  34700. // XX = X1^2
  34701. var xx = this.x.redSqr();
  34702. // YY = Y1^2
  34703. var yy = this.y.redSqr();
  34704. // ZZ = Z1^2
  34705. var zz = this.z.redSqr();
  34706. // YYYY = YY^2
  34707. var yyyy = yy.redSqr();
  34708. // M = 3 * XX + a * ZZ2; a = 0
  34709. var m = xx.redAdd(xx).redIAdd(xx);
  34710. // MM = M^2
  34711. var mm = m.redSqr();
  34712. // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
  34713. var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  34714. e = e.redIAdd(e);
  34715. e = e.redAdd(e).redIAdd(e);
  34716. e = e.redISub(mm);
  34717. // EE = E^2
  34718. var ee = e.redSqr();
  34719. // T = 16*YYYY
  34720. var t = yyyy.redIAdd(yyyy);
  34721. t = t.redIAdd(t);
  34722. t = t.redIAdd(t);
  34723. t = t.redIAdd(t);
  34724. // U = (M + E)^2 - MM - EE - T
  34725. var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
  34726. // X3 = 4 * (X1 * EE - 4 * YY * U)
  34727. var yyu4 = yy.redMul(u);
  34728. yyu4 = yyu4.redIAdd(yyu4);
  34729. yyu4 = yyu4.redIAdd(yyu4);
  34730. var nx = this.x.redMul(ee).redISub(yyu4);
  34731. nx = nx.redIAdd(nx);
  34732. nx = nx.redIAdd(nx);
  34733. // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
  34734. var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
  34735. ny = ny.redIAdd(ny);
  34736. ny = ny.redIAdd(ny);
  34737. ny = ny.redIAdd(ny);
  34738. // Z3 = (Z1 + E)^2 - ZZ - EE
  34739. var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
  34740. return this.curve.jpoint(nx, ny, nz);
  34741. };
  34742. JPoint.prototype.mul = function mul(k, kbase) {
  34743. k = new BN(k, kbase);
  34744. return this.curve._wnafMul(this, k);
  34745. };
  34746. JPoint.prototype.eq = function eq(p) {
  34747. if (p.type === 'affine') return this.eq(p.toJ());
  34748. if (this === p) return true;
  34749. // x1 * z2^2 == x2 * z1^2
  34750. var z2 = this.z.redSqr();
  34751. var pz2 = p.z.redSqr();
  34752. if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false;
  34753. // y1 * z2^3 == y2 * z1^3
  34754. var z3 = z2.redMul(this.z);
  34755. var pz3 = pz2.redMul(p.z);
  34756. return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
  34757. };
  34758. JPoint.prototype.eqXToP = function eqXToP(x) {
  34759. var zs = this.z.redSqr();
  34760. var rx = x.toRed(this.curve.red).redMul(zs);
  34761. if (this.x.cmp(rx) === 0) return true;
  34762. var xc = x.clone();
  34763. var t = this.curve.redN.redMul(zs);
  34764. for (;;) {
  34765. xc.iadd(this.curve.n);
  34766. if (xc.cmp(this.curve.p) >= 0) return false;
  34767. rx.redIAdd(t);
  34768. if (this.x.cmp(rx) === 0) return true;
  34769. }
  34770. };
  34771. JPoint.prototype.inspect = function inspect() {
  34772. if (this.isInfinity()) return '<EC JPoint Infinity>';
  34773. return '<EC JPoint x: ' + this.x.toString(16, 2) + ' y: ' + this.y.toString(16, 2) + ' z: ' + this.z.toString(16, 2) + '>';
  34774. };
  34775. JPoint.prototype.isInfinity = function isInfinity() {
  34776. // XXX This code assumes that zero is always zero in red
  34777. return this.z.cmpn(0) === 0;
  34778. };
  34779. },{"../utils":419,"./base":406,"bn.js":420,"inherits":440}],411:[function(require,module,exports){
  34780. 'use strict';
  34781. var curves = exports;
  34782. var hash = require('hash.js');
  34783. var curve = require('./curve');
  34784. var utils = require('./utils');
  34785. var assert = utils.assert;
  34786. function PresetCurve(options) {
  34787. if (options.type === 'short') this.curve = new curve.short(options);else if (options.type === 'edwards') this.curve = new curve.edwards(options);else this.curve = new curve.mont(options);
  34788. this.g = this.curve.g;
  34789. this.n = this.curve.n;
  34790. this.hash = options.hash;
  34791. assert(this.g.validate(), 'Invalid curve');
  34792. assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
  34793. }
  34794. curves.PresetCurve = PresetCurve;
  34795. function defineCurve(name, options) {
  34796. Object.defineProperty(curves, name, {
  34797. configurable: true,
  34798. enumerable: true,
  34799. get: function () {
  34800. var curve = new PresetCurve(options);
  34801. Object.defineProperty(curves, name, {
  34802. configurable: true,
  34803. enumerable: true,
  34804. value: curve
  34805. });
  34806. return curve;
  34807. }
  34808. });
  34809. }
  34810. defineCurve('p192', {
  34811. type: 'short',
  34812. prime: 'p192',
  34813. p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
  34814. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
  34815. b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
  34816. n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
  34817. hash: hash.sha256,
  34818. gRed: false,
  34819. g: ['188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012', '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811']
  34820. });
  34821. defineCurve('p224', {
  34822. type: 'short',
  34823. prime: 'p224',
  34824. p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
  34825. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
  34826. b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
  34827. n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
  34828. hash: hash.sha256,
  34829. gRed: false,
  34830. g: ['b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21', 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34']
  34831. });
  34832. defineCurve('p256', {
  34833. type: 'short',
  34834. prime: null,
  34835. p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
  34836. a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
  34837. b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
  34838. n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
  34839. hash: hash.sha256,
  34840. gRed: false,
  34841. g: ['6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296', '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5']
  34842. });
  34843. defineCurve('p384', {
  34844. type: 'short',
  34845. prime: null,
  34846. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 ffffffff',
  34847. a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 fffffffc',
  34848. b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' + '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
  34849. n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' + 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
  34850. hash: hash.sha384,
  34851. gRed: false,
  34852. g: ['aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' + '5502f25d bf55296c 3a545e38 72760ab7', '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' + '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f']
  34853. });
  34854. defineCurve('p521', {
  34855. type: 'short',
  34856. prime: null,
  34857. p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff',
  34858. a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff fffffffc',
  34859. b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' + '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' + '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
  34860. n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' + 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
  34861. hash: hash.sha512,
  34862. gRed: false,
  34863. g: ['000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' + '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' + 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66', '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' + '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' + '3fad0761 353c7086 a272c240 88be9476 9fd16650']
  34864. });
  34865. defineCurve('curve25519', {
  34866. type: 'mont',
  34867. prime: 'p25519',
  34868. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  34869. a: '76d06',
  34870. b: '1',
  34871. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  34872. hash: hash.sha256,
  34873. gRed: false,
  34874. g: ['9']
  34875. });
  34876. defineCurve('ed25519', {
  34877. type: 'edwards',
  34878. prime: 'p25519',
  34879. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  34880. a: '-1',
  34881. c: '1',
  34882. // -121665 * (121666^(-1)) (mod P)
  34883. d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  34884. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  34885. hash: hash.sha256,
  34886. gRed: false,
  34887. g: ['216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
  34888. // 4/5
  34889. '6666666666666666666666666666666666666666666666666666666666666658']
  34890. });
  34891. var pre;
  34892. try {
  34893. pre = require('./precomputed/secp256k1');
  34894. } catch (e) {
  34895. pre = undefined;
  34896. }
  34897. defineCurve('secp256k1', {
  34898. type: 'short',
  34899. prime: 'k256',
  34900. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
  34901. a: '0',
  34902. b: '7',
  34903. n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
  34904. h: '1',
  34905. hash: hash.sha256,
  34906. // Precomputed endomorphism
  34907. beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
  34908. lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
  34909. basis: [{
  34910. a: '3086d221a7d46bcde86c90e49284eb15',
  34911. b: '-e4437ed6010e88286f547fa90abfe4c3'
  34912. }, {
  34913. a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
  34914. b: '3086d221a7d46bcde86c90e49284eb15'
  34915. }],
  34916. gRed: false,
  34917. g: ['79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', pre]
  34918. });
  34919. },{"./curve":408,"./precomputed/secp256k1":418,"./utils":419,"hash.js":426}],412:[function(require,module,exports){
  34920. 'use strict';
  34921. var BN = require('bn.js');
  34922. var HmacDRBG = require('hmac-drbg');
  34923. var utils = require('../utils');
  34924. var curves = require('../curves');
  34925. var rand = require('brorand');
  34926. var assert = utils.assert;
  34927. var KeyPair = require('./key');
  34928. var Signature = require('./signature');
  34929. function EC(options) {
  34930. if (!(this instanceof EC)) return new EC(options);
  34931. // Shortcut `elliptic.ec(curve-name)`
  34932. if (typeof options === 'string') {
  34933. assert(Object.prototype.hasOwnProperty.call(curves, options), 'Unknown curve ' + options);
  34934. options = curves[options];
  34935. }
  34936. // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
  34937. if (options instanceof curves.PresetCurve) options = {
  34938. curve: options
  34939. };
  34940. this.curve = options.curve.curve;
  34941. this.n = this.curve.n;
  34942. this.nh = this.n.ushrn(1);
  34943. this.g = this.curve.g;
  34944. // Point on curve
  34945. this.g = options.curve.g;
  34946. this.g.precompute(options.curve.n.bitLength() + 1);
  34947. // Hash for function for DRBG
  34948. this.hash = options.hash || options.curve.hash;
  34949. }
  34950. module.exports = EC;
  34951. EC.prototype.keyPair = function keyPair(options) {
  34952. return new KeyPair(this, options);
  34953. };
  34954. EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
  34955. return KeyPair.fromPrivate(this, priv, enc);
  34956. };
  34957. EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
  34958. return KeyPair.fromPublic(this, pub, enc);
  34959. };
  34960. EC.prototype.genKeyPair = function genKeyPair(options) {
  34961. if (!options) options = {};
  34962. // Instantiate Hmac_DRBG
  34963. var drbg = new HmacDRBG({
  34964. hash: this.hash,
  34965. pers: options.pers,
  34966. persEnc: options.persEnc || 'utf8',
  34967. entropy: options.entropy || rand(this.hash.hmacStrength),
  34968. entropyEnc: options.entropy && options.entropyEnc || 'utf8',
  34969. nonce: this.n.toArray()
  34970. });
  34971. var bytes = this.n.byteLength();
  34972. var ns2 = this.n.sub(new BN(2));
  34973. for (;;) {
  34974. var priv = new BN(drbg.generate(bytes));
  34975. if (priv.cmp(ns2) > 0) continue;
  34976. priv.iaddn(1);
  34977. return this.keyFromPrivate(priv);
  34978. }
  34979. };
  34980. EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
  34981. var delta = msg.byteLength() * 8 - this.n.bitLength();
  34982. if (delta > 0) msg = msg.ushrn(delta);
  34983. if (!truncOnly && msg.cmp(this.n) >= 0) return msg.sub(this.n);else return msg;
  34984. };
  34985. EC.prototype.sign = function sign(msg, key, enc, options) {
  34986. if (typeof enc === 'object') {
  34987. options = enc;
  34988. enc = null;
  34989. }
  34990. if (!options) options = {};
  34991. key = this.keyFromPrivate(key, enc);
  34992. msg = this._truncateToN(new BN(msg, 16));
  34993. // Zero-extend key to provide enough entropy
  34994. var bytes = this.n.byteLength();
  34995. var bkey = key.getPrivate().toArray('be', bytes);
  34996. // Zero-extend nonce to have the same byte size as N
  34997. var nonce = msg.toArray('be', bytes);
  34998. // Instantiate Hmac_DRBG
  34999. var drbg = new HmacDRBG({
  35000. hash: this.hash,
  35001. entropy: bkey,
  35002. nonce: nonce,
  35003. pers: options.pers,
  35004. persEnc: options.persEnc || 'utf8'
  35005. });
  35006. // Number of bytes to generate
  35007. var ns1 = this.n.sub(new BN(1));
  35008. for (var iter = 0;; iter++) {
  35009. var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength()));
  35010. k = this._truncateToN(k, true);
  35011. if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) continue;
  35012. var kp = this.g.mul(k);
  35013. if (kp.isInfinity()) continue;
  35014. var kpX = kp.getX();
  35015. var r = kpX.umod(this.n);
  35016. if (r.cmpn(0) === 0) continue;
  35017. var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
  35018. s = s.umod(this.n);
  35019. if (s.cmpn(0) === 0) continue;
  35020. var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0);
  35021. // Use complement of `s`, if it is > `n / 2`
  35022. if (options.canonical && s.cmp(this.nh) > 0) {
  35023. s = this.n.sub(s);
  35024. recoveryParam ^= 1;
  35025. }
  35026. return new Signature({
  35027. r: r,
  35028. s: s,
  35029. recoveryParam: recoveryParam
  35030. });
  35031. }
  35032. };
  35033. EC.prototype.verify = function verify(msg, signature, key, enc) {
  35034. msg = this._truncateToN(new BN(msg, 16));
  35035. key = this.keyFromPublic(key, enc);
  35036. signature = new Signature(signature, 'hex');
  35037. // Perform primitive values validation
  35038. var r = signature.r;
  35039. var s = signature.s;
  35040. if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) return false;
  35041. if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false;
  35042. // Validate signature
  35043. var sinv = s.invm(this.n);
  35044. var u1 = sinv.mul(msg).umod(this.n);
  35045. var u2 = sinv.mul(r).umod(this.n);
  35046. var p;
  35047. if (!this.curve._maxwellTrick) {
  35048. p = this.g.mulAdd(u1, key.getPublic(), u2);
  35049. if (p.isInfinity()) return false;
  35050. return p.getX().umod(this.n).cmp(r) === 0;
  35051. }
  35052. // NOTE: Greg Maxwell's trick, inspired by:
  35053. // https://git.io/vad3K
  35054. p = this.g.jmulAdd(u1, key.getPublic(), u2);
  35055. if (p.isInfinity()) return false;
  35056. // Compare `p.x` of Jacobian point with `r`,
  35057. // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
  35058. // inverse of `p.z^2`
  35059. return p.eqXToP(r);
  35060. };
  35061. EC.prototype.recoverPubKey = function (msg, signature, j, enc) {
  35062. assert((3 & j) === j, 'The recovery param is more than two bits');
  35063. signature = new Signature(signature, enc);
  35064. var n = this.n;
  35065. var e = new BN(msg);
  35066. var r = signature.r;
  35067. var s = signature.s;
  35068. // A set LSB signifies that the y-coordinate is odd
  35069. var isYOdd = j & 1;
  35070. var isSecondKey = j >> 1;
  35071. if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) throw new Error('Unable to find sencond key candinate');
  35072. // 1.1. Let x = r + jn.
  35073. if (isSecondKey) r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);else r = this.curve.pointFromX(r, isYOdd);
  35074. var rInv = signature.r.invm(n);
  35075. var s1 = n.sub(e).mul(rInv).umod(n);
  35076. var s2 = s.mul(rInv).umod(n);
  35077. // 1.6.1 Compute Q = r^-1 (sR - eG)
  35078. // Q = r^-1 (sR + -eG)
  35079. return this.g.mulAdd(s1, r, s2);
  35080. };
  35081. EC.prototype.getKeyRecoveryParam = function (e, signature, Q, enc) {
  35082. signature = new Signature(signature, enc);
  35083. if (signature.recoveryParam !== null) return signature.recoveryParam;
  35084. for (var i = 0; i < 4; i++) {
  35085. var Qprime;
  35086. try {
  35087. Qprime = this.recoverPubKey(e, signature, i);
  35088. } catch (e) {
  35089. continue;
  35090. }
  35091. if (Qprime.eq(Q)) return i;
  35092. }
  35093. throw new Error('Unable to find valid recovery factor');
  35094. };
  35095. },{"../curves":411,"../utils":419,"./key":413,"./signature":414,"bn.js":420,"brorand":187,"hmac-drbg":438}],413:[function(require,module,exports){
  35096. 'use strict';
  35097. var BN = require('bn.js');
  35098. var utils = require('../utils');
  35099. var assert = utils.assert;
  35100. function KeyPair(ec, options) {
  35101. this.ec = ec;
  35102. this.priv = null;
  35103. this.pub = null;
  35104. // KeyPair(ec, { priv: ..., pub: ... })
  35105. if (options.priv) this._importPrivate(options.priv, options.privEnc);
  35106. if (options.pub) this._importPublic(options.pub, options.pubEnc);
  35107. }
  35108. module.exports = KeyPair;
  35109. KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
  35110. if (pub instanceof KeyPair) return pub;
  35111. return new KeyPair(ec, {
  35112. pub: pub,
  35113. pubEnc: enc
  35114. });
  35115. };
  35116. KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
  35117. if (priv instanceof KeyPair) return priv;
  35118. return new KeyPair(ec, {
  35119. priv: priv,
  35120. privEnc: enc
  35121. });
  35122. };
  35123. KeyPair.prototype.validate = function validate() {
  35124. var pub = this.getPublic();
  35125. if (pub.isInfinity()) return {
  35126. result: false,
  35127. reason: 'Invalid public key'
  35128. };
  35129. if (!pub.validate()) return {
  35130. result: false,
  35131. reason: 'Public key is not a point'
  35132. };
  35133. if (!pub.mul(this.ec.curve.n).isInfinity()) return {
  35134. result: false,
  35135. reason: 'Public key * N != O'
  35136. };
  35137. return {
  35138. result: true,
  35139. reason: null
  35140. };
  35141. };
  35142. KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  35143. // compact is optional argument
  35144. if (typeof compact === 'string') {
  35145. enc = compact;
  35146. compact = null;
  35147. }
  35148. if (!this.pub) this.pub = this.ec.g.mul(this.priv);
  35149. if (!enc) return this.pub;
  35150. return this.pub.encode(enc, compact);
  35151. };
  35152. KeyPair.prototype.getPrivate = function getPrivate(enc) {
  35153. if (enc === 'hex') return this.priv.toString(16, 2);else return this.priv;
  35154. };
  35155. KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
  35156. this.priv = new BN(key, enc || 16);
  35157. // Ensure that the priv won't be bigger than n, otherwise we may fail
  35158. // in fixed multiplication method
  35159. this.priv = this.priv.umod(this.ec.curve.n);
  35160. };
  35161. KeyPair.prototype._importPublic = function _importPublic(key, enc) {
  35162. if (key.x || key.y) {
  35163. // Montgomery points only have an `x` coordinate.
  35164. // Weierstrass/Edwards points on the other hand have both `x` and
  35165. // `y` coordinates.
  35166. if (this.ec.curve.type === 'mont') {
  35167. assert(key.x, 'Need x coordinate');
  35168. } else if (this.ec.curve.type === 'short' || this.ec.curve.type === 'edwards') {
  35169. assert(key.x && key.y, 'Need both x and y coordinate');
  35170. }
  35171. this.pub = this.ec.curve.point(key.x, key.y);
  35172. return;
  35173. }
  35174. this.pub = this.ec.curve.decodePoint(key, enc);
  35175. };
  35176. // ECDH
  35177. KeyPair.prototype.derive = function derive(pub) {
  35178. if (!pub.validate()) {
  35179. assert(pub.validate(), 'public point not validated');
  35180. }
  35181. return pub.mul(this.priv).getX();
  35182. };
  35183. // ECDSA
  35184. KeyPair.prototype.sign = function sign(msg, enc, options) {
  35185. return this.ec.sign(msg, this, enc, options);
  35186. };
  35187. KeyPair.prototype.verify = function verify(msg, signature) {
  35188. return this.ec.verify(msg, signature, this);
  35189. };
  35190. KeyPair.prototype.inspect = function inspect() {
  35191. return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) + ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
  35192. };
  35193. },{"../utils":419,"bn.js":420}],414:[function(require,module,exports){
  35194. 'use strict';
  35195. var BN = require('bn.js');
  35196. var utils = require('../utils');
  35197. var assert = utils.assert;
  35198. function Signature(options, enc) {
  35199. if (options instanceof Signature) return options;
  35200. if (this._importDER(options, enc)) return;
  35201. assert(options.r && options.s, 'Signature without r or s');
  35202. this.r = new BN(options.r, 16);
  35203. this.s = new BN(options.s, 16);
  35204. if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam;
  35205. }
  35206. module.exports = Signature;
  35207. function Position() {
  35208. this.place = 0;
  35209. }
  35210. function getLength(buf, p) {
  35211. var initial = buf[p.place++];
  35212. if (!(initial & 0x80)) {
  35213. return initial;
  35214. }
  35215. var octetLen = initial & 0xf;
  35216. // Indefinite length or overflow
  35217. if (octetLen === 0 || octetLen > 4) {
  35218. return false;
  35219. }
  35220. var val = 0;
  35221. for (var i = 0, off = p.place; i < octetLen; i++, off++) {
  35222. val <<= 8;
  35223. val |= buf[off];
  35224. val >>>= 0;
  35225. }
  35226. // Leading zeroes
  35227. if (val <= 0x7f) {
  35228. return false;
  35229. }
  35230. p.place = off;
  35231. return val;
  35232. }
  35233. function rmPadding(buf) {
  35234. var i = 0;
  35235. var len = buf.length - 1;
  35236. while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
  35237. i++;
  35238. }
  35239. if (i === 0) {
  35240. return buf;
  35241. }
  35242. return buf.slice(i);
  35243. }
  35244. Signature.prototype._importDER = function _importDER(data, enc) {
  35245. data = utils.toArray(data, enc);
  35246. var p = new Position();
  35247. if (data[p.place++] !== 0x30) {
  35248. return false;
  35249. }
  35250. var len = getLength(data, p);
  35251. if (len === false) {
  35252. return false;
  35253. }
  35254. if (len + p.place !== data.length) {
  35255. return false;
  35256. }
  35257. if (data[p.place++] !== 0x02) {
  35258. return false;
  35259. }
  35260. var rlen = getLength(data, p);
  35261. if (rlen === false) {
  35262. return false;
  35263. }
  35264. var r = data.slice(p.place, rlen + p.place);
  35265. p.place += rlen;
  35266. if (data[p.place++] !== 0x02) {
  35267. return false;
  35268. }
  35269. var slen = getLength(data, p);
  35270. if (slen === false) {
  35271. return false;
  35272. }
  35273. if (data.length !== slen + p.place) {
  35274. return false;
  35275. }
  35276. var s = data.slice(p.place, slen + p.place);
  35277. if (r[0] === 0) {
  35278. if (r[1] & 0x80) {
  35279. r = r.slice(1);
  35280. } else {
  35281. // Leading zeroes
  35282. return false;
  35283. }
  35284. }
  35285. if (s[0] === 0) {
  35286. if (s[1] & 0x80) {
  35287. s = s.slice(1);
  35288. } else {
  35289. // Leading zeroes
  35290. return false;
  35291. }
  35292. }
  35293. this.r = new BN(r);
  35294. this.s = new BN(s);
  35295. this.recoveryParam = null;
  35296. return true;
  35297. };
  35298. function constructLength(arr, len) {
  35299. if (len < 0x80) {
  35300. arr.push(len);
  35301. return;
  35302. }
  35303. var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
  35304. arr.push(octets | 0x80);
  35305. while (--octets) {
  35306. arr.push(len >>> (octets << 3) & 0xff);
  35307. }
  35308. arr.push(len);
  35309. }
  35310. Signature.prototype.toDER = function toDER(enc) {
  35311. var r = this.r.toArray();
  35312. var s = this.s.toArray();
  35313. // Pad values
  35314. if (r[0] & 0x80) r = [0].concat(r);
  35315. // Pad values
  35316. if (s[0] & 0x80) s = [0].concat(s);
  35317. r = rmPadding(r);
  35318. s = rmPadding(s);
  35319. while (!s[0] && !(s[1] & 0x80)) {
  35320. s = s.slice(1);
  35321. }
  35322. var arr = [0x02];
  35323. constructLength(arr, r.length);
  35324. arr = arr.concat(r);
  35325. arr.push(0x02);
  35326. constructLength(arr, s.length);
  35327. var backHalf = arr.concat(s);
  35328. var res = [0x30];
  35329. constructLength(res, backHalf.length);
  35330. res = res.concat(backHalf);
  35331. return utils.encode(res, enc);
  35332. };
  35333. },{"../utils":419,"bn.js":420}],415:[function(require,module,exports){
  35334. 'use strict';
  35335. var hash = require('hash.js');
  35336. var curves = require('../curves');
  35337. var utils = require('../utils');
  35338. var assert = utils.assert;
  35339. var parseBytes = utils.parseBytes;
  35340. var KeyPair = require('./key');
  35341. var Signature = require('./signature');
  35342. function EDDSA(curve) {
  35343. assert(curve === 'ed25519', 'only tested with ed25519 so far');
  35344. if (!(this instanceof EDDSA)) return new EDDSA(curve);
  35345. curve = curves[curve].curve;
  35346. this.curve = curve;
  35347. this.g = curve.g;
  35348. this.g.precompute(curve.n.bitLength() + 1);
  35349. this.pointClass = curve.point().constructor;
  35350. this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
  35351. this.hash = hash.sha512;
  35352. }
  35353. module.exports = EDDSA;
  35354. /**
  35355. * @param {Array|String} message - message bytes
  35356. * @param {Array|String|KeyPair} secret - secret bytes or a keypair
  35357. * @returns {Signature} - signature
  35358. */
  35359. EDDSA.prototype.sign = function sign(message, secret) {
  35360. message = parseBytes(message);
  35361. var key = this.keyFromSecret(secret);
  35362. var r = this.hashInt(key.messagePrefix(), message);
  35363. var R = this.g.mul(r);
  35364. var Rencoded = this.encodePoint(R);
  35365. var s_ = this.hashInt(Rencoded, key.pubBytes(), message).mul(key.priv());
  35366. var S = r.add(s_).umod(this.curve.n);
  35367. return this.makeSignature({
  35368. R: R,
  35369. S: S,
  35370. Rencoded: Rencoded
  35371. });
  35372. };
  35373. /**
  35374. * @param {Array} message - message bytes
  35375. * @param {Array|String|Signature} sig - sig bytes
  35376. * @param {Array|String|Point|KeyPair} pub - public key
  35377. * @returns {Boolean} - true if public key matches sig of message
  35378. */
  35379. EDDSA.prototype.verify = function verify(message, sig, pub) {
  35380. message = parseBytes(message);
  35381. sig = this.makeSignature(sig);
  35382. var key = this.keyFromPublic(pub);
  35383. var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
  35384. var SG = this.g.mul(sig.S());
  35385. var RplusAh = sig.R().add(key.pub().mul(h));
  35386. return RplusAh.eq(SG);
  35387. };
  35388. EDDSA.prototype.hashInt = function hashInt() {
  35389. var hash = this.hash();
  35390. for (var i = 0; i < arguments.length; i++) hash.update(arguments[i]);
  35391. return utils.intFromLE(hash.digest()).umod(this.curve.n);
  35392. };
  35393. EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
  35394. return KeyPair.fromPublic(this, pub);
  35395. };
  35396. EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
  35397. return KeyPair.fromSecret(this, secret);
  35398. };
  35399. EDDSA.prototype.makeSignature = function makeSignature(sig) {
  35400. if (sig instanceof Signature) return sig;
  35401. return new Signature(this, sig);
  35402. };
  35403. /**
  35404. * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
  35405. *
  35406. * EDDSA defines methods for encoding and decoding points and integers. These are
  35407. * helper convenience methods, that pass along to utility functions implied
  35408. * parameters.
  35409. *
  35410. */
  35411. EDDSA.prototype.encodePoint = function encodePoint(point) {
  35412. var enc = point.getY().toArray('le', this.encodingLength);
  35413. enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
  35414. return enc;
  35415. };
  35416. EDDSA.prototype.decodePoint = function decodePoint(bytes) {
  35417. bytes = utils.parseBytes(bytes);
  35418. var lastIx = bytes.length - 1;
  35419. var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
  35420. var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
  35421. var y = utils.intFromLE(normed);
  35422. return this.curve.pointFromY(y, xIsOdd);
  35423. };
  35424. EDDSA.prototype.encodeInt = function encodeInt(num) {
  35425. return num.toArray('le', this.encodingLength);
  35426. };
  35427. EDDSA.prototype.decodeInt = function decodeInt(bytes) {
  35428. return utils.intFromLE(bytes);
  35429. };
  35430. EDDSA.prototype.isPoint = function isPoint(val) {
  35431. return val instanceof this.pointClass;
  35432. };
  35433. },{"../curves":411,"../utils":419,"./key":416,"./signature":417,"hash.js":426}],416:[function(require,module,exports){
  35434. 'use strict';
  35435. var utils = require('../utils');
  35436. var assert = utils.assert;
  35437. var parseBytes = utils.parseBytes;
  35438. var cachedProperty = utils.cachedProperty;
  35439. /**
  35440. * @param {EDDSA} eddsa - instance
  35441. * @param {Object} params - public/private key parameters
  35442. *
  35443. * @param {Array<Byte>} [params.secret] - secret seed bytes
  35444. * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
  35445. * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
  35446. *
  35447. */
  35448. function KeyPair(eddsa, params) {
  35449. this.eddsa = eddsa;
  35450. this._secret = parseBytes(params.secret);
  35451. if (eddsa.isPoint(params.pub)) this._pub = params.pub;else this._pubBytes = parseBytes(params.pub);
  35452. }
  35453. KeyPair.fromPublic = function fromPublic(eddsa, pub) {
  35454. if (pub instanceof KeyPair) return pub;
  35455. return new KeyPair(eddsa, {
  35456. pub: pub
  35457. });
  35458. };
  35459. KeyPair.fromSecret = function fromSecret(eddsa, secret) {
  35460. if (secret instanceof KeyPair) return secret;
  35461. return new KeyPair(eddsa, {
  35462. secret: secret
  35463. });
  35464. };
  35465. KeyPair.prototype.secret = function secret() {
  35466. return this._secret;
  35467. };
  35468. cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
  35469. return this.eddsa.encodePoint(this.pub());
  35470. });
  35471. cachedProperty(KeyPair, 'pub', function pub() {
  35472. if (this._pubBytes) return this.eddsa.decodePoint(this._pubBytes);
  35473. return this.eddsa.g.mul(this.priv());
  35474. });
  35475. cachedProperty(KeyPair, 'privBytes', function privBytes() {
  35476. var eddsa = this.eddsa;
  35477. var hash = this.hash();
  35478. var lastIx = eddsa.encodingLength - 1;
  35479. var a = hash.slice(0, eddsa.encodingLength);
  35480. a[0] &= 248;
  35481. a[lastIx] &= 127;
  35482. a[lastIx] |= 64;
  35483. return a;
  35484. });
  35485. cachedProperty(KeyPair, 'priv', function priv() {
  35486. return this.eddsa.decodeInt(this.privBytes());
  35487. });
  35488. cachedProperty(KeyPair, 'hash', function hash() {
  35489. return this.eddsa.hash().update(this.secret()).digest();
  35490. });
  35491. cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
  35492. return this.hash().slice(this.eddsa.encodingLength);
  35493. });
  35494. KeyPair.prototype.sign = function sign(message) {
  35495. assert(this._secret, 'KeyPair can only verify');
  35496. return this.eddsa.sign(message, this);
  35497. };
  35498. KeyPair.prototype.verify = function verify(message, sig) {
  35499. return this.eddsa.verify(message, sig, this);
  35500. };
  35501. KeyPair.prototype.getSecret = function getSecret(enc) {
  35502. assert(this._secret, 'KeyPair is public only');
  35503. return utils.encode(this.secret(), enc);
  35504. };
  35505. KeyPair.prototype.getPublic = function getPublic(enc) {
  35506. return utils.encode(this.pubBytes(), enc);
  35507. };
  35508. module.exports = KeyPair;
  35509. },{"../utils":419}],417:[function(require,module,exports){
  35510. 'use strict';
  35511. var BN = require('bn.js');
  35512. var utils = require('../utils');
  35513. var assert = utils.assert;
  35514. var cachedProperty = utils.cachedProperty;
  35515. var parseBytes = utils.parseBytes;
  35516. /**
  35517. * @param {EDDSA} eddsa - eddsa instance
  35518. * @param {Array<Bytes>|Object} sig -
  35519. * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
  35520. * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
  35521. * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
  35522. * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
  35523. */
  35524. function Signature(eddsa, sig) {
  35525. this.eddsa = eddsa;
  35526. if (typeof sig !== 'object') sig = parseBytes(sig);
  35527. if (Array.isArray(sig)) {
  35528. sig = {
  35529. R: sig.slice(0, eddsa.encodingLength),
  35530. S: sig.slice(eddsa.encodingLength)
  35531. };
  35532. }
  35533. assert(sig.R && sig.S, 'Signature without R or S');
  35534. if (eddsa.isPoint(sig.R)) this._R = sig.R;
  35535. if (sig.S instanceof BN) this._S = sig.S;
  35536. this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
  35537. this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
  35538. }
  35539. cachedProperty(Signature, 'S', function S() {
  35540. return this.eddsa.decodeInt(this.Sencoded());
  35541. });
  35542. cachedProperty(Signature, 'R', function R() {
  35543. return this.eddsa.decodePoint(this.Rencoded());
  35544. });
  35545. cachedProperty(Signature, 'Rencoded', function Rencoded() {
  35546. return this.eddsa.encodePoint(this.R());
  35547. });
  35548. cachedProperty(Signature, 'Sencoded', function Sencoded() {
  35549. return this.eddsa.encodeInt(this.S());
  35550. });
  35551. Signature.prototype.toBytes = function toBytes() {
  35552. return this.Rencoded().concat(this.Sencoded());
  35553. };
  35554. Signature.prototype.toHex = function toHex() {
  35555. return utils.encode(this.toBytes(), 'hex').toUpperCase();
  35556. };
  35557. module.exports = Signature;
  35558. },{"../utils":419,"bn.js":420}],418:[function(require,module,exports){
  35559. "use strict";
  35560. module.exports = {
  35561. doubles: {
  35562. step: 4,
  35563. points: [['e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a', 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'], ['8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508', '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'], ['175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739', 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'], ['363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640', '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'], ['8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c', '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'], ['723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda', '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'], ['eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa', '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'], ['100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0', 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'], ['e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d', '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'], ['feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d', 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'], ['da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1', '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'], ['53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0', '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'], ['8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047', '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'], ['385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862', '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'], ['6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7', '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'], ['3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd', '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'], ['85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83', '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'], ['948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a', '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'], ['6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8', 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'], ['e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d', '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'], ['e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725', '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'], ['213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754', '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'], ['4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c', '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'], ['fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6', '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'], ['76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39', 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'], ['c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891', '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'], ['d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b', 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'], ['b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03', '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'], ['e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d', 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'], ['a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070', '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'], ['90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4', 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'], ['8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da', '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'], ['e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11', '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'], ['8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e', 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'], ['e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41', '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'], ['b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef', '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'], ['d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8', 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'], ['324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d', '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'], ['4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96', '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'], ['9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd', 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'], ['6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5', '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'], ['a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266', '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'], ['7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71', '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'], ['928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac', 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'], ['85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751', '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'], ['ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e', '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'], ['827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241', 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'], ['eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3', 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'], ['e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f', '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'], ['1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19', 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'], ['146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be', 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'], ['fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9', '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'], ['da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2', '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'], ['a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13', '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'], ['174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c', 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'], ['959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba', '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'], ['d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151', 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'], ['64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073', 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'], ['8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458', '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'], ['13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b', '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'], ['bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366', 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'], ['8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa', '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'], ['8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0', '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'], ['dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787', '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'], ['f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e', 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82']]
  35564. },
  35565. naf: {
  35566. wnd: 7,
  35567. points: [['f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9', '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'], ['2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4', 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'], ['5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc', '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'], ['acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe', 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'], ['774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb', 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'], ['f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8', 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'], ['d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e', '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'], ['defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34', '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'], ['2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c', '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'], ['352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5', '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'], ['2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f', '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'], ['9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714', '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'], ['daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729', 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'], ['c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db', '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'], ['6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4', 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'], ['1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5', 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'], ['605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479', '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'], ['62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d', '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'], ['80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f', '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'], ['7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb', 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'], ['d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9', 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'], ['49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963', '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'], ['77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74', '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'], ['f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530', 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'], ['463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b', '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'], ['f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247', 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'], ['caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1', 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'], ['2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120', '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'], ['7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435', '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'], ['754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18', '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'], ['e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8', '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'], ['186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb', '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'], ['df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f', '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'], ['5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143', 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'], ['290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba', 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'], ['af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45', 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'], ['766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a', '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'], ['59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e', 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'], ['f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8', 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'], ['7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c', '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'], ['948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519', 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'], ['7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab', '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'], ['3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca', 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'], ['d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf', '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'], ['1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610', '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'], ['733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4', 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'], ['15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c', 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'], ['a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940', 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'], ['e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980', 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'], ['311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3', '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'], ['34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf', '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'], ['f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63', '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'], ['d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448', 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'], ['32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf', '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'], ['7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5', '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'], ['ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6', '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'], ['16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5', '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'], ['eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99', 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'], ['78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51', 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'], ['494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5', '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'], ['a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5', '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'], ['c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997', '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'], ['841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881', '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'], ['5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5', '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'], ['36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66', 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'], ['336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726', 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'], ['8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede', '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'], ['1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94', '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'], ['85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31', '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'], ['29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51', 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'], ['a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252', 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'], ['4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5', 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'], ['d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b', '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'], ['ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4', '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'], ['af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f', '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'], ['e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889', '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'], ['591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246', 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'], ['11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984', '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'], ['3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a', 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'], ['cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030', 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'], ['c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197', '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'], ['c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593', 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'], ['a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef', '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'], ['347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38', '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'], ['da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a', '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'], ['c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111', '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'], ['4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502', '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'], ['3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea', 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'], ['cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26', '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'], ['b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986', '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'], ['d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e', '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'], ['48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4', '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'], ['dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda', 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'], ['6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859', 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'], ['e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f', 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'], ['eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c', '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'], ['13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942', 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'], ['ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a', '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'], ['b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80', '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'], ['ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d', '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'], ['8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1', 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'], ['52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63', 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'], ['e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352', '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'], ['7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193', 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'], ['5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00', '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'], ['32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58', 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'], ['e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7', 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'], ['8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8', 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'], ['4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e', '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'], ['3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d', 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'], ['674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b', '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'], ['d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f', 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'], ['30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6', '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'], ['be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297', '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'], ['93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a', '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'], ['b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c', 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'], ['d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52', '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'], ['d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb', 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'], ['463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065', 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'], ['7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917', '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'], ['74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9', 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'], ['30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3', '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'], ['9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57', '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'], ['176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66', 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'], ['75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8', '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'], ['809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721', '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'], ['1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180', '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9']]
  35568. }
  35569. };
  35570. },{}],419:[function(require,module,exports){
  35571. 'use strict';
  35572. var utils = exports;
  35573. var BN = require('bn.js');
  35574. var minAssert = require('minimalistic-assert');
  35575. var minUtils = require('minimalistic-crypto-utils');
  35576. utils.assert = minAssert;
  35577. utils.toArray = minUtils.toArray;
  35578. utils.zero2 = minUtils.zero2;
  35579. utils.toHex = minUtils.toHex;
  35580. utils.encode = minUtils.encode;
  35581. // Represent num in a w-NAF form
  35582. function getNAF(num, w, bits) {
  35583. var naf = new Array(Math.max(num.bitLength(), bits) + 1);
  35584. naf.fill(0);
  35585. var ws = 1 << w + 1;
  35586. var k = num.clone();
  35587. for (var i = 0; i < naf.length; i++) {
  35588. var z;
  35589. var mod = k.andln(ws - 1);
  35590. if (k.isOdd()) {
  35591. if (mod > (ws >> 1) - 1) z = (ws >> 1) - mod;else z = mod;
  35592. k.isubn(z);
  35593. } else {
  35594. z = 0;
  35595. }
  35596. naf[i] = z;
  35597. k.iushrn(1);
  35598. }
  35599. return naf;
  35600. }
  35601. utils.getNAF = getNAF;
  35602. // Represent k1, k2 in a Joint Sparse Form
  35603. function getJSF(k1, k2) {
  35604. var jsf = [[], []];
  35605. k1 = k1.clone();
  35606. k2 = k2.clone();
  35607. var d1 = 0;
  35608. var d2 = 0;
  35609. var m8;
  35610. while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
  35611. // First phase
  35612. var m14 = k1.andln(3) + d1 & 3;
  35613. var m24 = k2.andln(3) + d2 & 3;
  35614. if (m14 === 3) m14 = -1;
  35615. if (m24 === 3) m24 = -1;
  35616. var u1;
  35617. if ((m14 & 1) === 0) {
  35618. u1 = 0;
  35619. } else {
  35620. m8 = k1.andln(7) + d1 & 7;
  35621. if ((m8 === 3 || m8 === 5) && m24 === 2) u1 = -m14;else u1 = m14;
  35622. }
  35623. jsf[0].push(u1);
  35624. var u2;
  35625. if ((m24 & 1) === 0) {
  35626. u2 = 0;
  35627. } else {
  35628. m8 = k2.andln(7) + d2 & 7;
  35629. if ((m8 === 3 || m8 === 5) && m14 === 2) u2 = -m24;else u2 = m24;
  35630. }
  35631. jsf[1].push(u2);
  35632. // Second phase
  35633. if (2 * d1 === u1 + 1) d1 = 1 - d1;
  35634. if (2 * d2 === u2 + 1) d2 = 1 - d2;
  35635. k1.iushrn(1);
  35636. k2.iushrn(1);
  35637. }
  35638. return jsf;
  35639. }
  35640. utils.getJSF = getJSF;
  35641. function cachedProperty(obj, name, computer) {
  35642. var key = '_' + name;
  35643. obj.prototype[name] = function cachedProperty() {
  35644. return this[key] !== undefined ? this[key] : this[key] = computer.call(this);
  35645. };
  35646. }
  35647. utils.cachedProperty = cachedProperty;
  35648. function parseBytes(bytes) {
  35649. return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : bytes;
  35650. }
  35651. utils.parseBytes = parseBytes;
  35652. function intFromLE(bytes) {
  35653. return new BN(bytes, 'hex', 'le');
  35654. }
  35655. utils.intFromLE = intFromLE;
  35656. },{"bn.js":420,"minimalistic-assert":453,"minimalistic-crypto-utils":454}],420:[function(require,module,exports){
  35657. arguments[4][184][0].apply(exports,arguments)
  35658. },{"buffer":188,"dup":184}],421:[function(require,module,exports){
  35659. module.exports={
  35660. "name": "elliptic",
  35661. "version": "6.5.4",
  35662. "description": "EC cryptography",
  35663. "main": "lib/elliptic.js",
  35664. "files": [
  35665. "lib"
  35666. ],
  35667. "scripts": {
  35668. "lint": "eslint lib test",
  35669. "lint:fix": "npm run lint -- --fix",
  35670. "unit": "istanbul test _mocha --reporter=spec test/index.js",
  35671. "test": "npm run lint && npm run unit",
  35672. "version": "grunt dist && git add dist/"
  35673. },
  35674. "repository": {
  35675. "type": "git",
  35676. "url": "git@github.com:indutny/elliptic"
  35677. },
  35678. "keywords": [
  35679. "EC",
  35680. "Elliptic",
  35681. "curve",
  35682. "Cryptography"
  35683. ],
  35684. "author": "Fedor Indutny <fedor@indutny.com>",
  35685. "license": "MIT",
  35686. "bugs": {
  35687. "url": "https://github.com/indutny/elliptic/issues"
  35688. },
  35689. "homepage": "https://github.com/indutny/elliptic",
  35690. "devDependencies": {
  35691. "brfs": "^2.0.2",
  35692. "coveralls": "^3.1.0",
  35693. "eslint": "^7.6.0",
  35694. "grunt": "^1.2.1",
  35695. "grunt-browserify": "^5.3.0",
  35696. "grunt-cli": "^1.3.2",
  35697. "grunt-contrib-connect": "^3.0.0",
  35698. "grunt-contrib-copy": "^1.0.0",
  35699. "grunt-contrib-uglify": "^5.0.0",
  35700. "grunt-mocha-istanbul": "^5.0.2",
  35701. "grunt-saucelabs": "^9.0.1",
  35702. "istanbul": "^0.4.5",
  35703. "mocha": "^8.0.1"
  35704. },
  35705. "dependencies": {
  35706. "bn.js": "^4.11.9",
  35707. "brorand": "^1.1.0",
  35708. "hash.js": "^1.0.0",
  35709. "hmac-drbg": "^1.0.1",
  35710. "inherits": "^2.0.4",
  35711. "minimalistic-assert": "^1.0.1",
  35712. "minimalistic-crypto-utils": "^1.0.1"
  35713. }
  35714. }
  35715. },{}],422:[function(require,module,exports){
  35716. "use strict";
  35717. // Copyright Joyent, Inc. and other Node contributors.
  35718. //
  35719. // Permission is hereby granted, free of charge, to any person obtaining a
  35720. // copy of this software and associated documentation files (the
  35721. // "Software"), to deal in the Software without restriction, including
  35722. // without limitation the rights to use, copy, modify, merge, publish,
  35723. // distribute, sublicense, and/or sell copies of the Software, and to permit
  35724. // persons to whom the Software is furnished to do so, subject to the
  35725. // following conditions:
  35726. //
  35727. // The above copyright notice and this permission notice shall be included
  35728. // in all copies or substantial portions of the Software.
  35729. //
  35730. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  35731. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  35732. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  35733. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  35734. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  35735. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  35736. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  35737. var objectCreate = Object.create || objectCreatePolyfill;
  35738. var objectKeys = Object.keys || objectKeysPolyfill;
  35739. var bind = Function.prototype.bind || functionBindPolyfill;
  35740. function EventEmitter() {
  35741. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  35742. this._events = objectCreate(null);
  35743. this._eventsCount = 0;
  35744. }
  35745. this._maxListeners = this._maxListeners || undefined;
  35746. }
  35747. module.exports = EventEmitter;
  35748. // Backwards-compat with node 0.10.x
  35749. EventEmitter.EventEmitter = EventEmitter;
  35750. EventEmitter.prototype._events = undefined;
  35751. EventEmitter.prototype._maxListeners = undefined;
  35752. // By default EventEmitters will print a warning if more than 10 listeners are
  35753. // added to it. This is a useful default which helps finding memory leaks.
  35754. var defaultMaxListeners = 10;
  35755. var hasDefineProperty;
  35756. try {
  35757. var o = {};
  35758. if (Object.defineProperty) Object.defineProperty(o, 'x', {
  35759. value: 0
  35760. });
  35761. hasDefineProperty = o.x === 0;
  35762. } catch (err) {
  35763. hasDefineProperty = false;
  35764. }
  35765. if (hasDefineProperty) {
  35766. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  35767. enumerable: true,
  35768. get: function () {
  35769. return defaultMaxListeners;
  35770. },
  35771. set: function (arg) {
  35772. // check whether the input is a positive number (whose value is zero or
  35773. // greater and not a NaN).
  35774. if (typeof arg !== 'number' || arg < 0 || arg !== arg) throw new TypeError('"defaultMaxListeners" must be a positive number');
  35775. defaultMaxListeners = arg;
  35776. }
  35777. });
  35778. } else {
  35779. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  35780. }
  35781. // Obviously not all Emitters should be limited to 10. This function allows
  35782. // that to be increased. Set to zero for unlimited.
  35783. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  35784. if (typeof n !== 'number' || n < 0 || isNaN(n)) throw new TypeError('"n" argument must be a positive number');
  35785. this._maxListeners = n;
  35786. return this;
  35787. };
  35788. function $getMaxListeners(that) {
  35789. if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
  35790. return that._maxListeners;
  35791. }
  35792. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  35793. return $getMaxListeners(this);
  35794. };
  35795. // These standalone emit* functions are used to optimize calling of event
  35796. // handlers for fast cases because emit() itself often has a variable number of
  35797. // arguments and can be deoptimized because of that. These functions always have
  35798. // the same number of arguments and thus do not get deoptimized, so the code
  35799. // inside them can execute faster.
  35800. function emitNone(handler, isFn, self) {
  35801. if (isFn) handler.call(self);else {
  35802. var len = handler.length;
  35803. var listeners = arrayClone(handler, len);
  35804. for (var i = 0; i < len; ++i) listeners[i].call(self);
  35805. }
  35806. }
  35807. function emitOne(handler, isFn, self, arg1) {
  35808. if (isFn) handler.call(self, arg1);else {
  35809. var len = handler.length;
  35810. var listeners = arrayClone(handler, len);
  35811. for (var i = 0; i < len; ++i) listeners[i].call(self, arg1);
  35812. }
  35813. }
  35814. function emitTwo(handler, isFn, self, arg1, arg2) {
  35815. if (isFn) handler.call(self, arg1, arg2);else {
  35816. var len = handler.length;
  35817. var listeners = arrayClone(handler, len);
  35818. for (var i = 0; i < len; ++i) listeners[i].call(self, arg1, arg2);
  35819. }
  35820. }
  35821. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  35822. if (isFn) handler.call(self, arg1, arg2, arg3);else {
  35823. var len = handler.length;
  35824. var listeners = arrayClone(handler, len);
  35825. for (var i = 0; i < len; ++i) listeners[i].call(self, arg1, arg2, arg3);
  35826. }
  35827. }
  35828. function emitMany(handler, isFn, self, args) {
  35829. if (isFn) handler.apply(self, args);else {
  35830. var len = handler.length;
  35831. var listeners = arrayClone(handler, len);
  35832. for (var i = 0; i < len; ++i) listeners[i].apply(self, args);
  35833. }
  35834. }
  35835. EventEmitter.prototype.emit = function emit(type) {
  35836. var er, handler, len, args, i, events;
  35837. var doError = type === 'error';
  35838. events = this._events;
  35839. if (events) doError = doError && events.error == null;else if (!doError) return false;
  35840. // If there is no 'error' event listener then throw.
  35841. if (doError) {
  35842. if (arguments.length > 1) er = arguments[1];
  35843. if (er instanceof Error) {
  35844. throw er; // Unhandled 'error' event
  35845. } else {
  35846. // At least give some kind of context to the user
  35847. var err = new Error('Unhandled "error" event. (' + er + ')');
  35848. err.context = er;
  35849. throw err;
  35850. }
  35851. return false;
  35852. }
  35853. handler = events[type];
  35854. if (!handler) return false;
  35855. var isFn = typeof handler === 'function';
  35856. len = arguments.length;
  35857. switch (len) {
  35858. // fast cases
  35859. case 1:
  35860. emitNone(handler, isFn, this);
  35861. break;
  35862. case 2:
  35863. emitOne(handler, isFn, this, arguments[1]);
  35864. break;
  35865. case 3:
  35866. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  35867. break;
  35868. case 4:
  35869. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  35870. break;
  35871. // slower
  35872. default:
  35873. args = new Array(len - 1);
  35874. for (i = 1; i < len; i++) args[i - 1] = arguments[i];
  35875. emitMany(handler, isFn, this, args);
  35876. }
  35877. return true;
  35878. };
  35879. function _addListener(target, type, listener, prepend) {
  35880. var m;
  35881. var events;
  35882. var existing;
  35883. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  35884. events = target._events;
  35885. if (!events) {
  35886. events = target._events = objectCreate(null);
  35887. target._eventsCount = 0;
  35888. } else {
  35889. // To avoid recursion in the case that type === "newListener"! Before
  35890. // adding it to the listeners, first emit "newListener".
  35891. if (events.newListener) {
  35892. target.emit('newListener', type, listener.listener ? listener.listener : listener);
  35893. // Re-assign `events` because a newListener handler could have caused the
  35894. // this._events to be assigned to a new object
  35895. events = target._events;
  35896. }
  35897. existing = events[type];
  35898. }
  35899. if (!existing) {
  35900. // Optimize the case of one listener. Don't need the extra array object.
  35901. existing = events[type] = listener;
  35902. ++target._eventsCount;
  35903. } else {
  35904. if (typeof existing === 'function') {
  35905. // Adding the second element, need to change to array.
  35906. existing = events[type] = prepend ? [listener, existing] : [existing, listener];
  35907. } else {
  35908. // If we've already got an array, just append.
  35909. if (prepend) {
  35910. existing.unshift(listener);
  35911. } else {
  35912. existing.push(listener);
  35913. }
  35914. }
  35915. // Check for listener leak
  35916. if (!existing.warned) {
  35917. m = $getMaxListeners(target);
  35918. if (m && m > 0 && existing.length > m) {
  35919. existing.warned = true;
  35920. var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' "' + String(type) + '" listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit.');
  35921. w.name = 'MaxListenersExceededWarning';
  35922. w.emitter = target;
  35923. w.type = type;
  35924. w.count = existing.length;
  35925. if (typeof console === 'object' && console.warn) {
  35926. console.warn('%s: %s', w.name, w.message);
  35927. }
  35928. }
  35929. }
  35930. }
  35931. return target;
  35932. }
  35933. EventEmitter.prototype.addListener = function addListener(type, listener) {
  35934. return _addListener(this, type, listener, false);
  35935. };
  35936. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  35937. EventEmitter.prototype.prependListener = function prependListener(type, listener) {
  35938. return _addListener(this, type, listener, true);
  35939. };
  35940. function onceWrapper() {
  35941. if (!this.fired) {
  35942. this.target.removeListener(this.type, this.wrapFn);
  35943. this.fired = true;
  35944. switch (arguments.length) {
  35945. case 0:
  35946. return this.listener.call(this.target);
  35947. case 1:
  35948. return this.listener.call(this.target, arguments[0]);
  35949. case 2:
  35950. return this.listener.call(this.target, arguments[0], arguments[1]);
  35951. case 3:
  35952. return this.listener.call(this.target, arguments[0], arguments[1], arguments[2]);
  35953. default:
  35954. var args = new Array(arguments.length);
  35955. for (var i = 0; i < args.length; ++i) args[i] = arguments[i];
  35956. this.listener.apply(this.target, args);
  35957. }
  35958. }
  35959. }
  35960. function _onceWrap(target, type, listener) {
  35961. var state = {
  35962. fired: false,
  35963. wrapFn: undefined,
  35964. target: target,
  35965. type: type,
  35966. listener: listener
  35967. };
  35968. var wrapped = bind.call(onceWrapper, state);
  35969. wrapped.listener = listener;
  35970. state.wrapFn = wrapped;
  35971. return wrapped;
  35972. }
  35973. EventEmitter.prototype.once = function once(type, listener) {
  35974. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  35975. this.on(type, _onceWrap(this, type, listener));
  35976. return this;
  35977. };
  35978. EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
  35979. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  35980. this.prependListener(type, _onceWrap(this, type, listener));
  35981. return this;
  35982. };
  35983. // Emits a 'removeListener' event if and only if the listener was removed.
  35984. EventEmitter.prototype.removeListener = function removeListener(type, listener) {
  35985. var list, events, position, i, originalListener;
  35986. if (typeof listener !== 'function') throw new TypeError('"listener" argument must be a function');
  35987. events = this._events;
  35988. if (!events) return this;
  35989. list = events[type];
  35990. if (!list) return this;
  35991. if (list === listener || list.listener === listener) {
  35992. if (--this._eventsCount === 0) this._events = objectCreate(null);else {
  35993. delete events[type];
  35994. if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
  35995. }
  35996. } else if (typeof list !== 'function') {
  35997. position = -1;
  35998. for (i = list.length - 1; i >= 0; i--) {
  35999. if (list[i] === listener || list[i].listener === listener) {
  36000. originalListener = list[i].listener;
  36001. position = i;
  36002. break;
  36003. }
  36004. }
  36005. if (position < 0) return this;
  36006. if (position === 0) list.shift();else spliceOne(list, position);
  36007. if (list.length === 1) events[type] = list[0];
  36008. if (events.removeListener) this.emit('removeListener', type, originalListener || listener);
  36009. }
  36010. return this;
  36011. };
  36012. EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
  36013. var listeners, events, i;
  36014. events = this._events;
  36015. if (!events) return this;
  36016. // not listening for removeListener, no need to emit
  36017. if (!events.removeListener) {
  36018. if (arguments.length === 0) {
  36019. this._events = objectCreate(null);
  36020. this._eventsCount = 0;
  36021. } else if (events[type]) {
  36022. if (--this._eventsCount === 0) this._events = objectCreate(null);else delete events[type];
  36023. }
  36024. return this;
  36025. }
  36026. // emit removeListener for all listeners on all events
  36027. if (arguments.length === 0) {
  36028. var keys = objectKeys(events);
  36029. var key;
  36030. for (i = 0; i < keys.length; ++i) {
  36031. key = keys[i];
  36032. if (key === 'removeListener') continue;
  36033. this.removeAllListeners(key);
  36034. }
  36035. this.removeAllListeners('removeListener');
  36036. this._events = objectCreate(null);
  36037. this._eventsCount = 0;
  36038. return this;
  36039. }
  36040. listeners = events[type];
  36041. if (typeof listeners === 'function') {
  36042. this.removeListener(type, listeners);
  36043. } else if (listeners) {
  36044. // LIFO order
  36045. for (i = listeners.length - 1; i >= 0; i--) {
  36046. this.removeListener(type, listeners[i]);
  36047. }
  36048. }
  36049. return this;
  36050. };
  36051. function _listeners(target, type, unwrap) {
  36052. var events = target._events;
  36053. if (!events) return [];
  36054. var evlistener = events[type];
  36055. if (!evlistener) return [];
  36056. if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  36057. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  36058. }
  36059. EventEmitter.prototype.listeners = function listeners(type) {
  36060. return _listeners(this, type, true);
  36061. };
  36062. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  36063. return _listeners(this, type, false);
  36064. };
  36065. EventEmitter.listenerCount = function (emitter, type) {
  36066. if (typeof emitter.listenerCount === 'function') {
  36067. return emitter.listenerCount(type);
  36068. } else {
  36069. return listenerCount.call(emitter, type);
  36070. }
  36071. };
  36072. EventEmitter.prototype.listenerCount = listenerCount;
  36073. function listenerCount(type) {
  36074. var events = this._events;
  36075. if (events) {
  36076. var evlistener = events[type];
  36077. if (typeof evlistener === 'function') {
  36078. return 1;
  36079. } else if (evlistener) {
  36080. return evlistener.length;
  36081. }
  36082. }
  36083. return 0;
  36084. }
  36085. EventEmitter.prototype.eventNames = function eventNames() {
  36086. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  36087. };
  36088. // About 1.5x faster than the two-arg version of Array#splice().
  36089. function spliceOne(list, index) {
  36090. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) list[i] = list[k];
  36091. list.pop();
  36092. }
  36093. function arrayClone(arr, n) {
  36094. var copy = new Array(n);
  36095. for (var i = 0; i < n; ++i) copy[i] = arr[i];
  36096. return copy;
  36097. }
  36098. function unwrapListeners(arr) {
  36099. var ret = new Array(arr.length);
  36100. for (var i = 0; i < ret.length; ++i) {
  36101. ret[i] = arr[i].listener || arr[i];
  36102. }
  36103. return ret;
  36104. }
  36105. function objectCreatePolyfill(proto) {
  36106. var F = function () {};
  36107. F.prototype = proto;
  36108. return new F();
  36109. }
  36110. function objectKeysPolyfill(obj) {
  36111. var keys = [];
  36112. for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
  36113. keys.push(k);
  36114. }
  36115. return k;
  36116. }
  36117. function functionBindPolyfill(context) {
  36118. var fn = this;
  36119. return function () {
  36120. return fn.apply(context, arguments);
  36121. };
  36122. }
  36123. },{}],423:[function(require,module,exports){
  36124. "use strict";
  36125. var Buffer = require('safe-buffer').Buffer;
  36126. var MD5 = require('md5.js');
  36127. /* eslint-disable camelcase */
  36128. function EVP_BytesToKey(password, salt, keyBits, ivLen) {
  36129. if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary');
  36130. if (salt) {
  36131. if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary');
  36132. if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length');
  36133. }
  36134. var keyLen = keyBits / 8;
  36135. var key = Buffer.alloc(keyLen);
  36136. var iv = Buffer.alloc(ivLen || 0);
  36137. var tmp = Buffer.alloc(0);
  36138. while (keyLen > 0 || ivLen > 0) {
  36139. var hash = new MD5();
  36140. hash.update(tmp);
  36141. hash.update(password);
  36142. if (salt) hash.update(salt);
  36143. tmp = hash.digest();
  36144. var used = 0;
  36145. if (keyLen > 0) {
  36146. var keyStart = key.length - keyLen;
  36147. used = Math.min(keyLen, tmp.length);
  36148. tmp.copy(key, keyStart, 0, used);
  36149. keyLen -= used;
  36150. }
  36151. if (used < tmp.length && ivLen > 0) {
  36152. var ivStart = iv.length - ivLen;
  36153. var length = Math.min(ivLen, tmp.length - used);
  36154. tmp.copy(iv, ivStart, used, used + length);
  36155. ivLen -= length;
  36156. }
  36157. }
  36158. tmp.fill(0);
  36159. return {
  36160. key: key,
  36161. iv: iv
  36162. };
  36163. }
  36164. module.exports = EVP_BytesToKey;
  36165. },{"md5.js":450,"safe-buffer":494}],424:[function(require,module,exports){
  36166. "use strict";
  36167. Object.defineProperty(exports, "__esModule", {
  36168. value: true
  36169. });
  36170. exports.CsvParserStream = exports.ParserOptions = exports.parseFile = exports.parseStream = exports.parseString = exports.parse = exports.FormatterOptions = exports.CsvFormatterStream = exports.writeToPath = exports.writeToString = exports.writeToBuffer = exports.writeToStream = exports.write = exports.format = void 0;
  36171. var format_1 = require("@fast-csv/format");
  36172. Object.defineProperty(exports, "format", {
  36173. enumerable: true,
  36174. get: function () {
  36175. return format_1.format;
  36176. }
  36177. });
  36178. Object.defineProperty(exports, "write", {
  36179. enumerable: true,
  36180. get: function () {
  36181. return format_1.write;
  36182. }
  36183. });
  36184. Object.defineProperty(exports, "writeToStream", {
  36185. enumerable: true,
  36186. get: function () {
  36187. return format_1.writeToStream;
  36188. }
  36189. });
  36190. Object.defineProperty(exports, "writeToBuffer", {
  36191. enumerable: true,
  36192. get: function () {
  36193. return format_1.writeToBuffer;
  36194. }
  36195. });
  36196. Object.defineProperty(exports, "writeToString", {
  36197. enumerable: true,
  36198. get: function () {
  36199. return format_1.writeToString;
  36200. }
  36201. });
  36202. Object.defineProperty(exports, "writeToPath", {
  36203. enumerable: true,
  36204. get: function () {
  36205. return format_1.writeToPath;
  36206. }
  36207. });
  36208. Object.defineProperty(exports, "CsvFormatterStream", {
  36209. enumerable: true,
  36210. get: function () {
  36211. return format_1.CsvFormatterStream;
  36212. }
  36213. });
  36214. Object.defineProperty(exports, "FormatterOptions", {
  36215. enumerable: true,
  36216. get: function () {
  36217. return format_1.FormatterOptions;
  36218. }
  36219. });
  36220. var parse_1 = require("@fast-csv/parse");
  36221. Object.defineProperty(exports, "parse", {
  36222. enumerable: true,
  36223. get: function () {
  36224. return parse_1.parse;
  36225. }
  36226. });
  36227. Object.defineProperty(exports, "parseString", {
  36228. enumerable: true,
  36229. get: function () {
  36230. return parse_1.parseString;
  36231. }
  36232. });
  36233. Object.defineProperty(exports, "parseStream", {
  36234. enumerable: true,
  36235. get: function () {
  36236. return parse_1.parseStream;
  36237. }
  36238. });
  36239. Object.defineProperty(exports, "parseFile", {
  36240. enumerable: true,
  36241. get: function () {
  36242. return parse_1.parseFile;
  36243. }
  36244. });
  36245. Object.defineProperty(exports, "ParserOptions", {
  36246. enumerable: true,
  36247. get: function () {
  36248. return parse_1.ParserOptions;
  36249. }
  36250. });
  36251. Object.defineProperty(exports, "CsvParserStream", {
  36252. enumerable: true,
  36253. get: function () {
  36254. return parse_1.CsvParserStream;
  36255. }
  36256. });
  36257. },{"@fast-csv/format":151,"@fast-csv/parse":155}],425:[function(require,module,exports){
  36258. 'use strict';
  36259. var Buffer = require('safe-buffer').Buffer;
  36260. var Transform = require('readable-stream').Transform;
  36261. var inherits = require('inherits');
  36262. function throwIfNotStringOrBuffer(val, prefix) {
  36263. if (!Buffer.isBuffer(val) && typeof val !== 'string') {
  36264. throw new TypeError(prefix + ' must be a string or a buffer');
  36265. }
  36266. }
  36267. function HashBase(blockSize) {
  36268. Transform.call(this);
  36269. this._block = Buffer.allocUnsafe(blockSize);
  36270. this._blockSize = blockSize;
  36271. this._blockOffset = 0;
  36272. this._length = [0, 0, 0, 0];
  36273. this._finalized = false;
  36274. }
  36275. inherits(HashBase, Transform);
  36276. HashBase.prototype._transform = function (chunk, encoding, callback) {
  36277. var error = null;
  36278. try {
  36279. this.update(chunk, encoding);
  36280. } catch (err) {
  36281. error = err;
  36282. }
  36283. callback(error);
  36284. };
  36285. HashBase.prototype._flush = function (callback) {
  36286. var error = null;
  36287. try {
  36288. this.push(this.digest());
  36289. } catch (err) {
  36290. error = err;
  36291. }
  36292. callback(error);
  36293. };
  36294. HashBase.prototype.update = function (data, encoding) {
  36295. throwIfNotStringOrBuffer(data, 'Data');
  36296. if (this._finalized) throw new Error('Digest already called');
  36297. if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding);
  36298. // consume data
  36299. var block = this._block;
  36300. var offset = 0;
  36301. while (this._blockOffset + data.length - offset >= this._blockSize) {
  36302. for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++];
  36303. this._update();
  36304. this._blockOffset = 0;
  36305. }
  36306. while (offset < data.length) block[this._blockOffset++] = data[offset++];
  36307. // update length
  36308. for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
  36309. this._length[j] += carry;
  36310. carry = this._length[j] / 0x0100000000 | 0;
  36311. if (carry > 0) this._length[j] -= 0x0100000000 * carry;
  36312. }
  36313. return this;
  36314. };
  36315. HashBase.prototype._update = function () {
  36316. throw new Error('_update is not implemented');
  36317. };
  36318. HashBase.prototype.digest = function (encoding) {
  36319. if (this._finalized) throw new Error('Digest already called');
  36320. this._finalized = true;
  36321. var digest = this._digest();
  36322. if (encoding !== undefined) digest = digest.toString(encoding);
  36323. // reset state
  36324. this._block.fill(0);
  36325. this._blockOffset = 0;
  36326. for (var i = 0; i < 4; ++i) this._length[i] = 0;
  36327. return digest;
  36328. };
  36329. HashBase.prototype._digest = function () {
  36330. throw new Error('_digest is not implemented');
  36331. };
  36332. module.exports = HashBase;
  36333. },{"inherits":440,"readable-stream":491,"safe-buffer":494}],426:[function(require,module,exports){
  36334. "use strict";
  36335. var hash = exports;
  36336. hash.utils = require('./hash/utils');
  36337. hash.common = require('./hash/common');
  36338. hash.sha = require('./hash/sha');
  36339. hash.ripemd = require('./hash/ripemd');
  36340. hash.hmac = require('./hash/hmac');
  36341. // Proxy hash functions to the main object
  36342. hash.sha1 = hash.sha.sha1;
  36343. hash.sha256 = hash.sha.sha256;
  36344. hash.sha224 = hash.sha.sha224;
  36345. hash.sha384 = hash.sha.sha384;
  36346. hash.sha512 = hash.sha.sha512;
  36347. hash.ripemd160 = hash.ripemd.ripemd160;
  36348. },{"./hash/common":427,"./hash/hmac":428,"./hash/ripemd":429,"./hash/sha":430,"./hash/utils":437}],427:[function(require,module,exports){
  36349. 'use strict';
  36350. var utils = require('./utils');
  36351. var assert = require('minimalistic-assert');
  36352. function BlockHash() {
  36353. this.pending = null;
  36354. this.pendingTotal = 0;
  36355. this.blockSize = this.constructor.blockSize;
  36356. this.outSize = this.constructor.outSize;
  36357. this.hmacStrength = this.constructor.hmacStrength;
  36358. this.padLength = this.constructor.padLength / 8;
  36359. this.endian = 'big';
  36360. this._delta8 = this.blockSize / 8;
  36361. this._delta32 = this.blockSize / 32;
  36362. }
  36363. exports.BlockHash = BlockHash;
  36364. BlockHash.prototype.update = function update(msg, enc) {
  36365. // Convert message to array, pad it, and join into 32bit blocks
  36366. msg = utils.toArray(msg, enc);
  36367. if (!this.pending) this.pending = msg;else this.pending = this.pending.concat(msg);
  36368. this.pendingTotal += msg.length;
  36369. // Enough data, try updating
  36370. if (this.pending.length >= this._delta8) {
  36371. msg = this.pending;
  36372. // Process pending data in blocks
  36373. var r = msg.length % this._delta8;
  36374. this.pending = msg.slice(msg.length - r, msg.length);
  36375. if (this.pending.length === 0) this.pending = null;
  36376. msg = utils.join32(msg, 0, msg.length - r, this.endian);
  36377. for (var i = 0; i < msg.length; i += this._delta32) this._update(msg, i, i + this._delta32);
  36378. }
  36379. return this;
  36380. };
  36381. BlockHash.prototype.digest = function digest(enc) {
  36382. this.update(this._pad());
  36383. assert(this.pending === null);
  36384. return this._digest(enc);
  36385. };
  36386. BlockHash.prototype._pad = function pad() {
  36387. var len = this.pendingTotal;
  36388. var bytes = this._delta8;
  36389. var k = bytes - (len + this.padLength) % bytes;
  36390. var res = new Array(k + this.padLength);
  36391. res[0] = 0x80;
  36392. for (var i = 1; i < k; i++) res[i] = 0;
  36393. // Append length
  36394. len <<= 3;
  36395. if (this.endian === 'big') {
  36396. for (var t = 8; t < this.padLength; t++) res[i++] = 0;
  36397. res[i++] = 0;
  36398. res[i++] = 0;
  36399. res[i++] = 0;
  36400. res[i++] = 0;
  36401. res[i++] = len >>> 24 & 0xff;
  36402. res[i++] = len >>> 16 & 0xff;
  36403. res[i++] = len >>> 8 & 0xff;
  36404. res[i++] = len & 0xff;
  36405. } else {
  36406. res[i++] = len & 0xff;
  36407. res[i++] = len >>> 8 & 0xff;
  36408. res[i++] = len >>> 16 & 0xff;
  36409. res[i++] = len >>> 24 & 0xff;
  36410. res[i++] = 0;
  36411. res[i++] = 0;
  36412. res[i++] = 0;
  36413. res[i++] = 0;
  36414. for (t = 8; t < this.padLength; t++) res[i++] = 0;
  36415. }
  36416. return res;
  36417. };
  36418. },{"./utils":437,"minimalistic-assert":453}],428:[function(require,module,exports){
  36419. 'use strict';
  36420. var utils = require('./utils');
  36421. var assert = require('minimalistic-assert');
  36422. function Hmac(hash, key, enc) {
  36423. if (!(this instanceof Hmac)) return new Hmac(hash, key, enc);
  36424. this.Hash = hash;
  36425. this.blockSize = hash.blockSize / 8;
  36426. this.outSize = hash.outSize / 8;
  36427. this.inner = null;
  36428. this.outer = null;
  36429. this._init(utils.toArray(key, enc));
  36430. }
  36431. module.exports = Hmac;
  36432. Hmac.prototype._init = function init(key) {
  36433. // Shorten key, if needed
  36434. if (key.length > this.blockSize) key = new this.Hash().update(key).digest();
  36435. assert(key.length <= this.blockSize);
  36436. // Add padding to key
  36437. for (var i = key.length; i < this.blockSize; i++) key.push(0);
  36438. for (i = 0; i < key.length; i++) key[i] ^= 0x36;
  36439. this.inner = new this.Hash().update(key);
  36440. // 0x36 ^ 0x5c = 0x6a
  36441. for (i = 0; i < key.length; i++) key[i] ^= 0x6a;
  36442. this.outer = new this.Hash().update(key);
  36443. };
  36444. Hmac.prototype.update = function update(msg, enc) {
  36445. this.inner.update(msg, enc);
  36446. return this;
  36447. };
  36448. Hmac.prototype.digest = function digest(enc) {
  36449. this.outer.update(this.inner.digest());
  36450. return this.outer.digest(enc);
  36451. };
  36452. },{"./utils":437,"minimalistic-assert":453}],429:[function(require,module,exports){
  36453. 'use strict';
  36454. var utils = require('./utils');
  36455. var common = require('./common');
  36456. var rotl32 = utils.rotl32;
  36457. var sum32 = utils.sum32;
  36458. var sum32_3 = utils.sum32_3;
  36459. var sum32_4 = utils.sum32_4;
  36460. var BlockHash = common.BlockHash;
  36461. function RIPEMD160() {
  36462. if (!(this instanceof RIPEMD160)) return new RIPEMD160();
  36463. BlockHash.call(this);
  36464. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  36465. this.endian = 'little';
  36466. }
  36467. utils.inherits(RIPEMD160, BlockHash);
  36468. exports.ripemd160 = RIPEMD160;
  36469. RIPEMD160.blockSize = 512;
  36470. RIPEMD160.outSize = 160;
  36471. RIPEMD160.hmacStrength = 192;
  36472. RIPEMD160.padLength = 64;
  36473. RIPEMD160.prototype._update = function update(msg, start) {
  36474. var A = this.h[0];
  36475. var B = this.h[1];
  36476. var C = this.h[2];
  36477. var D = this.h[3];
  36478. var E = this.h[4];
  36479. var Ah = A;
  36480. var Bh = B;
  36481. var Ch = C;
  36482. var Dh = D;
  36483. var Eh = E;
  36484. for (var j = 0; j < 80; j++) {
  36485. var T = sum32(rotl32(sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E);
  36486. A = E;
  36487. E = D;
  36488. D = rotl32(C, 10);
  36489. C = B;
  36490. B = T;
  36491. T = sum32(rotl32(sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), sh[j]), Eh);
  36492. Ah = Eh;
  36493. Eh = Dh;
  36494. Dh = rotl32(Ch, 10);
  36495. Ch = Bh;
  36496. Bh = T;
  36497. }
  36498. T = sum32_3(this.h[1], C, Dh);
  36499. this.h[1] = sum32_3(this.h[2], D, Eh);
  36500. this.h[2] = sum32_3(this.h[3], E, Ah);
  36501. this.h[3] = sum32_3(this.h[4], A, Bh);
  36502. this.h[4] = sum32_3(this.h[0], B, Ch);
  36503. this.h[0] = T;
  36504. };
  36505. RIPEMD160.prototype._digest = function digest(enc) {
  36506. if (enc === 'hex') return utils.toHex32(this.h, 'little');else return utils.split32(this.h, 'little');
  36507. };
  36508. function f(j, x, y, z) {
  36509. if (j <= 15) return x ^ y ^ z;else if (j <= 31) return x & y | ~x & z;else if (j <= 47) return (x | ~y) ^ z;else if (j <= 63) return x & z | y & ~z;else return x ^ (y | ~z);
  36510. }
  36511. function K(j) {
  36512. if (j <= 15) return 0x00000000;else if (j <= 31) return 0x5a827999;else if (j <= 47) return 0x6ed9eba1;else if (j <= 63) return 0x8f1bbcdc;else return 0xa953fd4e;
  36513. }
  36514. function Kh(j) {
  36515. if (j <= 15) return 0x50a28be6;else if (j <= 31) return 0x5c4dd124;else if (j <= 47) return 0x6d703ef3;else if (j <= 63) return 0x7a6d76e9;else return 0x00000000;
  36516. }
  36517. var r = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13];
  36518. var rh = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11];
  36519. var s = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6];
  36520. var sh = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11];
  36521. },{"./common":427,"./utils":437}],430:[function(require,module,exports){
  36522. 'use strict';
  36523. exports.sha1 = require('./sha/1');
  36524. exports.sha224 = require('./sha/224');
  36525. exports.sha256 = require('./sha/256');
  36526. exports.sha384 = require('./sha/384');
  36527. exports.sha512 = require('./sha/512');
  36528. },{"./sha/1":431,"./sha/224":432,"./sha/256":433,"./sha/384":434,"./sha/512":435}],431:[function(require,module,exports){
  36529. 'use strict';
  36530. var utils = require('../utils');
  36531. var common = require('../common');
  36532. var shaCommon = require('./common');
  36533. var rotl32 = utils.rotl32;
  36534. var sum32 = utils.sum32;
  36535. var sum32_5 = utils.sum32_5;
  36536. var ft_1 = shaCommon.ft_1;
  36537. var BlockHash = common.BlockHash;
  36538. var sha1_K = [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6];
  36539. function SHA1() {
  36540. if (!(this instanceof SHA1)) return new SHA1();
  36541. BlockHash.call(this);
  36542. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  36543. this.W = new Array(80);
  36544. }
  36545. utils.inherits(SHA1, BlockHash);
  36546. module.exports = SHA1;
  36547. SHA1.blockSize = 512;
  36548. SHA1.outSize = 160;
  36549. SHA1.hmacStrength = 80;
  36550. SHA1.padLength = 64;
  36551. SHA1.prototype._update = function _update(msg, start) {
  36552. var W = this.W;
  36553. for (var i = 0; i < 16; i++) W[i] = msg[start + i];
  36554. for (; i < W.length; i++) W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  36555. var a = this.h[0];
  36556. var b = this.h[1];
  36557. var c = this.h[2];
  36558. var d = this.h[3];
  36559. var e = this.h[4];
  36560. for (i = 0; i < W.length; i++) {
  36561. var s = ~~(i / 20);
  36562. var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
  36563. e = d;
  36564. d = c;
  36565. c = rotl32(b, 30);
  36566. b = a;
  36567. a = t;
  36568. }
  36569. this.h[0] = sum32(this.h[0], a);
  36570. this.h[1] = sum32(this.h[1], b);
  36571. this.h[2] = sum32(this.h[2], c);
  36572. this.h[3] = sum32(this.h[3], d);
  36573. this.h[4] = sum32(this.h[4], e);
  36574. };
  36575. SHA1.prototype._digest = function digest(enc) {
  36576. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  36577. };
  36578. },{"../common":427,"../utils":437,"./common":436}],432:[function(require,module,exports){
  36579. 'use strict';
  36580. var utils = require('../utils');
  36581. var SHA256 = require('./256');
  36582. function SHA224() {
  36583. if (!(this instanceof SHA224)) return new SHA224();
  36584. SHA256.call(this);
  36585. this.h = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];
  36586. }
  36587. utils.inherits(SHA224, SHA256);
  36588. module.exports = SHA224;
  36589. SHA224.blockSize = 512;
  36590. SHA224.outSize = 224;
  36591. SHA224.hmacStrength = 192;
  36592. SHA224.padLength = 64;
  36593. SHA224.prototype._digest = function digest(enc) {
  36594. // Just truncate output
  36595. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 7), 'big');else return utils.split32(this.h.slice(0, 7), 'big');
  36596. };
  36597. },{"../utils":437,"./256":433}],433:[function(require,module,exports){
  36598. 'use strict';
  36599. var utils = require('../utils');
  36600. var common = require('../common');
  36601. var shaCommon = require('./common');
  36602. var assert = require('minimalistic-assert');
  36603. var sum32 = utils.sum32;
  36604. var sum32_4 = utils.sum32_4;
  36605. var sum32_5 = utils.sum32_5;
  36606. var ch32 = shaCommon.ch32;
  36607. var maj32 = shaCommon.maj32;
  36608. var s0_256 = shaCommon.s0_256;
  36609. var s1_256 = shaCommon.s1_256;
  36610. var g0_256 = shaCommon.g0_256;
  36611. var g1_256 = shaCommon.g1_256;
  36612. var BlockHash = common.BlockHash;
  36613. var sha256_K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  36614. function SHA256() {
  36615. if (!(this instanceof SHA256)) return new SHA256();
  36616. BlockHash.call(this);
  36617. this.h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  36618. this.k = sha256_K;
  36619. this.W = new Array(64);
  36620. }
  36621. utils.inherits(SHA256, BlockHash);
  36622. module.exports = SHA256;
  36623. SHA256.blockSize = 512;
  36624. SHA256.outSize = 256;
  36625. SHA256.hmacStrength = 192;
  36626. SHA256.padLength = 64;
  36627. SHA256.prototype._update = function _update(msg, start) {
  36628. var W = this.W;
  36629. for (var i = 0; i < 16; i++) W[i] = msg[start + i];
  36630. for (; i < W.length; i++) W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
  36631. var a = this.h[0];
  36632. var b = this.h[1];
  36633. var c = this.h[2];
  36634. var d = this.h[3];
  36635. var e = this.h[4];
  36636. var f = this.h[5];
  36637. var g = this.h[6];
  36638. var h = this.h[7];
  36639. assert(this.k.length === W.length);
  36640. for (i = 0; i < W.length; i++) {
  36641. var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
  36642. var T2 = sum32(s0_256(a), maj32(a, b, c));
  36643. h = g;
  36644. g = f;
  36645. f = e;
  36646. e = sum32(d, T1);
  36647. d = c;
  36648. c = b;
  36649. b = a;
  36650. a = sum32(T1, T2);
  36651. }
  36652. this.h[0] = sum32(this.h[0], a);
  36653. this.h[1] = sum32(this.h[1], b);
  36654. this.h[2] = sum32(this.h[2], c);
  36655. this.h[3] = sum32(this.h[3], d);
  36656. this.h[4] = sum32(this.h[4], e);
  36657. this.h[5] = sum32(this.h[5], f);
  36658. this.h[6] = sum32(this.h[6], g);
  36659. this.h[7] = sum32(this.h[7], h);
  36660. };
  36661. SHA256.prototype._digest = function digest(enc) {
  36662. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  36663. };
  36664. },{"../common":427,"../utils":437,"./common":436,"minimalistic-assert":453}],434:[function(require,module,exports){
  36665. 'use strict';
  36666. var utils = require('../utils');
  36667. var SHA512 = require('./512');
  36668. function SHA384() {
  36669. if (!(this instanceof SHA384)) return new SHA384();
  36670. SHA512.call(this);
  36671. this.h = [0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939, 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4];
  36672. }
  36673. utils.inherits(SHA384, SHA512);
  36674. module.exports = SHA384;
  36675. SHA384.blockSize = 1024;
  36676. SHA384.outSize = 384;
  36677. SHA384.hmacStrength = 192;
  36678. SHA384.padLength = 128;
  36679. SHA384.prototype._digest = function digest(enc) {
  36680. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 12), 'big');else return utils.split32(this.h.slice(0, 12), 'big');
  36681. };
  36682. },{"../utils":437,"./512":435}],435:[function(require,module,exports){
  36683. 'use strict';
  36684. var utils = require('../utils');
  36685. var common = require('../common');
  36686. var assert = require('minimalistic-assert');
  36687. var rotr64_hi = utils.rotr64_hi;
  36688. var rotr64_lo = utils.rotr64_lo;
  36689. var shr64_hi = utils.shr64_hi;
  36690. var shr64_lo = utils.shr64_lo;
  36691. var sum64 = utils.sum64;
  36692. var sum64_hi = utils.sum64_hi;
  36693. var sum64_lo = utils.sum64_lo;
  36694. var sum64_4_hi = utils.sum64_4_hi;
  36695. var sum64_4_lo = utils.sum64_4_lo;
  36696. var sum64_5_hi = utils.sum64_5_hi;
  36697. var sum64_5_lo = utils.sum64_5_lo;
  36698. var BlockHash = common.BlockHash;
  36699. var sha512_K = [0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817];
  36700. function SHA512() {
  36701. if (!(this instanceof SHA512)) return new SHA512();
  36702. BlockHash.call(this);
  36703. this.h = [0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179];
  36704. this.k = sha512_K;
  36705. this.W = new Array(160);
  36706. }
  36707. utils.inherits(SHA512, BlockHash);
  36708. module.exports = SHA512;
  36709. SHA512.blockSize = 1024;
  36710. SHA512.outSize = 512;
  36711. SHA512.hmacStrength = 192;
  36712. SHA512.padLength = 128;
  36713. SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
  36714. var W = this.W;
  36715. // 32 x 32bit words
  36716. for (var i = 0; i < 32; i++) W[i] = msg[start + i];
  36717. for (; i < W.length; i += 2) {
  36718. var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
  36719. var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
  36720. var c1_hi = W[i - 14]; // i - 7
  36721. var c1_lo = W[i - 13];
  36722. var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
  36723. var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
  36724. var c3_hi = W[i - 32]; // i - 16
  36725. var c3_lo = W[i - 31];
  36726. W[i] = sum64_4_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  36727. W[i + 1] = sum64_4_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  36728. }
  36729. };
  36730. SHA512.prototype._update = function _update(msg, start) {
  36731. this._prepareBlock(msg, start);
  36732. var W = this.W;
  36733. var ah = this.h[0];
  36734. var al = this.h[1];
  36735. var bh = this.h[2];
  36736. var bl = this.h[3];
  36737. var ch = this.h[4];
  36738. var cl = this.h[5];
  36739. var dh = this.h[6];
  36740. var dl = this.h[7];
  36741. var eh = this.h[8];
  36742. var el = this.h[9];
  36743. var fh = this.h[10];
  36744. var fl = this.h[11];
  36745. var gh = this.h[12];
  36746. var gl = this.h[13];
  36747. var hh = this.h[14];
  36748. var hl = this.h[15];
  36749. assert(this.k.length === W.length);
  36750. for (var i = 0; i < W.length; i += 2) {
  36751. var c0_hi = hh;
  36752. var c0_lo = hl;
  36753. var c1_hi = s1_512_hi(eh, el);
  36754. var c1_lo = s1_512_lo(eh, el);
  36755. var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
  36756. var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
  36757. var c3_hi = this.k[i];
  36758. var c3_lo = this.k[i + 1];
  36759. var c4_hi = W[i];
  36760. var c4_lo = W[i + 1];
  36761. var T1_hi = sum64_5_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo);
  36762. var T1_lo = sum64_5_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo);
  36763. c0_hi = s0_512_hi(ah, al);
  36764. c0_lo = s0_512_lo(ah, al);
  36765. c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
  36766. c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
  36767. var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
  36768. var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
  36769. hh = gh;
  36770. hl = gl;
  36771. gh = fh;
  36772. gl = fl;
  36773. fh = eh;
  36774. fl = el;
  36775. eh = sum64_hi(dh, dl, T1_hi, T1_lo);
  36776. el = sum64_lo(dl, dl, T1_hi, T1_lo);
  36777. dh = ch;
  36778. dl = cl;
  36779. ch = bh;
  36780. cl = bl;
  36781. bh = ah;
  36782. bl = al;
  36783. ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
  36784. al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
  36785. }
  36786. sum64(this.h, 0, ah, al);
  36787. sum64(this.h, 2, bh, bl);
  36788. sum64(this.h, 4, ch, cl);
  36789. sum64(this.h, 6, dh, dl);
  36790. sum64(this.h, 8, eh, el);
  36791. sum64(this.h, 10, fh, fl);
  36792. sum64(this.h, 12, gh, gl);
  36793. sum64(this.h, 14, hh, hl);
  36794. };
  36795. SHA512.prototype._digest = function digest(enc) {
  36796. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  36797. };
  36798. function ch64_hi(xh, xl, yh, yl, zh) {
  36799. var r = xh & yh ^ ~xh & zh;
  36800. if (r < 0) r += 0x100000000;
  36801. return r;
  36802. }
  36803. function ch64_lo(xh, xl, yh, yl, zh, zl) {
  36804. var r = xl & yl ^ ~xl & zl;
  36805. if (r < 0) r += 0x100000000;
  36806. return r;
  36807. }
  36808. function maj64_hi(xh, xl, yh, yl, zh) {
  36809. var r = xh & yh ^ xh & zh ^ yh & zh;
  36810. if (r < 0) r += 0x100000000;
  36811. return r;
  36812. }
  36813. function maj64_lo(xh, xl, yh, yl, zh, zl) {
  36814. var r = xl & yl ^ xl & zl ^ yl & zl;
  36815. if (r < 0) r += 0x100000000;
  36816. return r;
  36817. }
  36818. function s0_512_hi(xh, xl) {
  36819. var c0_hi = rotr64_hi(xh, xl, 28);
  36820. var c1_hi = rotr64_hi(xl, xh, 2); // 34
  36821. var c2_hi = rotr64_hi(xl, xh, 7); // 39
  36822. var r = c0_hi ^ c1_hi ^ c2_hi;
  36823. if (r < 0) r += 0x100000000;
  36824. return r;
  36825. }
  36826. function s0_512_lo(xh, xl) {
  36827. var c0_lo = rotr64_lo(xh, xl, 28);
  36828. var c1_lo = rotr64_lo(xl, xh, 2); // 34
  36829. var c2_lo = rotr64_lo(xl, xh, 7); // 39
  36830. var r = c0_lo ^ c1_lo ^ c2_lo;
  36831. if (r < 0) r += 0x100000000;
  36832. return r;
  36833. }
  36834. function s1_512_hi(xh, xl) {
  36835. var c0_hi = rotr64_hi(xh, xl, 14);
  36836. var c1_hi = rotr64_hi(xh, xl, 18);
  36837. var c2_hi = rotr64_hi(xl, xh, 9); // 41
  36838. var r = c0_hi ^ c1_hi ^ c2_hi;
  36839. if (r < 0) r += 0x100000000;
  36840. return r;
  36841. }
  36842. function s1_512_lo(xh, xl) {
  36843. var c0_lo = rotr64_lo(xh, xl, 14);
  36844. var c1_lo = rotr64_lo(xh, xl, 18);
  36845. var c2_lo = rotr64_lo(xl, xh, 9); // 41
  36846. var r = c0_lo ^ c1_lo ^ c2_lo;
  36847. if (r < 0) r += 0x100000000;
  36848. return r;
  36849. }
  36850. function g0_512_hi(xh, xl) {
  36851. var c0_hi = rotr64_hi(xh, xl, 1);
  36852. var c1_hi = rotr64_hi(xh, xl, 8);
  36853. var c2_hi = shr64_hi(xh, xl, 7);
  36854. var r = c0_hi ^ c1_hi ^ c2_hi;
  36855. if (r < 0) r += 0x100000000;
  36856. return r;
  36857. }
  36858. function g0_512_lo(xh, xl) {
  36859. var c0_lo = rotr64_lo(xh, xl, 1);
  36860. var c1_lo = rotr64_lo(xh, xl, 8);
  36861. var c2_lo = shr64_lo(xh, xl, 7);
  36862. var r = c0_lo ^ c1_lo ^ c2_lo;
  36863. if (r < 0) r += 0x100000000;
  36864. return r;
  36865. }
  36866. function g1_512_hi(xh, xl) {
  36867. var c0_hi = rotr64_hi(xh, xl, 19);
  36868. var c1_hi = rotr64_hi(xl, xh, 29); // 61
  36869. var c2_hi = shr64_hi(xh, xl, 6);
  36870. var r = c0_hi ^ c1_hi ^ c2_hi;
  36871. if (r < 0) r += 0x100000000;
  36872. return r;
  36873. }
  36874. function g1_512_lo(xh, xl) {
  36875. var c0_lo = rotr64_lo(xh, xl, 19);
  36876. var c1_lo = rotr64_lo(xl, xh, 29); // 61
  36877. var c2_lo = shr64_lo(xh, xl, 6);
  36878. var r = c0_lo ^ c1_lo ^ c2_lo;
  36879. if (r < 0) r += 0x100000000;
  36880. return r;
  36881. }
  36882. },{"../common":427,"../utils":437,"minimalistic-assert":453}],436:[function(require,module,exports){
  36883. 'use strict';
  36884. var utils = require('../utils');
  36885. var rotr32 = utils.rotr32;
  36886. function ft_1(s, x, y, z) {
  36887. if (s === 0) return ch32(x, y, z);
  36888. if (s === 1 || s === 3) return p32(x, y, z);
  36889. if (s === 2) return maj32(x, y, z);
  36890. }
  36891. exports.ft_1 = ft_1;
  36892. function ch32(x, y, z) {
  36893. return x & y ^ ~x & z;
  36894. }
  36895. exports.ch32 = ch32;
  36896. function maj32(x, y, z) {
  36897. return x & y ^ x & z ^ y & z;
  36898. }
  36899. exports.maj32 = maj32;
  36900. function p32(x, y, z) {
  36901. return x ^ y ^ z;
  36902. }
  36903. exports.p32 = p32;
  36904. function s0_256(x) {
  36905. return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
  36906. }
  36907. exports.s0_256 = s0_256;
  36908. function s1_256(x) {
  36909. return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
  36910. }
  36911. exports.s1_256 = s1_256;
  36912. function g0_256(x) {
  36913. return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
  36914. }
  36915. exports.g0_256 = g0_256;
  36916. function g1_256(x) {
  36917. return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10;
  36918. }
  36919. exports.g1_256 = g1_256;
  36920. },{"../utils":437}],437:[function(require,module,exports){
  36921. 'use strict';
  36922. var assert = require('minimalistic-assert');
  36923. var inherits = require('inherits');
  36924. exports.inherits = inherits;
  36925. function isSurrogatePair(msg, i) {
  36926. if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
  36927. return false;
  36928. }
  36929. if (i < 0 || i + 1 >= msg.length) {
  36930. return false;
  36931. }
  36932. return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
  36933. }
  36934. function toArray(msg, enc) {
  36935. if (Array.isArray(msg)) return msg.slice();
  36936. if (!msg) return [];
  36937. var res = [];
  36938. if (typeof msg === 'string') {
  36939. if (!enc) {
  36940. // Inspired by stringToUtf8ByteArray() in closure-library by Google
  36941. // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
  36942. // Apache License 2.0
  36943. // https://github.com/google/closure-library/blob/master/LICENSE
  36944. var p = 0;
  36945. for (var i = 0; i < msg.length; i++) {
  36946. var c = msg.charCodeAt(i);
  36947. if (c < 128) {
  36948. res[p++] = c;
  36949. } else if (c < 2048) {
  36950. res[p++] = c >> 6 | 192;
  36951. res[p++] = c & 63 | 128;
  36952. } else if (isSurrogatePair(msg, i)) {
  36953. c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
  36954. res[p++] = c >> 18 | 240;
  36955. res[p++] = c >> 12 & 63 | 128;
  36956. res[p++] = c >> 6 & 63 | 128;
  36957. res[p++] = c & 63 | 128;
  36958. } else {
  36959. res[p++] = c >> 12 | 224;
  36960. res[p++] = c >> 6 & 63 | 128;
  36961. res[p++] = c & 63 | 128;
  36962. }
  36963. }
  36964. } else if (enc === 'hex') {
  36965. msg = msg.replace(/[^a-z0-9]+/ig, '');
  36966. if (msg.length % 2 !== 0) msg = '0' + msg;
  36967. for (i = 0; i < msg.length; i += 2) res.push(parseInt(msg[i] + msg[i + 1], 16));
  36968. }
  36969. } else {
  36970. for (i = 0; i < msg.length; i++) res[i] = msg[i] | 0;
  36971. }
  36972. return res;
  36973. }
  36974. exports.toArray = toArray;
  36975. function toHex(msg) {
  36976. var res = '';
  36977. for (var i = 0; i < msg.length; i++) res += zero2(msg[i].toString(16));
  36978. return res;
  36979. }
  36980. exports.toHex = toHex;
  36981. function htonl(w) {
  36982. var res = w >>> 24 | w >>> 8 & 0xff00 | w << 8 & 0xff0000 | (w & 0xff) << 24;
  36983. return res >>> 0;
  36984. }
  36985. exports.htonl = htonl;
  36986. function toHex32(msg, endian) {
  36987. var res = '';
  36988. for (var i = 0; i < msg.length; i++) {
  36989. var w = msg[i];
  36990. if (endian === 'little') w = htonl(w);
  36991. res += zero8(w.toString(16));
  36992. }
  36993. return res;
  36994. }
  36995. exports.toHex32 = toHex32;
  36996. function zero2(word) {
  36997. if (word.length === 1) return '0' + word;else return word;
  36998. }
  36999. exports.zero2 = zero2;
  37000. function zero8(word) {
  37001. if (word.length === 7) return '0' + word;else if (word.length === 6) return '00' + word;else if (word.length === 5) return '000' + word;else if (word.length === 4) return '0000' + word;else if (word.length === 3) return '00000' + word;else if (word.length === 2) return '000000' + word;else if (word.length === 1) return '0000000' + word;else return word;
  37002. }
  37003. exports.zero8 = zero8;
  37004. function join32(msg, start, end, endian) {
  37005. var len = end - start;
  37006. assert(len % 4 === 0);
  37007. var res = new Array(len / 4);
  37008. for (var i = 0, k = start; i < res.length; i++, k += 4) {
  37009. var w;
  37010. if (endian === 'big') w = msg[k] << 24 | msg[k + 1] << 16 | msg[k + 2] << 8 | msg[k + 3];else w = msg[k + 3] << 24 | msg[k + 2] << 16 | msg[k + 1] << 8 | msg[k];
  37011. res[i] = w >>> 0;
  37012. }
  37013. return res;
  37014. }
  37015. exports.join32 = join32;
  37016. function split32(msg, endian) {
  37017. var res = new Array(msg.length * 4);
  37018. for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
  37019. var m = msg[i];
  37020. if (endian === 'big') {
  37021. res[k] = m >>> 24;
  37022. res[k + 1] = m >>> 16 & 0xff;
  37023. res[k + 2] = m >>> 8 & 0xff;
  37024. res[k + 3] = m & 0xff;
  37025. } else {
  37026. res[k + 3] = m >>> 24;
  37027. res[k + 2] = m >>> 16 & 0xff;
  37028. res[k + 1] = m >>> 8 & 0xff;
  37029. res[k] = m & 0xff;
  37030. }
  37031. }
  37032. return res;
  37033. }
  37034. exports.split32 = split32;
  37035. function rotr32(w, b) {
  37036. return w >>> b | w << 32 - b;
  37037. }
  37038. exports.rotr32 = rotr32;
  37039. function rotl32(w, b) {
  37040. return w << b | w >>> 32 - b;
  37041. }
  37042. exports.rotl32 = rotl32;
  37043. function sum32(a, b) {
  37044. return a + b >>> 0;
  37045. }
  37046. exports.sum32 = sum32;
  37047. function sum32_3(a, b, c) {
  37048. return a + b + c >>> 0;
  37049. }
  37050. exports.sum32_3 = sum32_3;
  37051. function sum32_4(a, b, c, d) {
  37052. return a + b + c + d >>> 0;
  37053. }
  37054. exports.sum32_4 = sum32_4;
  37055. function sum32_5(a, b, c, d, e) {
  37056. return a + b + c + d + e >>> 0;
  37057. }
  37058. exports.sum32_5 = sum32_5;
  37059. function sum64(buf, pos, ah, al) {
  37060. var bh = buf[pos];
  37061. var bl = buf[pos + 1];
  37062. var lo = al + bl >>> 0;
  37063. var hi = (lo < al ? 1 : 0) + ah + bh;
  37064. buf[pos] = hi >>> 0;
  37065. buf[pos + 1] = lo;
  37066. }
  37067. exports.sum64 = sum64;
  37068. function sum64_hi(ah, al, bh, bl) {
  37069. var lo = al + bl >>> 0;
  37070. var hi = (lo < al ? 1 : 0) + ah + bh;
  37071. return hi >>> 0;
  37072. }
  37073. exports.sum64_hi = sum64_hi;
  37074. function sum64_lo(ah, al, bh, bl) {
  37075. var lo = al + bl;
  37076. return lo >>> 0;
  37077. }
  37078. exports.sum64_lo = sum64_lo;
  37079. function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
  37080. var carry = 0;
  37081. var lo = al;
  37082. lo = lo + bl >>> 0;
  37083. carry += lo < al ? 1 : 0;
  37084. lo = lo + cl >>> 0;
  37085. carry += lo < cl ? 1 : 0;
  37086. lo = lo + dl >>> 0;
  37087. carry += lo < dl ? 1 : 0;
  37088. var hi = ah + bh + ch + dh + carry;
  37089. return hi >>> 0;
  37090. }
  37091. exports.sum64_4_hi = sum64_4_hi;
  37092. function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
  37093. var lo = al + bl + cl + dl;
  37094. return lo >>> 0;
  37095. }
  37096. exports.sum64_4_lo = sum64_4_lo;
  37097. function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  37098. var carry = 0;
  37099. var lo = al;
  37100. lo = lo + bl >>> 0;
  37101. carry += lo < al ? 1 : 0;
  37102. lo = lo + cl >>> 0;
  37103. carry += lo < cl ? 1 : 0;
  37104. lo = lo + dl >>> 0;
  37105. carry += lo < dl ? 1 : 0;
  37106. lo = lo + el >>> 0;
  37107. carry += lo < el ? 1 : 0;
  37108. var hi = ah + bh + ch + dh + eh + carry;
  37109. return hi >>> 0;
  37110. }
  37111. exports.sum64_5_hi = sum64_5_hi;
  37112. function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  37113. var lo = al + bl + cl + dl + el;
  37114. return lo >>> 0;
  37115. }
  37116. exports.sum64_5_lo = sum64_5_lo;
  37117. function rotr64_hi(ah, al, num) {
  37118. var r = al << 32 - num | ah >>> num;
  37119. return r >>> 0;
  37120. }
  37121. exports.rotr64_hi = rotr64_hi;
  37122. function rotr64_lo(ah, al, num) {
  37123. var r = ah << 32 - num | al >>> num;
  37124. return r >>> 0;
  37125. }
  37126. exports.rotr64_lo = rotr64_lo;
  37127. function shr64_hi(ah, al, num) {
  37128. return ah >>> num;
  37129. }
  37130. exports.shr64_hi = shr64_hi;
  37131. function shr64_lo(ah, al, num) {
  37132. var r = ah << 32 - num | al >>> num;
  37133. return r >>> 0;
  37134. }
  37135. exports.shr64_lo = shr64_lo;
  37136. },{"inherits":440,"minimalistic-assert":453}],438:[function(require,module,exports){
  37137. 'use strict';
  37138. var hash = require('hash.js');
  37139. var utils = require('minimalistic-crypto-utils');
  37140. var assert = require('minimalistic-assert');
  37141. function HmacDRBG(options) {
  37142. if (!(this instanceof HmacDRBG)) return new HmacDRBG(options);
  37143. this.hash = options.hash;
  37144. this.predResist = !!options.predResist;
  37145. this.outLen = this.hash.outSize;
  37146. this.minEntropy = options.minEntropy || this.hash.hmacStrength;
  37147. this._reseed = null;
  37148. this.reseedInterval = null;
  37149. this.K = null;
  37150. this.V = null;
  37151. var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
  37152. var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
  37153. var pers = utils.toArray(options.pers, options.persEnc || 'hex');
  37154. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  37155. this._init(entropy, nonce, pers);
  37156. }
  37157. module.exports = HmacDRBG;
  37158. HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
  37159. var seed = entropy.concat(nonce).concat(pers);
  37160. this.K = new Array(this.outLen / 8);
  37161. this.V = new Array(this.outLen / 8);
  37162. for (var i = 0; i < this.V.length; i++) {
  37163. this.K[i] = 0x00;
  37164. this.V[i] = 0x01;
  37165. }
  37166. this._update(seed);
  37167. this._reseed = 1;
  37168. this.reseedInterval = 0x1000000000000; // 2^48
  37169. };
  37170. HmacDRBG.prototype._hmac = function hmac() {
  37171. return new hash.hmac(this.hash, this.K);
  37172. };
  37173. HmacDRBG.prototype._update = function update(seed) {
  37174. var kmac = this._hmac().update(this.V).update([0x00]);
  37175. if (seed) kmac = kmac.update(seed);
  37176. this.K = kmac.digest();
  37177. this.V = this._hmac().update(this.V).digest();
  37178. if (!seed) return;
  37179. this.K = this._hmac().update(this.V).update([0x01]).update(seed).digest();
  37180. this.V = this._hmac().update(this.V).digest();
  37181. };
  37182. HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  37183. // Optional entropy enc
  37184. if (typeof entropyEnc !== 'string') {
  37185. addEnc = add;
  37186. add = entropyEnc;
  37187. entropyEnc = null;
  37188. }
  37189. entropy = utils.toArray(entropy, entropyEnc);
  37190. add = utils.toArray(add, addEnc);
  37191. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  37192. this._update(entropy.concat(add || []));
  37193. this._reseed = 1;
  37194. };
  37195. HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  37196. if (this._reseed > this.reseedInterval) throw new Error('Reseed is required');
  37197. // Optional encoding
  37198. if (typeof enc !== 'string') {
  37199. addEnc = add;
  37200. add = enc;
  37201. enc = null;
  37202. }
  37203. // Optional additional data
  37204. if (add) {
  37205. add = utils.toArray(add, addEnc || 'hex');
  37206. this._update(add);
  37207. }
  37208. var temp = [];
  37209. while (temp.length < len) {
  37210. this.V = this._hmac().update(this.V).digest();
  37211. temp = temp.concat(this.V);
  37212. }
  37213. var res = temp.slice(0, len);
  37214. this._update(add);
  37215. this._reseed++;
  37216. return utils.encode(res, enc);
  37217. };
  37218. },{"hash.js":426,"minimalistic-assert":453,"minimalistic-crypto-utils":454}],439:[function(require,module,exports){
  37219. "use strict";
  37220. /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
  37221. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  37222. var e, m;
  37223. var eLen = nBytes * 8 - mLen - 1;
  37224. var eMax = (1 << eLen) - 1;
  37225. var eBias = eMax >> 1;
  37226. var nBits = -7;
  37227. var i = isLE ? nBytes - 1 : 0;
  37228. var d = isLE ? -1 : 1;
  37229. var s = buffer[offset + i];
  37230. i += d;
  37231. e = s & (1 << -nBits) - 1;
  37232. s >>= -nBits;
  37233. nBits += eLen;
  37234. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  37235. m = e & (1 << -nBits) - 1;
  37236. e >>= -nBits;
  37237. nBits += mLen;
  37238. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  37239. if (e === 0) {
  37240. e = 1 - eBias;
  37241. } else if (e === eMax) {
  37242. return m ? NaN : (s ? -1 : 1) * Infinity;
  37243. } else {
  37244. m = m + Math.pow(2, mLen);
  37245. e = e - eBias;
  37246. }
  37247. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  37248. };
  37249. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  37250. var e, m, c;
  37251. var eLen = nBytes * 8 - mLen - 1;
  37252. var eMax = (1 << eLen) - 1;
  37253. var eBias = eMax >> 1;
  37254. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  37255. var i = isLE ? 0 : nBytes - 1;
  37256. var d = isLE ? 1 : -1;
  37257. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  37258. value = Math.abs(value);
  37259. if (isNaN(value) || value === Infinity) {
  37260. m = isNaN(value) ? 1 : 0;
  37261. e = eMax;
  37262. } else {
  37263. e = Math.floor(Math.log(value) / Math.LN2);
  37264. if (value * (c = Math.pow(2, -e)) < 1) {
  37265. e--;
  37266. c *= 2;
  37267. }
  37268. if (e + eBias >= 1) {
  37269. value += rt / c;
  37270. } else {
  37271. value += rt * Math.pow(2, 1 - eBias);
  37272. }
  37273. if (value * c >= 2) {
  37274. e++;
  37275. c /= 2;
  37276. }
  37277. if (e + eBias >= eMax) {
  37278. m = 0;
  37279. e = eMax;
  37280. } else if (e + eBias >= 1) {
  37281. m = (value * c - 1) * Math.pow(2, mLen);
  37282. e = e + eBias;
  37283. } else {
  37284. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  37285. e = 0;
  37286. }
  37287. }
  37288. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  37289. e = e << mLen | m;
  37290. eLen += mLen;
  37291. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  37292. buffer[offset + i - d] |= s * 128;
  37293. };
  37294. },{}],440:[function(require,module,exports){
  37295. "use strict";
  37296. if (typeof Object.create === 'function') {
  37297. // implementation from standard node.js 'util' module
  37298. module.exports = function inherits(ctor, superCtor) {
  37299. if (superCtor) {
  37300. ctor.super_ = superCtor;
  37301. ctor.prototype = Object.create(superCtor.prototype, {
  37302. constructor: {
  37303. value: ctor,
  37304. enumerable: false,
  37305. writable: true,
  37306. configurable: true
  37307. }
  37308. });
  37309. }
  37310. };
  37311. } else {
  37312. // old school shim for old browsers
  37313. module.exports = function inherits(ctor, superCtor) {
  37314. if (superCtor) {
  37315. ctor.super_ = superCtor;
  37316. var TempCtor = function () {};
  37317. TempCtor.prototype = superCtor.prototype;
  37318. ctor.prototype = new TempCtor();
  37319. ctor.prototype.constructor = ctor;
  37320. }
  37321. };
  37322. }
  37323. },{}],441:[function(require,module,exports){
  37324. (function (process,global,Buffer,__argument0,__argument1,__argument2,__argument3,setImmediate){(function (){
  37325. "use strict";
  37326. /*!
  37327. JSZip v3.10.1 - A JavaScript class for generating and reading zip files
  37328. <http://stuartk.com/jszip>
  37329. (c) 2009-2016 Stuart Knightley <stuart [at] stuartk.com>
  37330. Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/main/LICENSE.markdown.
  37331. JSZip uses the library pako released under the MIT license :
  37332. https://github.com/nodeca/pako/blob/main/LICENSE
  37333. */
  37334. !function (e) {
  37335. if ("object" == typeof exports && "undefined" != typeof module) module.exports = e();else if ("function" == typeof define && define.amd) define([], e);else {
  37336. ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).JSZip = e();
  37337. }
  37338. }(function () {
  37339. return function s(a, o, h) {
  37340. function u(r, e) {
  37341. if (!o[r]) {
  37342. if (!a[r]) {
  37343. var t = "function" == typeof require && require;
  37344. if (!e && t) return t(r, !0);
  37345. if (l) return l(r, !0);
  37346. var n = new Error("Cannot find module '" + r + "'");
  37347. throw n.code = "MODULE_NOT_FOUND", n;
  37348. }
  37349. var i = o[r] = {
  37350. exports: {}
  37351. };
  37352. a[r][0].call(i.exports, function (e) {
  37353. var t = a[r][1][e];
  37354. return u(t || e);
  37355. }, i, i.exports, s, a, o, h);
  37356. }
  37357. return o[r].exports;
  37358. }
  37359. for (var l = "function" == typeof require && require, e = 0; e < h.length; e++) u(h[e]);
  37360. return u;
  37361. }({
  37362. 1: [function (e, t, r) {
  37363. "use strict";
  37364. var d = e("./utils"),
  37365. c = e("./support"),
  37366. p = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  37367. r.encode = function (e) {
  37368. for (var t, r, n, i, s, a, o, h = [], u = 0, l = e.length, f = l, c = "string" !== d.getTypeOf(e); u < e.length;) f = l - u, n = c ? (t = e[u++], r = u < l ? e[u++] : 0, u < l ? e[u++] : 0) : (t = e.charCodeAt(u++), r = u < l ? e.charCodeAt(u++) : 0, u < l ? e.charCodeAt(u++) : 0), i = t >> 2, s = (3 & t) << 4 | r >> 4, a = 1 < f ? (15 & r) << 2 | n >> 6 : 64, o = 2 < f ? 63 & n : 64, h.push(p.charAt(i) + p.charAt(s) + p.charAt(a) + p.charAt(o));
  37369. return h.join("");
  37370. }, r.decode = function (e) {
  37371. var t,
  37372. r,
  37373. n,
  37374. i,
  37375. s,
  37376. a,
  37377. o = 0,
  37378. h = 0,
  37379. u = "data:";
  37380. if (e.substr(0, u.length) === u) throw new Error("Invalid base64 input, it looks like a data url.");
  37381. var l,
  37382. f = 3 * (e = e.replace(/[^A-Za-z0-9+/=]/g, "")).length / 4;
  37383. if (e.charAt(e.length - 1) === p.charAt(64) && f--, e.charAt(e.length - 2) === p.charAt(64) && f--, f % 1 != 0) throw new Error("Invalid base64 input, bad content length.");
  37384. for (l = c.uint8array ? new Uint8Array(0 | f) : new Array(0 | f); o < e.length;) t = p.indexOf(e.charAt(o++)) << 2 | (i = p.indexOf(e.charAt(o++))) >> 4, r = (15 & i) << 4 | (s = p.indexOf(e.charAt(o++))) >> 2, n = (3 & s) << 6 | (a = p.indexOf(e.charAt(o++))), l[h++] = t, 64 !== s && (l[h++] = r), 64 !== a && (l[h++] = n);
  37385. return l;
  37386. };
  37387. }, {
  37388. "./support": 30,
  37389. "./utils": 32
  37390. }],
  37391. 2: [function (e, t, r) {
  37392. "use strict";
  37393. var n = e("./external"),
  37394. i = e("./stream/DataWorker"),
  37395. s = e("./stream/Crc32Probe"),
  37396. a = e("./stream/DataLengthProbe");
  37397. function o(e, t, r, n, i) {
  37398. this.compressedSize = e, this.uncompressedSize = t, this.crc32 = r, this.compression = n, this.compressedContent = i;
  37399. }
  37400. o.prototype = {
  37401. getContentWorker: function () {
  37402. var e = new i(n.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new a("data_length")),
  37403. t = this;
  37404. return e.on("end", function () {
  37405. if (this.streamInfo.data_length !== t.uncompressedSize) throw new Error("Bug : uncompressed data size mismatch");
  37406. }), e;
  37407. },
  37408. getCompressedWorker: function () {
  37409. return new i(n.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize", this.compressedSize).withStreamInfo("uncompressedSize", this.uncompressedSize).withStreamInfo("crc32", this.crc32).withStreamInfo("compression", this.compression);
  37410. }
  37411. }, o.createWorkerFrom = function (e, t, r) {
  37412. return e.pipe(new s()).pipe(new a("uncompressedSize")).pipe(t.compressWorker(r)).pipe(new a("compressedSize")).withStreamInfo("compression", t);
  37413. }, t.exports = o;
  37414. }, {
  37415. "./external": 6,
  37416. "./stream/Crc32Probe": 25,
  37417. "./stream/DataLengthProbe": 26,
  37418. "./stream/DataWorker": 27
  37419. }],
  37420. 3: [function (e, t, r) {
  37421. "use strict";
  37422. var n = e("./stream/GenericWorker");
  37423. r.STORE = {
  37424. magic: "\0\0",
  37425. compressWorker: function () {
  37426. return new n("STORE compression");
  37427. },
  37428. uncompressWorker: function () {
  37429. return new n("STORE decompression");
  37430. }
  37431. }, r.DEFLATE = e("./flate");
  37432. }, {
  37433. "./flate": 7,
  37434. "./stream/GenericWorker": 28
  37435. }],
  37436. 4: [function (e, t, r) {
  37437. "use strict";
  37438. var n = e("./utils");
  37439. var o = function () {
  37440. for (var e, t = [], r = 0; r < 256; r++) {
  37441. e = r;
  37442. for (var n = 0; n < 8; n++) e = 1 & e ? 3988292384 ^ e >>> 1 : e >>> 1;
  37443. t[r] = e;
  37444. }
  37445. return t;
  37446. }();
  37447. t.exports = function (e, t) {
  37448. return void 0 !== e && e.length ? "string" !== n.getTypeOf(e) ? function (e, t, r, n) {
  37449. var i = o,
  37450. s = n + r;
  37451. e ^= -1;
  37452. for (var a = n; a < s; a++) e = e >>> 8 ^ i[255 & (e ^ t[a])];
  37453. return -1 ^ e;
  37454. }(0 | t, e, e.length, 0) : function (e, t, r, n) {
  37455. var i = o,
  37456. s = n + r;
  37457. e ^= -1;
  37458. for (var a = n; a < s; a++) e = e >>> 8 ^ i[255 & (e ^ t.charCodeAt(a))];
  37459. return -1 ^ e;
  37460. }(0 | t, e, e.length, 0) : 0;
  37461. };
  37462. }, {
  37463. "./utils": 32
  37464. }],
  37465. 5: [function (e, t, r) {
  37466. "use strict";
  37467. r.base64 = !1, r.binary = !1, r.dir = !1, r.createFolders = !0, r.date = null, r.compression = null, r.compressionOptions = null, r.comment = null, r.unixPermissions = null, r.dosPermissions = null;
  37468. }, {}],
  37469. 6: [function (e, t, r) {
  37470. "use strict";
  37471. var n = null;
  37472. n = "undefined" != typeof Promise ? Promise : e("lie"), t.exports = {
  37473. Promise: n
  37474. };
  37475. }, {
  37476. lie: 37
  37477. }],
  37478. 7: [function (e, t, r) {
  37479. "use strict";
  37480. var n = "undefined" != typeof Uint8Array && "undefined" != typeof Uint16Array && "undefined" != typeof Uint32Array,
  37481. i = e("pako"),
  37482. s = e("./utils"),
  37483. a = e("./stream/GenericWorker"),
  37484. o = n ? "uint8array" : "array";
  37485. function h(e, t) {
  37486. a.call(this, "FlateWorker/" + e), this._pako = null, this._pakoAction = e, this._pakoOptions = t, this.meta = {};
  37487. }
  37488. r.magic = "\b\0", s.inherits(h, a), h.prototype.processChunk = function (e) {
  37489. this.meta = e.meta, null === this._pako && this._createPako(), this._pako.push(s.transformTo(o, e.data), !1);
  37490. }, h.prototype.flush = function () {
  37491. a.prototype.flush.call(this), null === this._pako && this._createPako(), this._pako.push([], !0);
  37492. }, h.prototype.cleanUp = function () {
  37493. a.prototype.cleanUp.call(this), this._pako = null;
  37494. }, h.prototype._createPako = function () {
  37495. this._pako = new i[this._pakoAction]({
  37496. raw: !0,
  37497. level: this._pakoOptions.level || -1
  37498. });
  37499. var t = this;
  37500. this._pako.onData = function (e) {
  37501. t.push({
  37502. data: e,
  37503. meta: t.meta
  37504. });
  37505. };
  37506. }, r.compressWorker = function (e) {
  37507. return new h("Deflate", e);
  37508. }, r.uncompressWorker = function () {
  37509. return new h("Inflate", {});
  37510. };
  37511. }, {
  37512. "./stream/GenericWorker": 28,
  37513. "./utils": 32,
  37514. pako: 38
  37515. }],
  37516. 8: [function (e, t, r) {
  37517. "use strict";
  37518. function A(e, t) {
  37519. var r,
  37520. n = "";
  37521. for (r = 0; r < t; r++) n += String.fromCharCode(255 & e), e >>>= 8;
  37522. return n;
  37523. }
  37524. function n(e, t, r, n, i, s) {
  37525. var a,
  37526. o,
  37527. h = e.file,
  37528. u = e.compression,
  37529. l = s !== O.utf8encode,
  37530. f = I.transformTo("string", s(h.name)),
  37531. c = I.transformTo("string", O.utf8encode(h.name)),
  37532. d = h.comment,
  37533. p = I.transformTo("string", s(d)),
  37534. m = I.transformTo("string", O.utf8encode(d)),
  37535. _ = c.length !== h.name.length,
  37536. g = m.length !== d.length,
  37537. b = "",
  37538. v = "",
  37539. y = "",
  37540. w = h.dir,
  37541. k = h.date,
  37542. x = {
  37543. crc32: 0,
  37544. compressedSize: 0,
  37545. uncompressedSize: 0
  37546. };
  37547. t && !r || (x.crc32 = e.crc32, x.compressedSize = e.compressedSize, x.uncompressedSize = e.uncompressedSize);
  37548. var S = 0;
  37549. t && (S |= 8), l || !_ && !g || (S |= 2048);
  37550. var z = 0,
  37551. C = 0;
  37552. w && (z |= 16), "UNIX" === i ? (C = 798, z |= function (e, t) {
  37553. var r = e;
  37554. return e || (r = t ? 16893 : 33204), (65535 & r) << 16;
  37555. }(h.unixPermissions, w)) : (C = 20, z |= function (e) {
  37556. return 63 & (e || 0);
  37557. }(h.dosPermissions)), a = k.getUTCHours(), a <<= 6, a |= k.getUTCMinutes(), a <<= 5, a |= k.getUTCSeconds() / 2, o = k.getUTCFullYear() - 1980, o <<= 4, o |= k.getUTCMonth() + 1, o <<= 5, o |= k.getUTCDate(), _ && (v = A(1, 1) + A(B(f), 4) + c, b += "up" + A(v.length, 2) + v), g && (y = A(1, 1) + A(B(p), 4) + m, b += "uc" + A(y.length, 2) + y);
  37558. var E = "";
  37559. return E += "\n\0", E += A(S, 2), E += u.magic, E += A(a, 2), E += A(o, 2), E += A(x.crc32, 4), E += A(x.compressedSize, 4), E += A(x.uncompressedSize, 4), E += A(f.length, 2), E += A(b.length, 2), {
  37560. fileRecord: R.LOCAL_FILE_HEADER + E + f + b,
  37561. dirRecord: R.CENTRAL_FILE_HEADER + A(C, 2) + E + A(p.length, 2) + "\0\0\0\0" + A(z, 4) + A(n, 4) + f + b + p
  37562. };
  37563. }
  37564. var I = e("../utils"),
  37565. i = e("../stream/GenericWorker"),
  37566. O = e("../utf8"),
  37567. B = e("../crc32"),
  37568. R = e("../signature");
  37569. function s(e, t, r, n) {
  37570. i.call(this, "ZipFileWorker"), this.bytesWritten = 0, this.zipComment = t, this.zipPlatform = r, this.encodeFileName = n, this.streamFiles = e, this.accumulate = !1, this.contentBuffer = [], this.dirRecords = [], this.currentSourceOffset = 0, this.entriesCount = 0, this.currentFile = null, this._sources = [];
  37571. }
  37572. I.inherits(s, i), s.prototype.push = function (e) {
  37573. var t = e.meta.percent || 0,
  37574. r = this.entriesCount,
  37575. n = this._sources.length;
  37576. this.accumulate ? this.contentBuffer.push(e) : (this.bytesWritten += e.data.length, i.prototype.push.call(this, {
  37577. data: e.data,
  37578. meta: {
  37579. currentFile: this.currentFile,
  37580. percent: r ? (t + 100 * (r - n - 1)) / r : 100
  37581. }
  37582. }));
  37583. }, s.prototype.openedSource = function (e) {
  37584. this.currentSourceOffset = this.bytesWritten, this.currentFile = e.file.name;
  37585. var t = this.streamFiles && !e.file.dir;
  37586. if (t) {
  37587. var r = n(e, t, !1, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
  37588. this.push({
  37589. data: r.fileRecord,
  37590. meta: {
  37591. percent: 0
  37592. }
  37593. });
  37594. } else this.accumulate = !0;
  37595. }, s.prototype.closedSource = function (e) {
  37596. this.accumulate = !1;
  37597. var t = this.streamFiles && !e.file.dir,
  37598. r = n(e, t, !0, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
  37599. if (this.dirRecords.push(r.dirRecord), t) this.push({
  37600. data: function (e) {
  37601. return R.DATA_DESCRIPTOR + A(e.crc32, 4) + A(e.compressedSize, 4) + A(e.uncompressedSize, 4);
  37602. }(e),
  37603. meta: {
  37604. percent: 100
  37605. }
  37606. });else for (this.push({
  37607. data: r.fileRecord,
  37608. meta: {
  37609. percent: 0
  37610. }
  37611. }); this.contentBuffer.length;) this.push(this.contentBuffer.shift());
  37612. this.currentFile = null;
  37613. }, s.prototype.flush = function () {
  37614. for (var e = this.bytesWritten, t = 0; t < this.dirRecords.length; t++) this.push({
  37615. data: this.dirRecords[t],
  37616. meta: {
  37617. percent: 100
  37618. }
  37619. });
  37620. var r = this.bytesWritten - e,
  37621. n = function (e, t, r, n, i) {
  37622. var s = I.transformTo("string", i(n));
  37623. return R.CENTRAL_DIRECTORY_END + "\0\0\0\0" + A(e, 2) + A(e, 2) + A(t, 4) + A(r, 4) + A(s.length, 2) + s;
  37624. }(this.dirRecords.length, r, e, this.zipComment, this.encodeFileName);
  37625. this.push({
  37626. data: n,
  37627. meta: {
  37628. percent: 100
  37629. }
  37630. });
  37631. }, s.prototype.prepareNextSource = function () {
  37632. this.previous = this._sources.shift(), this.openedSource(this.previous.streamInfo), this.isPaused ? this.previous.pause() : this.previous.resume();
  37633. }, s.prototype.registerPrevious = function (e) {
  37634. this._sources.push(e);
  37635. var t = this;
  37636. return e.on("data", function (e) {
  37637. t.processChunk(e);
  37638. }), e.on("end", function () {
  37639. t.closedSource(t.previous.streamInfo), t._sources.length ? t.prepareNextSource() : t.end();
  37640. }), e.on("error", function (e) {
  37641. t.error(e);
  37642. }), this;
  37643. }, s.prototype.resume = function () {
  37644. return !!i.prototype.resume.call(this) && (!this.previous && this._sources.length ? (this.prepareNextSource(), !0) : this.previous || this._sources.length || this.generatedError ? void 0 : (this.end(), !0));
  37645. }, s.prototype.error = function (e) {
  37646. var t = this._sources;
  37647. if (!i.prototype.error.call(this, e)) return !1;
  37648. for (var r = 0; r < t.length; r++) try {
  37649. t[r].error(e);
  37650. } catch (e) {}
  37651. return !0;
  37652. }, s.prototype.lock = function () {
  37653. i.prototype.lock.call(this);
  37654. for (var e = this._sources, t = 0; t < e.length; t++) e[t].lock();
  37655. }, t.exports = s;
  37656. }, {
  37657. "../crc32": 4,
  37658. "../signature": 23,
  37659. "../stream/GenericWorker": 28,
  37660. "../utf8": 31,
  37661. "../utils": 32
  37662. }],
  37663. 9: [function (e, t, r) {
  37664. "use strict";
  37665. var u = e("../compressions"),
  37666. n = e("./ZipFileWorker");
  37667. r.generateWorker = function (e, a, t) {
  37668. var o = new n(a.streamFiles, t, a.platform, a.encodeFileName),
  37669. h = 0;
  37670. try {
  37671. e.forEach(function (e, t) {
  37672. h++;
  37673. var r = function (e, t) {
  37674. var r = e || t,
  37675. n = u[r];
  37676. if (!n) throw new Error(r + " is not a valid compression method !");
  37677. return n;
  37678. }(t.options.compression, a.compression),
  37679. n = t.options.compressionOptions || a.compressionOptions || {},
  37680. i = t.dir,
  37681. s = t.date;
  37682. t._compressWorker(r, n).withStreamInfo("file", {
  37683. name: e,
  37684. dir: i,
  37685. date: s,
  37686. comment: t.comment || "",
  37687. unixPermissions: t.unixPermissions,
  37688. dosPermissions: t.dosPermissions
  37689. }).pipe(o);
  37690. }), o.entriesCount = h;
  37691. } catch (e) {
  37692. o.error(e);
  37693. }
  37694. return o;
  37695. };
  37696. }, {
  37697. "../compressions": 3,
  37698. "./ZipFileWorker": 8
  37699. }],
  37700. 10: [function (e, t, r) {
  37701. "use strict";
  37702. function n() {
  37703. if (!(this instanceof n)) return new n();
  37704. if (arguments.length) throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
  37705. this.files = Object.create(null), this.comment = null, this.root = "", this.clone = function () {
  37706. var e = new n();
  37707. for (var t in this) "function" != typeof this[t] && (e[t] = this[t]);
  37708. return e;
  37709. };
  37710. }
  37711. (n.prototype = e("./object")).loadAsync = e("./load"), n.support = e("./support"), n.defaults = e("./defaults"), n.version = "3.10.1", n.loadAsync = function (e, t) {
  37712. return new n().loadAsync(e, t);
  37713. }, n.external = e("./external"), t.exports = n;
  37714. }, {
  37715. "./defaults": 5,
  37716. "./external": 6,
  37717. "./load": 11,
  37718. "./object": 15,
  37719. "./support": 30
  37720. }],
  37721. 11: [function (e, t, r) {
  37722. "use strict";
  37723. var u = e("./utils"),
  37724. i = e("./external"),
  37725. n = e("./utf8"),
  37726. s = e("./zipEntries"),
  37727. a = e("./stream/Crc32Probe"),
  37728. l = e("./nodejsUtils");
  37729. function f(n) {
  37730. return new i.Promise(function (e, t) {
  37731. var r = n.decompressed.getContentWorker().pipe(new a());
  37732. r.on("error", function (e) {
  37733. t(e);
  37734. }).on("end", function () {
  37735. r.streamInfo.crc32 !== n.decompressed.crc32 ? t(new Error("Corrupted zip : CRC32 mismatch")) : e();
  37736. }).resume();
  37737. });
  37738. }
  37739. t.exports = function (e, o) {
  37740. var h = this;
  37741. return o = u.extend(o || {}, {
  37742. base64: !1,
  37743. checkCRC32: !1,
  37744. optimizedBinaryString: !1,
  37745. createFolders: !1,
  37746. decodeFileName: n.utf8decode
  37747. }), l.isNode && l.isStream(e) ? i.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")) : u.prepareContent("the loaded zip file", e, !0, o.optimizedBinaryString, o.base64).then(function (e) {
  37748. var t = new s(o);
  37749. return t.load(e), t;
  37750. }).then(function (e) {
  37751. var t = [i.Promise.resolve(e)],
  37752. r = e.files;
  37753. if (o.checkCRC32) for (var n = 0; n < r.length; n++) t.push(f(r[n]));
  37754. return i.Promise.all(t);
  37755. }).then(function (e) {
  37756. for (var t = e.shift(), r = t.files, n = 0; n < r.length; n++) {
  37757. var i = r[n],
  37758. s = i.fileNameStr,
  37759. a = u.resolve(i.fileNameStr);
  37760. h.file(a, i.decompressed, {
  37761. binary: !0,
  37762. optimizedBinaryString: !0,
  37763. date: i.date,
  37764. dir: i.dir,
  37765. comment: i.fileCommentStr.length ? i.fileCommentStr : null,
  37766. unixPermissions: i.unixPermissions,
  37767. dosPermissions: i.dosPermissions,
  37768. createFolders: o.createFolders
  37769. }), i.dir || (h.file(a).unsafeOriginalName = s);
  37770. }
  37771. return t.zipComment.length && (h.comment = t.zipComment), h;
  37772. });
  37773. };
  37774. }, {
  37775. "./external": 6,
  37776. "./nodejsUtils": 14,
  37777. "./stream/Crc32Probe": 25,
  37778. "./utf8": 31,
  37779. "./utils": 32,
  37780. "./zipEntries": 33
  37781. }],
  37782. 12: [function (e, t, r) {
  37783. "use strict";
  37784. var n = e("../utils"),
  37785. i = e("../stream/GenericWorker");
  37786. function s(e, t) {
  37787. i.call(this, "Nodejs stream input adapter for " + e), this._upstreamEnded = !1, this._bindStream(t);
  37788. }
  37789. n.inherits(s, i), s.prototype._bindStream = function (e) {
  37790. var t = this;
  37791. (this._stream = e).pause(), e.on("data", function (e) {
  37792. t.push({
  37793. data: e,
  37794. meta: {
  37795. percent: 0
  37796. }
  37797. });
  37798. }).on("error", function (e) {
  37799. t.isPaused ? this.generatedError = e : t.error(e);
  37800. }).on("end", function () {
  37801. t.isPaused ? t._upstreamEnded = !0 : t.end();
  37802. });
  37803. }, s.prototype.pause = function () {
  37804. return !!i.prototype.pause.call(this) && (this._stream.pause(), !0);
  37805. }, s.prototype.resume = function () {
  37806. return !!i.prototype.resume.call(this) && (this._upstreamEnded ? this.end() : this._stream.resume(), !0);
  37807. }, t.exports = s;
  37808. }, {
  37809. "../stream/GenericWorker": 28,
  37810. "../utils": 32
  37811. }],
  37812. 13: [function (e, t, r) {
  37813. "use strict";
  37814. var i = e("readable-stream").Readable;
  37815. function n(e, t, r) {
  37816. i.call(this, t), this._helper = e;
  37817. var n = this;
  37818. e.on("data", function (e, t) {
  37819. n.push(e) || n._helper.pause(), r && r(t);
  37820. }).on("error", function (e) {
  37821. n.emit("error", e);
  37822. }).on("end", function () {
  37823. n.push(null);
  37824. });
  37825. }
  37826. e("../utils").inherits(n, i), n.prototype._read = function () {
  37827. this._helper.resume();
  37828. }, t.exports = n;
  37829. }, {
  37830. "../utils": 32,
  37831. "readable-stream": 16
  37832. }],
  37833. 14: [function (e, t, r) {
  37834. "use strict";
  37835. t.exports = {
  37836. isNode: "undefined" != typeof Buffer,
  37837. newBufferFrom: function (e, t) {
  37838. if (Buffer.from && Buffer.from !== Uint8Array.from) return Buffer.from(e, t);
  37839. if ("number" == typeof e) throw new Error('The "data" argument must not be a number');
  37840. return new Buffer(e, t);
  37841. },
  37842. allocBuffer: function (e) {
  37843. if (Buffer.alloc) return Buffer.alloc(e);
  37844. var t = new Buffer(e);
  37845. return t.fill(0), t;
  37846. },
  37847. isBuffer: function (e) {
  37848. return Buffer.isBuffer(e);
  37849. },
  37850. isStream: function (e) {
  37851. return e && "function" == typeof e.on && "function" == typeof e.pause && "function" == typeof e.resume;
  37852. }
  37853. };
  37854. }, {}],
  37855. 15: [function (e, t, r) {
  37856. "use strict";
  37857. function s(e, t, r) {
  37858. var n,
  37859. i = u.getTypeOf(t),
  37860. s = u.extend(r || {}, f);
  37861. s.date = s.date || new Date(), null !== s.compression && (s.compression = s.compression.toUpperCase()), "string" == typeof s.unixPermissions && (s.unixPermissions = parseInt(s.unixPermissions, 8)), s.unixPermissions && 16384 & s.unixPermissions && (s.dir = !0), s.dosPermissions && 16 & s.dosPermissions && (s.dir = !0), s.dir && (e = g(e)), s.createFolders && (n = _(e)) && b.call(this, n, !0);
  37862. var a = "string" === i && !1 === s.binary && !1 === s.base64;
  37863. r && void 0 !== r.binary || (s.binary = !a), (t instanceof c && 0 === t.uncompressedSize || s.dir || !t || 0 === t.length) && (s.base64 = !1, s.binary = !0, t = "", s.compression = "STORE", i = "string");
  37864. var o = null;
  37865. o = t instanceof c || t instanceof l ? t : p.isNode && p.isStream(t) ? new m(e, t) : u.prepareContent(e, t, s.binary, s.optimizedBinaryString, s.base64);
  37866. var h = new d(e, o, s);
  37867. this.files[e] = h;
  37868. }
  37869. var i = e("./utf8"),
  37870. u = e("./utils"),
  37871. l = e("./stream/GenericWorker"),
  37872. a = e("./stream/StreamHelper"),
  37873. f = e("./defaults"),
  37874. c = e("./compressedObject"),
  37875. d = e("./zipObject"),
  37876. o = e("./generate"),
  37877. p = e("./nodejsUtils"),
  37878. m = e("./nodejs/NodejsStreamInputAdapter"),
  37879. _ = function (e) {
  37880. "/" === e.slice(-1) && (e = e.substring(0, e.length - 1));
  37881. var t = e.lastIndexOf("/");
  37882. return 0 < t ? e.substring(0, t) : "";
  37883. },
  37884. g = function (e) {
  37885. return "/" !== e.slice(-1) && (e += "/"), e;
  37886. },
  37887. b = function (e, t) {
  37888. return t = void 0 !== t ? t : f.createFolders, e = g(e), this.files[e] || s.call(this, e, null, {
  37889. dir: !0,
  37890. createFolders: t
  37891. }), this.files[e];
  37892. };
  37893. function h(e) {
  37894. return "[object RegExp]" === Object.prototype.toString.call(e);
  37895. }
  37896. var n = {
  37897. load: function () {
  37898. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  37899. },
  37900. forEach: function (e) {
  37901. var t, r, n;
  37902. for (t in this.files) n = this.files[t], (r = t.slice(this.root.length, t.length)) && t.slice(0, this.root.length) === this.root && e(r, n);
  37903. },
  37904. filter: function (r) {
  37905. var n = [];
  37906. return this.forEach(function (e, t) {
  37907. r(e, t) && n.push(t);
  37908. }), n;
  37909. },
  37910. file: function (e, t, r) {
  37911. if (1 !== arguments.length) return e = this.root + e, s.call(this, e, t, r), this;
  37912. if (h(e)) {
  37913. var n = e;
  37914. return this.filter(function (e, t) {
  37915. return !t.dir && n.test(e);
  37916. });
  37917. }
  37918. var i = this.files[this.root + e];
  37919. return i && !i.dir ? i : null;
  37920. },
  37921. folder: function (r) {
  37922. if (!r) return this;
  37923. if (h(r)) return this.filter(function (e, t) {
  37924. return t.dir && r.test(e);
  37925. });
  37926. var e = this.root + r,
  37927. t = b.call(this, e),
  37928. n = this.clone();
  37929. return n.root = t.name, n;
  37930. },
  37931. remove: function (r) {
  37932. r = this.root + r;
  37933. var e = this.files[r];
  37934. if (e || ("/" !== r.slice(-1) && (r += "/"), e = this.files[r]), e && !e.dir) delete this.files[r];else for (var t = this.filter(function (e, t) {
  37935. return t.name.slice(0, r.length) === r;
  37936. }), n = 0; n < t.length; n++) delete this.files[t[n].name];
  37937. return this;
  37938. },
  37939. generate: function () {
  37940. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  37941. },
  37942. generateInternalStream: function (e) {
  37943. var t,
  37944. r = {};
  37945. try {
  37946. if ((r = u.extend(e || {}, {
  37947. streamFiles: !1,
  37948. compression: "STORE",
  37949. compressionOptions: null,
  37950. type: "",
  37951. platform: "DOS",
  37952. comment: null,
  37953. mimeType: "application/zip",
  37954. encodeFileName: i.utf8encode
  37955. })).type = r.type.toLowerCase(), r.compression = r.compression.toUpperCase(), "binarystring" === r.type && (r.type = "string"), !r.type) throw new Error("No output type specified.");
  37956. u.checkSupport(r.type), "darwin" !== r.platform && "freebsd" !== r.platform && "linux" !== r.platform && "sunos" !== r.platform || (r.platform = "UNIX"), "win32" === r.platform && (r.platform = "DOS");
  37957. var n = r.comment || this.comment || "";
  37958. t = o.generateWorker(this, r, n);
  37959. } catch (e) {
  37960. (t = new l("error")).error(e);
  37961. }
  37962. return new a(t, r.type || "string", r.mimeType);
  37963. },
  37964. generateAsync: function (e, t) {
  37965. return this.generateInternalStream(e).accumulate(t);
  37966. },
  37967. generateNodeStream: function (e, t) {
  37968. return (e = e || {}).type || (e.type = "nodebuffer"), this.generateInternalStream(e).toNodejsStream(t);
  37969. }
  37970. };
  37971. t.exports = n;
  37972. }, {
  37973. "./compressedObject": 2,
  37974. "./defaults": 5,
  37975. "./generate": 9,
  37976. "./nodejs/NodejsStreamInputAdapter": 12,
  37977. "./nodejsUtils": 14,
  37978. "./stream/GenericWorker": 28,
  37979. "./stream/StreamHelper": 29,
  37980. "./utf8": 31,
  37981. "./utils": 32,
  37982. "./zipObject": 35
  37983. }],
  37984. 16: [function (e, t, r) {
  37985. "use strict";
  37986. t.exports = e("stream");
  37987. }, {
  37988. stream: void 0
  37989. }],
  37990. 17: [function (e, t, r) {
  37991. "use strict";
  37992. var n = e("./DataReader");
  37993. function i(e) {
  37994. n.call(this, e);
  37995. for (var t = 0; t < this.data.length; t++) e[t] = 255 & e[t];
  37996. }
  37997. e("../utils").inherits(i, n), i.prototype.byteAt = function (e) {
  37998. return this.data[this.zero + e];
  37999. }, i.prototype.lastIndexOfSignature = function (e) {
  38000. for (var t = e.charCodeAt(0), r = e.charCodeAt(1), n = e.charCodeAt(2), i = e.charCodeAt(3), s = this.length - 4; 0 <= s; --s) if (this.data[s] === t && this.data[s + 1] === r && this.data[s + 2] === n && this.data[s + 3] === i) return s - this.zero;
  38001. return -1;
  38002. }, i.prototype.readAndCheckSignature = function (e) {
  38003. var t = e.charCodeAt(0),
  38004. r = e.charCodeAt(1),
  38005. n = e.charCodeAt(2),
  38006. i = e.charCodeAt(3),
  38007. s = this.readData(4);
  38008. return t === s[0] && r === s[1] && n === s[2] && i === s[3];
  38009. }, i.prototype.readData = function (e) {
  38010. if (this.checkOffset(e), 0 === e) return [];
  38011. var t = this.data.slice(this.zero + this.index, this.zero + this.index + e);
  38012. return this.index += e, t;
  38013. }, t.exports = i;
  38014. }, {
  38015. "../utils": 32,
  38016. "./DataReader": 18
  38017. }],
  38018. 18: [function (e, t, r) {
  38019. "use strict";
  38020. var n = e("../utils");
  38021. function i(e) {
  38022. this.data = e, this.length = e.length, this.index = 0, this.zero = 0;
  38023. }
  38024. i.prototype = {
  38025. checkOffset: function (e) {
  38026. this.checkIndex(this.index + e);
  38027. },
  38028. checkIndex: function (e) {
  38029. if (this.length < this.zero + e || e < 0) throw new Error("End of data reached (data length = " + this.length + ", asked index = " + e + "). Corrupted zip ?");
  38030. },
  38031. setIndex: function (e) {
  38032. this.checkIndex(e), this.index = e;
  38033. },
  38034. skip: function (e) {
  38035. this.setIndex(this.index + e);
  38036. },
  38037. byteAt: function () {},
  38038. readInt: function (e) {
  38039. var t,
  38040. r = 0;
  38041. for (this.checkOffset(e), t = this.index + e - 1; t >= this.index; t--) r = (r << 8) + this.byteAt(t);
  38042. return this.index += e, r;
  38043. },
  38044. readString: function (e) {
  38045. return n.transformTo("string", this.readData(e));
  38046. },
  38047. readData: function () {},
  38048. lastIndexOfSignature: function () {},
  38049. readAndCheckSignature: function () {},
  38050. readDate: function () {
  38051. var e = this.readInt(4);
  38052. return new Date(Date.UTC(1980 + (e >> 25 & 127), (e >> 21 & 15) - 1, e >> 16 & 31, e >> 11 & 31, e >> 5 & 63, (31 & e) << 1));
  38053. }
  38054. }, t.exports = i;
  38055. }, {
  38056. "../utils": 32
  38057. }],
  38058. 19: [function (e, t, r) {
  38059. "use strict";
  38060. var n = e("./Uint8ArrayReader");
  38061. function i(e) {
  38062. n.call(this, e);
  38063. }
  38064. e("../utils").inherits(i, n), i.prototype.readData = function (e) {
  38065. this.checkOffset(e);
  38066. var t = this.data.slice(this.zero + this.index, this.zero + this.index + e);
  38067. return this.index += e, t;
  38068. }, t.exports = i;
  38069. }, {
  38070. "../utils": 32,
  38071. "./Uint8ArrayReader": 21
  38072. }],
  38073. 20: [function (e, t, r) {
  38074. "use strict";
  38075. var n = e("./DataReader");
  38076. function i(e) {
  38077. n.call(this, e);
  38078. }
  38079. e("../utils").inherits(i, n), i.prototype.byteAt = function (e) {
  38080. return this.data.charCodeAt(this.zero + e);
  38081. }, i.prototype.lastIndexOfSignature = function (e) {
  38082. return this.data.lastIndexOf(e) - this.zero;
  38083. }, i.prototype.readAndCheckSignature = function (e) {
  38084. return e === this.readData(4);
  38085. }, i.prototype.readData = function (e) {
  38086. this.checkOffset(e);
  38087. var t = this.data.slice(this.zero + this.index, this.zero + this.index + e);
  38088. return this.index += e, t;
  38089. }, t.exports = i;
  38090. }, {
  38091. "../utils": 32,
  38092. "./DataReader": 18
  38093. }],
  38094. 21: [function (e, t, r) {
  38095. "use strict";
  38096. var n = e("./ArrayReader");
  38097. function i(e) {
  38098. n.call(this, e);
  38099. }
  38100. e("../utils").inherits(i, n), i.prototype.readData = function (e) {
  38101. if (this.checkOffset(e), 0 === e) return new Uint8Array(0);
  38102. var t = this.data.subarray(this.zero + this.index, this.zero + this.index + e);
  38103. return this.index += e, t;
  38104. }, t.exports = i;
  38105. }, {
  38106. "../utils": 32,
  38107. "./ArrayReader": 17
  38108. }],
  38109. 22: [function (e, t, r) {
  38110. "use strict";
  38111. var n = e("../utils"),
  38112. i = e("../support"),
  38113. s = e("./ArrayReader"),
  38114. a = e("./StringReader"),
  38115. o = e("./NodeBufferReader"),
  38116. h = e("./Uint8ArrayReader");
  38117. t.exports = function (e) {
  38118. var t = n.getTypeOf(e);
  38119. return n.checkSupport(t), "string" !== t || i.uint8array ? "nodebuffer" === t ? new o(e) : i.uint8array ? new h(n.transformTo("uint8array", e)) : new s(n.transformTo("array", e)) : new a(e);
  38120. };
  38121. }, {
  38122. "../support": 30,
  38123. "../utils": 32,
  38124. "./ArrayReader": 17,
  38125. "./NodeBufferReader": 19,
  38126. "./StringReader": 20,
  38127. "./Uint8ArrayReader": 21
  38128. }],
  38129. 23: [function (e, t, r) {
  38130. "use strict";
  38131. r.LOCAL_FILE_HEADER = "PK", r.CENTRAL_FILE_HEADER = "PK", r.CENTRAL_DIRECTORY_END = "PK", r.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK", r.ZIP64_CENTRAL_DIRECTORY_END = "PK", r.DATA_DESCRIPTOR = "PK\b";
  38132. }, {}],
  38133. 24: [function (e, t, r) {
  38134. "use strict";
  38135. var n = e("./GenericWorker"),
  38136. i = e("../utils");
  38137. function s(e) {
  38138. n.call(this, "ConvertWorker to " + e), this.destType = e;
  38139. }
  38140. i.inherits(s, n), s.prototype.processChunk = function (e) {
  38141. this.push({
  38142. data: i.transformTo(this.destType, e.data),
  38143. meta: e.meta
  38144. });
  38145. }, t.exports = s;
  38146. }, {
  38147. "../utils": 32,
  38148. "./GenericWorker": 28
  38149. }],
  38150. 25: [function (e, t, r) {
  38151. "use strict";
  38152. var n = e("./GenericWorker"),
  38153. i = e("../crc32");
  38154. function s() {
  38155. n.call(this, "Crc32Probe"), this.withStreamInfo("crc32", 0);
  38156. }
  38157. e("../utils").inherits(s, n), s.prototype.processChunk = function (e) {
  38158. this.streamInfo.crc32 = i(e.data, this.streamInfo.crc32 || 0), this.push(e);
  38159. }, t.exports = s;
  38160. }, {
  38161. "../crc32": 4,
  38162. "../utils": 32,
  38163. "./GenericWorker": 28
  38164. }],
  38165. 26: [function (e, t, r) {
  38166. "use strict";
  38167. var n = e("../utils"),
  38168. i = e("./GenericWorker");
  38169. function s(e) {
  38170. i.call(this, "DataLengthProbe for " + e), this.propName = e, this.withStreamInfo(e, 0);
  38171. }
  38172. n.inherits(s, i), s.prototype.processChunk = function (e) {
  38173. if (e) {
  38174. var t = this.streamInfo[this.propName] || 0;
  38175. this.streamInfo[this.propName] = t + e.data.length;
  38176. }
  38177. i.prototype.processChunk.call(this, e);
  38178. }, t.exports = s;
  38179. }, {
  38180. "../utils": 32,
  38181. "./GenericWorker": 28
  38182. }],
  38183. 27: [function (e, t, r) {
  38184. "use strict";
  38185. var n = e("../utils"),
  38186. i = e("./GenericWorker");
  38187. function s(e) {
  38188. i.call(this, "DataWorker");
  38189. var t = this;
  38190. this.dataIsReady = !1, this.index = 0, this.max = 0, this.data = null, this.type = "", this._tickScheduled = !1, e.then(function (e) {
  38191. t.dataIsReady = !0, t.data = e, t.max = e && e.length || 0, t.type = n.getTypeOf(e), t.isPaused || t._tickAndRepeat();
  38192. }, function (e) {
  38193. t.error(e);
  38194. });
  38195. }
  38196. n.inherits(s, i), s.prototype.cleanUp = function () {
  38197. i.prototype.cleanUp.call(this), this.data = null;
  38198. }, s.prototype.resume = function () {
  38199. return !!i.prototype.resume.call(this) && (!this._tickScheduled && this.dataIsReady && (this._tickScheduled = !0, n.delay(this._tickAndRepeat, [], this)), !0);
  38200. }, s.prototype._tickAndRepeat = function () {
  38201. this._tickScheduled = !1, this.isPaused || this.isFinished || (this._tick(), this.isFinished || (n.delay(this._tickAndRepeat, [], this), this._tickScheduled = !0));
  38202. }, s.prototype._tick = function () {
  38203. if (this.isPaused || this.isFinished) return !1;
  38204. var e = null,
  38205. t = Math.min(this.max, this.index + 16384);
  38206. if (this.index >= this.max) return this.end();
  38207. switch (this.type) {
  38208. case "string":
  38209. e = this.data.substring(this.index, t);
  38210. break;
  38211. case "uint8array":
  38212. e = this.data.subarray(this.index, t);
  38213. break;
  38214. case "array":
  38215. case "nodebuffer":
  38216. e = this.data.slice(this.index, t);
  38217. }
  38218. return this.index = t, this.push({
  38219. data: e,
  38220. meta: {
  38221. percent: this.max ? this.index / this.max * 100 : 0
  38222. }
  38223. });
  38224. }, t.exports = s;
  38225. }, {
  38226. "../utils": 32,
  38227. "./GenericWorker": 28
  38228. }],
  38229. 28: [function (e, t, r) {
  38230. "use strict";
  38231. function n(e) {
  38232. this.name = e || "default", this.streamInfo = {}, this.generatedError = null, this.extraStreamInfo = {}, this.isPaused = !0, this.isFinished = !1, this.isLocked = !1, this._listeners = {
  38233. data: [],
  38234. end: [],
  38235. error: []
  38236. }, this.previous = null;
  38237. }
  38238. n.prototype = {
  38239. push: function (e) {
  38240. this.emit("data", e);
  38241. },
  38242. end: function () {
  38243. if (this.isFinished) return !1;
  38244. this.flush();
  38245. try {
  38246. this.emit("end"), this.cleanUp(), this.isFinished = !0;
  38247. } catch (e) {
  38248. this.emit("error", e);
  38249. }
  38250. return !0;
  38251. },
  38252. error: function (e) {
  38253. return !this.isFinished && (this.isPaused ? this.generatedError = e : (this.isFinished = !0, this.emit("error", e), this.previous && this.previous.error(e), this.cleanUp()), !0);
  38254. },
  38255. on: function (e, t) {
  38256. return this._listeners[e].push(t), this;
  38257. },
  38258. cleanUp: function () {
  38259. this.streamInfo = this.generatedError = this.extraStreamInfo = null, this._listeners = [];
  38260. },
  38261. emit: function (e, t) {
  38262. if (this._listeners[e]) for (var r = 0; r < this._listeners[e].length; r++) this._listeners[e][r].call(this, t);
  38263. },
  38264. pipe: function (e) {
  38265. return e.registerPrevious(this);
  38266. },
  38267. registerPrevious: function (e) {
  38268. if (this.isLocked) throw new Error("The stream '" + this + "' has already been used.");
  38269. this.streamInfo = e.streamInfo, this.mergeStreamInfo(), this.previous = e;
  38270. var t = this;
  38271. return e.on("data", function (e) {
  38272. t.processChunk(e);
  38273. }), e.on("end", function () {
  38274. t.end();
  38275. }), e.on("error", function (e) {
  38276. t.error(e);
  38277. }), this;
  38278. },
  38279. pause: function () {
  38280. return !this.isPaused && !this.isFinished && (this.isPaused = !0, this.previous && this.previous.pause(), !0);
  38281. },
  38282. resume: function () {
  38283. if (!this.isPaused || this.isFinished) return !1;
  38284. var e = this.isPaused = !1;
  38285. return this.generatedError && (this.error(this.generatedError), e = !0), this.previous && this.previous.resume(), !e;
  38286. },
  38287. flush: function () {},
  38288. processChunk: function (e) {
  38289. this.push(e);
  38290. },
  38291. withStreamInfo: function (e, t) {
  38292. return this.extraStreamInfo[e] = t, this.mergeStreamInfo(), this;
  38293. },
  38294. mergeStreamInfo: function () {
  38295. for (var e in this.extraStreamInfo) Object.prototype.hasOwnProperty.call(this.extraStreamInfo, e) && (this.streamInfo[e] = this.extraStreamInfo[e]);
  38296. },
  38297. lock: function () {
  38298. if (this.isLocked) throw new Error("The stream '" + this + "' has already been used.");
  38299. this.isLocked = !0, this.previous && this.previous.lock();
  38300. },
  38301. toString: function () {
  38302. var e = "Worker " + this.name;
  38303. return this.previous ? this.previous + " -> " + e : e;
  38304. }
  38305. }, t.exports = n;
  38306. }, {}],
  38307. 29: [function (e, t, r) {
  38308. "use strict";
  38309. var h = e("../utils"),
  38310. i = e("./ConvertWorker"),
  38311. s = e("./GenericWorker"),
  38312. u = e("../base64"),
  38313. n = e("../support"),
  38314. a = e("../external"),
  38315. o = null;
  38316. if (n.nodestream) try {
  38317. o = e("../nodejs/NodejsStreamOutputAdapter");
  38318. } catch (e) {}
  38319. function l(e, o) {
  38320. return new a.Promise(function (t, r) {
  38321. var n = [],
  38322. i = e._internalType,
  38323. s = e._outputType,
  38324. a = e._mimeType;
  38325. e.on("data", function (e, t) {
  38326. n.push(e), o && o(t);
  38327. }).on("error", function (e) {
  38328. n = [], r(e);
  38329. }).on("end", function () {
  38330. try {
  38331. var e = function (e, t, r) {
  38332. switch (e) {
  38333. case "blob":
  38334. return h.newBlob(h.transformTo("arraybuffer", t), r);
  38335. case "base64":
  38336. return u.encode(t);
  38337. default:
  38338. return h.transformTo(e, t);
  38339. }
  38340. }(s, function (e, t) {
  38341. var r,
  38342. n = 0,
  38343. i = null,
  38344. s = 0;
  38345. for (r = 0; r < t.length; r++) s += t[r].length;
  38346. switch (e) {
  38347. case "string":
  38348. return t.join("");
  38349. case "array":
  38350. return Array.prototype.concat.apply([], t);
  38351. case "uint8array":
  38352. for (i = new Uint8Array(s), r = 0; r < t.length; r++) i.set(t[r], n), n += t[r].length;
  38353. return i;
  38354. case "nodebuffer":
  38355. return Buffer.concat(t);
  38356. default:
  38357. throw new Error("concat : unsupported type '" + e + "'");
  38358. }
  38359. }(i, n), a);
  38360. t(e);
  38361. } catch (e) {
  38362. r(e);
  38363. }
  38364. n = [];
  38365. }).resume();
  38366. });
  38367. }
  38368. function f(e, t, r) {
  38369. var n = t;
  38370. switch (t) {
  38371. case "blob":
  38372. case "arraybuffer":
  38373. n = "uint8array";
  38374. break;
  38375. case "base64":
  38376. n = "string";
  38377. }
  38378. try {
  38379. this._internalType = n, this._outputType = t, this._mimeType = r, h.checkSupport(n), this._worker = e.pipe(new i(n)), e.lock();
  38380. } catch (e) {
  38381. this._worker = new s("error"), this._worker.error(e);
  38382. }
  38383. }
  38384. f.prototype = {
  38385. accumulate: function (e) {
  38386. return l(this, e);
  38387. },
  38388. on: function (e, t) {
  38389. var r = this;
  38390. return "data" === e ? this._worker.on(e, function (e) {
  38391. t.call(r, e.data, e.meta);
  38392. }) : this._worker.on(e, function () {
  38393. h.delay(t, arguments, r);
  38394. }), this;
  38395. },
  38396. resume: function () {
  38397. return h.delay(this._worker.resume, [], this._worker), this;
  38398. },
  38399. pause: function () {
  38400. return this._worker.pause(), this;
  38401. },
  38402. toNodejsStream: function (e) {
  38403. if (h.checkSupport("nodestream"), "nodebuffer" !== this._outputType) throw new Error(this._outputType + " is not supported by this method");
  38404. return new o(this, {
  38405. objectMode: "nodebuffer" !== this._outputType
  38406. }, e);
  38407. }
  38408. }, t.exports = f;
  38409. }, {
  38410. "../base64": 1,
  38411. "../external": 6,
  38412. "../nodejs/NodejsStreamOutputAdapter": 13,
  38413. "../support": 30,
  38414. "../utils": 32,
  38415. "./ConvertWorker": 24,
  38416. "./GenericWorker": 28
  38417. }],
  38418. 30: [function (e, t, r) {
  38419. "use strict";
  38420. if (r.base64 = !0, r.array = !0, r.string = !0, r.arraybuffer = "undefined" != typeof ArrayBuffer && "undefined" != typeof Uint8Array, r.nodebuffer = "undefined" != typeof Buffer, r.uint8array = "undefined" != typeof Uint8Array, "undefined" == typeof ArrayBuffer) r.blob = !1;else {
  38421. var n = new ArrayBuffer(0);
  38422. try {
  38423. r.blob = 0 === new Blob([n], {
  38424. type: "application/zip"
  38425. }).size;
  38426. } catch (e) {
  38427. try {
  38428. var i = new (self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder)();
  38429. i.append(n), r.blob = 0 === i.getBlob("application/zip").size;
  38430. } catch (e) {
  38431. r.blob = !1;
  38432. }
  38433. }
  38434. }
  38435. try {
  38436. r.nodestream = !!e("readable-stream").Readable;
  38437. } catch (e) {
  38438. r.nodestream = !1;
  38439. }
  38440. }, {
  38441. "readable-stream": 16
  38442. }],
  38443. 31: [function (e, t, s) {
  38444. "use strict";
  38445. for (var o = e("./utils"), h = e("./support"), r = e("./nodejsUtils"), n = e("./stream/GenericWorker"), u = new Array(256), i = 0; i < 256; i++) u[i] = 252 <= i ? 6 : 248 <= i ? 5 : 240 <= i ? 4 : 224 <= i ? 3 : 192 <= i ? 2 : 1;
  38446. u[254] = u[254] = 1;
  38447. function a() {
  38448. n.call(this, "utf-8 decode"), this.leftOver = null;
  38449. }
  38450. function l() {
  38451. n.call(this, "utf-8 encode");
  38452. }
  38453. s.utf8encode = function (e) {
  38454. return h.nodebuffer ? r.newBufferFrom(e, "utf-8") : function (e) {
  38455. var t,
  38456. r,
  38457. n,
  38458. i,
  38459. s,
  38460. a = e.length,
  38461. o = 0;
  38462. for (i = 0; i < a; i++) 55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), o += r < 128 ? 1 : r < 2048 ? 2 : r < 65536 ? 3 : 4;
  38463. for (t = h.uint8array ? new Uint8Array(o) : new Array(o), i = s = 0; s < o; i++) 55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), r < 128 ? t[s++] = r : (r < 2048 ? t[s++] = 192 | r >>> 6 : (r < 65536 ? t[s++] = 224 | r >>> 12 : (t[s++] = 240 | r >>> 18, t[s++] = 128 | r >>> 12 & 63), t[s++] = 128 | r >>> 6 & 63), t[s++] = 128 | 63 & r);
  38464. return t;
  38465. }(e);
  38466. }, s.utf8decode = function (e) {
  38467. return h.nodebuffer ? o.transformTo("nodebuffer", e).toString("utf-8") : function (e) {
  38468. var t,
  38469. r,
  38470. n,
  38471. i,
  38472. s = e.length,
  38473. a = new Array(2 * s);
  38474. for (t = r = 0; t < s;) if ((n = e[t++]) < 128) a[r++] = n;else if (4 < (i = u[n])) a[r++] = 65533, t += i - 1;else {
  38475. for (n &= 2 === i ? 31 : 3 === i ? 15 : 7; 1 < i && t < s;) n = n << 6 | 63 & e[t++], i--;
  38476. 1 < i ? a[r++] = 65533 : n < 65536 ? a[r++] = n : (n -= 65536, a[r++] = 55296 | n >> 10 & 1023, a[r++] = 56320 | 1023 & n);
  38477. }
  38478. return a.length !== r && (a.subarray ? a = a.subarray(0, r) : a.length = r), o.applyFromCharCode(a);
  38479. }(e = o.transformTo(h.uint8array ? "uint8array" : "array", e));
  38480. }, o.inherits(a, n), a.prototype.processChunk = function (e) {
  38481. var t = o.transformTo(h.uint8array ? "uint8array" : "array", e.data);
  38482. if (this.leftOver && this.leftOver.length) {
  38483. if (h.uint8array) {
  38484. var r = t;
  38485. (t = new Uint8Array(r.length + this.leftOver.length)).set(this.leftOver, 0), t.set(r, this.leftOver.length);
  38486. } else t = this.leftOver.concat(t);
  38487. this.leftOver = null;
  38488. }
  38489. var n = function (e, t) {
  38490. var r;
  38491. for ((t = t || e.length) > e.length && (t = e.length), r = t - 1; 0 <= r && 128 == (192 & e[r]);) r--;
  38492. return r < 0 ? t : 0 === r ? t : r + u[e[r]] > t ? r : t;
  38493. }(t),
  38494. i = t;
  38495. n !== t.length && (h.uint8array ? (i = t.subarray(0, n), this.leftOver = t.subarray(n, t.length)) : (i = t.slice(0, n), this.leftOver = t.slice(n, t.length))), this.push({
  38496. data: s.utf8decode(i),
  38497. meta: e.meta
  38498. });
  38499. }, a.prototype.flush = function () {
  38500. this.leftOver && this.leftOver.length && (this.push({
  38501. data: s.utf8decode(this.leftOver),
  38502. meta: {}
  38503. }), this.leftOver = null);
  38504. }, s.Utf8DecodeWorker = a, o.inherits(l, n), l.prototype.processChunk = function (e) {
  38505. this.push({
  38506. data: s.utf8encode(e.data),
  38507. meta: e.meta
  38508. });
  38509. }, s.Utf8EncodeWorker = l;
  38510. }, {
  38511. "./nodejsUtils": 14,
  38512. "./stream/GenericWorker": 28,
  38513. "./support": 30,
  38514. "./utils": 32
  38515. }],
  38516. 32: [function (e, t, a) {
  38517. "use strict";
  38518. var o = e("./support"),
  38519. h = e("./base64"),
  38520. r = e("./nodejsUtils"),
  38521. u = e("./external");
  38522. function n(e) {
  38523. return e;
  38524. }
  38525. function l(e, t) {
  38526. for (var r = 0; r < e.length; ++r) t[r] = 255 & e.charCodeAt(r);
  38527. return t;
  38528. }
  38529. e("setimmediate"), a.newBlob = function (t, r) {
  38530. a.checkSupport("blob");
  38531. try {
  38532. return new Blob([t], {
  38533. type: r
  38534. });
  38535. } catch (e) {
  38536. try {
  38537. var n = new (self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder)();
  38538. return n.append(t), n.getBlob(r);
  38539. } catch (e) {
  38540. throw new Error("Bug : can't construct the Blob.");
  38541. }
  38542. }
  38543. };
  38544. var i = {
  38545. stringifyByChunk: function (e, t, r) {
  38546. var n = [],
  38547. i = 0,
  38548. s = e.length;
  38549. if (s <= r) return String.fromCharCode.apply(null, e);
  38550. for (; i < s;) "array" === t || "nodebuffer" === t ? n.push(String.fromCharCode.apply(null, e.slice(i, Math.min(i + r, s)))) : n.push(String.fromCharCode.apply(null, e.subarray(i, Math.min(i + r, s)))), i += r;
  38551. return n.join("");
  38552. },
  38553. stringifyByChar: function (e) {
  38554. for (var t = "", r = 0; r < e.length; r++) t += String.fromCharCode(e[r]);
  38555. return t;
  38556. },
  38557. applyCanBeUsed: {
  38558. uint8array: function () {
  38559. try {
  38560. return o.uint8array && 1 === String.fromCharCode.apply(null, new Uint8Array(1)).length;
  38561. } catch (e) {
  38562. return !1;
  38563. }
  38564. }(),
  38565. nodebuffer: function () {
  38566. try {
  38567. return o.nodebuffer && 1 === String.fromCharCode.apply(null, r.allocBuffer(1)).length;
  38568. } catch (e) {
  38569. return !1;
  38570. }
  38571. }()
  38572. }
  38573. };
  38574. function s(e) {
  38575. var t = 65536,
  38576. r = a.getTypeOf(e),
  38577. n = !0;
  38578. if ("uint8array" === r ? n = i.applyCanBeUsed.uint8array : "nodebuffer" === r && (n = i.applyCanBeUsed.nodebuffer), n) for (; 1 < t;) try {
  38579. return i.stringifyByChunk(e, r, t);
  38580. } catch (e) {
  38581. t = Math.floor(t / 2);
  38582. }
  38583. return i.stringifyByChar(e);
  38584. }
  38585. function f(e, t) {
  38586. for (var r = 0; r < e.length; r++) t[r] = e[r];
  38587. return t;
  38588. }
  38589. a.applyFromCharCode = s;
  38590. var c = {};
  38591. c.string = {
  38592. string: n,
  38593. array: function (e) {
  38594. return l(e, new Array(e.length));
  38595. },
  38596. arraybuffer: function (e) {
  38597. return c.string.uint8array(e).buffer;
  38598. },
  38599. uint8array: function (e) {
  38600. return l(e, new Uint8Array(e.length));
  38601. },
  38602. nodebuffer: function (e) {
  38603. return l(e, r.allocBuffer(e.length));
  38604. }
  38605. }, c.array = {
  38606. string: s,
  38607. array: n,
  38608. arraybuffer: function (e) {
  38609. return new Uint8Array(e).buffer;
  38610. },
  38611. uint8array: function (e) {
  38612. return new Uint8Array(e);
  38613. },
  38614. nodebuffer: function (e) {
  38615. return r.newBufferFrom(e);
  38616. }
  38617. }, c.arraybuffer = {
  38618. string: function (e) {
  38619. return s(new Uint8Array(e));
  38620. },
  38621. array: function (e) {
  38622. return f(new Uint8Array(e), new Array(e.byteLength));
  38623. },
  38624. arraybuffer: n,
  38625. uint8array: function (e) {
  38626. return new Uint8Array(e);
  38627. },
  38628. nodebuffer: function (e) {
  38629. return r.newBufferFrom(new Uint8Array(e));
  38630. }
  38631. }, c.uint8array = {
  38632. string: s,
  38633. array: function (e) {
  38634. return f(e, new Array(e.length));
  38635. },
  38636. arraybuffer: function (e) {
  38637. return e.buffer;
  38638. },
  38639. uint8array: n,
  38640. nodebuffer: function (e) {
  38641. return r.newBufferFrom(e);
  38642. }
  38643. }, c.nodebuffer = {
  38644. string: s,
  38645. array: function (e) {
  38646. return f(e, new Array(e.length));
  38647. },
  38648. arraybuffer: function (e) {
  38649. return c.nodebuffer.uint8array(e).buffer;
  38650. },
  38651. uint8array: function (e) {
  38652. return f(e, new Uint8Array(e.length));
  38653. },
  38654. nodebuffer: n
  38655. }, a.transformTo = function (e, t) {
  38656. if (t = t || "", !e) return t;
  38657. a.checkSupport(e);
  38658. var r = a.getTypeOf(t);
  38659. return c[r][e](t);
  38660. }, a.resolve = function (e) {
  38661. for (var t = e.split("/"), r = [], n = 0; n < t.length; n++) {
  38662. var i = t[n];
  38663. "." === i || "" === i && 0 !== n && n !== t.length - 1 || (".." === i ? r.pop() : r.push(i));
  38664. }
  38665. return r.join("/");
  38666. }, a.getTypeOf = function (e) {
  38667. return "string" == typeof e ? "string" : "[object Array]" === Object.prototype.toString.call(e) ? "array" : o.nodebuffer && r.isBuffer(e) ? "nodebuffer" : o.uint8array && e instanceof Uint8Array ? "uint8array" : o.arraybuffer && e instanceof ArrayBuffer ? "arraybuffer" : void 0;
  38668. }, a.checkSupport = function (e) {
  38669. if (!o[e.toLowerCase()]) throw new Error(e + " is not supported by this platform");
  38670. }, a.MAX_VALUE_16BITS = 65535, a.MAX_VALUE_32BITS = -1, a.pretty = function (e) {
  38671. var t,
  38672. r,
  38673. n = "";
  38674. for (r = 0; r < (e || "").length; r++) n += "\\x" + ((t = e.charCodeAt(r)) < 16 ? "0" : "") + t.toString(16).toUpperCase();
  38675. return n;
  38676. }, a.delay = function (e, t, r) {
  38677. setImmediate(function () {
  38678. e.apply(r || null, t || []);
  38679. });
  38680. }, a.inherits = function (e, t) {
  38681. function r() {}
  38682. r.prototype = t.prototype, e.prototype = new r();
  38683. }, a.extend = function () {
  38684. var e,
  38685. t,
  38686. r = {};
  38687. for (e = 0; e < arguments.length; e++) for (t in arguments[e]) Object.prototype.hasOwnProperty.call(arguments[e], t) && void 0 === r[t] && (r[t] = arguments[e][t]);
  38688. return r;
  38689. }, a.prepareContent = function (r, e, n, i, s) {
  38690. return u.Promise.resolve(e).then(function (n) {
  38691. return o.blob && (n instanceof Blob || -1 !== ["[object File]", "[object Blob]"].indexOf(Object.prototype.toString.call(n))) && "undefined" != typeof FileReader ? new u.Promise(function (t, r) {
  38692. var e = new FileReader();
  38693. e.onload = function (e) {
  38694. t(e.target.result);
  38695. }, e.onerror = function (e) {
  38696. r(e.target.error);
  38697. }, e.readAsArrayBuffer(n);
  38698. }) : n;
  38699. }).then(function (e) {
  38700. var t = a.getTypeOf(e);
  38701. return t ? ("arraybuffer" === t ? e = a.transformTo("uint8array", e) : "string" === t && (s ? e = h.decode(e) : n && !0 !== i && (e = function (e) {
  38702. return l(e, o.uint8array ? new Uint8Array(e.length) : new Array(e.length));
  38703. }(e))), e) : u.Promise.reject(new Error("Can't read the data of '" + r + "'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?"));
  38704. });
  38705. };
  38706. }, {
  38707. "./base64": 1,
  38708. "./external": 6,
  38709. "./nodejsUtils": 14,
  38710. "./support": 30,
  38711. setimmediate: 54
  38712. }],
  38713. 33: [function (e, t, r) {
  38714. "use strict";
  38715. var n = e("./reader/readerFor"),
  38716. i = e("./utils"),
  38717. s = e("./signature"),
  38718. a = e("./zipEntry"),
  38719. o = e("./support");
  38720. function h(e) {
  38721. this.files = [], this.loadOptions = e;
  38722. }
  38723. h.prototype = {
  38724. checkSignature: function (e) {
  38725. if (!this.reader.readAndCheckSignature(e)) {
  38726. this.reader.index -= 4;
  38727. var t = this.reader.readString(4);
  38728. throw new Error("Corrupted zip or bug: unexpected signature (" + i.pretty(t) + ", expected " + i.pretty(e) + ")");
  38729. }
  38730. },
  38731. isSignature: function (e, t) {
  38732. var r = this.reader.index;
  38733. this.reader.setIndex(e);
  38734. var n = this.reader.readString(4) === t;
  38735. return this.reader.setIndex(r), n;
  38736. },
  38737. readBlockEndOfCentral: function () {
  38738. this.diskNumber = this.reader.readInt(2), this.diskWithCentralDirStart = this.reader.readInt(2), this.centralDirRecordsOnThisDisk = this.reader.readInt(2), this.centralDirRecords = this.reader.readInt(2), this.centralDirSize = this.reader.readInt(4), this.centralDirOffset = this.reader.readInt(4), this.zipCommentLength = this.reader.readInt(2);
  38739. var e = this.reader.readData(this.zipCommentLength),
  38740. t = o.uint8array ? "uint8array" : "array",
  38741. r = i.transformTo(t, e);
  38742. this.zipComment = this.loadOptions.decodeFileName(r);
  38743. },
  38744. readBlockZip64EndOfCentral: function () {
  38745. this.zip64EndOfCentralSize = this.reader.readInt(8), this.reader.skip(4), this.diskNumber = this.reader.readInt(4), this.diskWithCentralDirStart = this.reader.readInt(4), this.centralDirRecordsOnThisDisk = this.reader.readInt(8), this.centralDirRecords = this.reader.readInt(8), this.centralDirSize = this.reader.readInt(8), this.centralDirOffset = this.reader.readInt(8), this.zip64ExtensibleData = {};
  38746. for (var e, t, r, n = this.zip64EndOfCentralSize - 44; 0 < n;) e = this.reader.readInt(2), t = this.reader.readInt(4), r = this.reader.readData(t), this.zip64ExtensibleData[e] = {
  38747. id: e,
  38748. length: t,
  38749. value: r
  38750. };
  38751. },
  38752. readBlockZip64EndOfCentralLocator: function () {
  38753. if (this.diskWithZip64CentralDirStart = this.reader.readInt(4), this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8), this.disksCount = this.reader.readInt(4), 1 < this.disksCount) throw new Error("Multi-volumes zip are not supported");
  38754. },
  38755. readLocalFiles: function () {
  38756. var e, t;
  38757. for (e = 0; e < this.files.length; e++) t = this.files[e], this.reader.setIndex(t.localHeaderOffset), this.checkSignature(s.LOCAL_FILE_HEADER), t.readLocalPart(this.reader), t.handleUTF8(), t.processAttributes();
  38758. },
  38759. readCentralDir: function () {
  38760. var e;
  38761. for (this.reader.setIndex(this.centralDirOffset); this.reader.readAndCheckSignature(s.CENTRAL_FILE_HEADER);) (e = new a({
  38762. zip64: this.zip64
  38763. }, this.loadOptions)).readCentralPart(this.reader), this.files.push(e);
  38764. if (this.centralDirRecords !== this.files.length && 0 !== this.centralDirRecords && 0 === this.files.length) throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length);
  38765. },
  38766. readEndOfCentral: function () {
  38767. var e = this.reader.lastIndexOfSignature(s.CENTRAL_DIRECTORY_END);
  38768. if (e < 0) throw !this.isSignature(0, s.LOCAL_FILE_HEADER) ? new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html") : new Error("Corrupted zip: can't find end of central directory");
  38769. this.reader.setIndex(e);
  38770. var t = e;
  38771. if (this.checkSignature(s.CENTRAL_DIRECTORY_END), this.readBlockEndOfCentral(), this.diskNumber === i.MAX_VALUE_16BITS || this.diskWithCentralDirStart === i.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === i.MAX_VALUE_16BITS || this.centralDirRecords === i.MAX_VALUE_16BITS || this.centralDirSize === i.MAX_VALUE_32BITS || this.centralDirOffset === i.MAX_VALUE_32BITS) {
  38772. if (this.zip64 = !0, (e = this.reader.lastIndexOfSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR)) < 0) throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");
  38773. if (this.reader.setIndex(e), this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR), this.readBlockZip64EndOfCentralLocator(), !this.isSignature(this.relativeOffsetEndOfZip64CentralDir, s.ZIP64_CENTRAL_DIRECTORY_END) && (this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(s.ZIP64_CENTRAL_DIRECTORY_END), this.relativeOffsetEndOfZip64CentralDir < 0)) throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");
  38774. this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir), this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_END), this.readBlockZip64EndOfCentral();
  38775. }
  38776. var r = this.centralDirOffset + this.centralDirSize;
  38777. this.zip64 && (r += 20, r += 12 + this.zip64EndOfCentralSize);
  38778. var n = t - r;
  38779. if (0 < n) this.isSignature(t, s.CENTRAL_FILE_HEADER) || (this.reader.zero = n);else if (n < 0) throw new Error("Corrupted zip: missing " + Math.abs(n) + " bytes.");
  38780. },
  38781. prepareReader: function (e) {
  38782. this.reader = n(e);
  38783. },
  38784. load: function (e) {
  38785. this.prepareReader(e), this.readEndOfCentral(), this.readCentralDir(), this.readLocalFiles();
  38786. }
  38787. }, t.exports = h;
  38788. }, {
  38789. "./reader/readerFor": 22,
  38790. "./signature": 23,
  38791. "./support": 30,
  38792. "./utils": 32,
  38793. "./zipEntry": 34
  38794. }],
  38795. 34: [function (e, t, r) {
  38796. "use strict";
  38797. var n = e("./reader/readerFor"),
  38798. s = e("./utils"),
  38799. i = e("./compressedObject"),
  38800. a = e("./crc32"),
  38801. o = e("./utf8"),
  38802. h = e("./compressions"),
  38803. u = e("./support");
  38804. function l(e, t) {
  38805. this.options = e, this.loadOptions = t;
  38806. }
  38807. l.prototype = {
  38808. isEncrypted: function () {
  38809. return 1 == (1 & this.bitFlag);
  38810. },
  38811. useUTF8: function () {
  38812. return 2048 == (2048 & this.bitFlag);
  38813. },
  38814. readLocalPart: function (e) {
  38815. var t, r;
  38816. if (e.skip(22), this.fileNameLength = e.readInt(2), r = e.readInt(2), this.fileName = e.readData(this.fileNameLength), e.skip(r), -1 === this.compressedSize || -1 === this.uncompressedSize) throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");
  38817. if (null === (t = function (e) {
  38818. for (var t in h) if (Object.prototype.hasOwnProperty.call(h, t) && h[t].magic === e) return h[t];
  38819. return null;
  38820. }(this.compressionMethod))) throw new Error("Corrupted zip : compression " + s.pretty(this.compressionMethod) + " unknown (inner file : " + s.transformTo("string", this.fileName) + ")");
  38821. this.decompressed = new i(this.compressedSize, this.uncompressedSize, this.crc32, t, e.readData(this.compressedSize));
  38822. },
  38823. readCentralPart: function (e) {
  38824. this.versionMadeBy = e.readInt(2), e.skip(2), this.bitFlag = e.readInt(2), this.compressionMethod = e.readString(2), this.date = e.readDate(), this.crc32 = e.readInt(4), this.compressedSize = e.readInt(4), this.uncompressedSize = e.readInt(4);
  38825. var t = e.readInt(2);
  38826. if (this.extraFieldsLength = e.readInt(2), this.fileCommentLength = e.readInt(2), this.diskNumberStart = e.readInt(2), this.internalFileAttributes = e.readInt(2), this.externalFileAttributes = e.readInt(4), this.localHeaderOffset = e.readInt(4), this.isEncrypted()) throw new Error("Encrypted zip are not supported");
  38827. e.skip(t), this.readExtraFields(e), this.parseZIP64ExtraField(e), this.fileComment = e.readData(this.fileCommentLength);
  38828. },
  38829. processAttributes: function () {
  38830. this.unixPermissions = null, this.dosPermissions = null;
  38831. var e = this.versionMadeBy >> 8;
  38832. this.dir = !!(16 & this.externalFileAttributes), 0 == e && (this.dosPermissions = 63 & this.externalFileAttributes), 3 == e && (this.unixPermissions = this.externalFileAttributes >> 16 & 65535), this.dir || "/" !== this.fileNameStr.slice(-1) || (this.dir = !0);
  38833. },
  38834. parseZIP64ExtraField: function () {
  38835. if (this.extraFields[1]) {
  38836. var e = n(this.extraFields[1].value);
  38837. this.uncompressedSize === s.MAX_VALUE_32BITS && (this.uncompressedSize = e.readInt(8)), this.compressedSize === s.MAX_VALUE_32BITS && (this.compressedSize = e.readInt(8)), this.localHeaderOffset === s.MAX_VALUE_32BITS && (this.localHeaderOffset = e.readInt(8)), this.diskNumberStart === s.MAX_VALUE_32BITS && (this.diskNumberStart = e.readInt(4));
  38838. }
  38839. },
  38840. readExtraFields: function (e) {
  38841. var t,
  38842. r,
  38843. n,
  38844. i = e.index + this.extraFieldsLength;
  38845. for (this.extraFields || (this.extraFields = {}); e.index + 4 < i;) t = e.readInt(2), r = e.readInt(2), n = e.readData(r), this.extraFields[t] = {
  38846. id: t,
  38847. length: r,
  38848. value: n
  38849. };
  38850. e.setIndex(i);
  38851. },
  38852. handleUTF8: function () {
  38853. var e = u.uint8array ? "uint8array" : "array";
  38854. if (this.useUTF8()) this.fileNameStr = o.utf8decode(this.fileName), this.fileCommentStr = o.utf8decode(this.fileComment);else {
  38855. var t = this.findExtraFieldUnicodePath();
  38856. if (null !== t) this.fileNameStr = t;else {
  38857. var r = s.transformTo(e, this.fileName);
  38858. this.fileNameStr = this.loadOptions.decodeFileName(r);
  38859. }
  38860. var n = this.findExtraFieldUnicodeComment();
  38861. if (null !== n) this.fileCommentStr = n;else {
  38862. var i = s.transformTo(e, this.fileComment);
  38863. this.fileCommentStr = this.loadOptions.decodeFileName(i);
  38864. }
  38865. }
  38866. },
  38867. findExtraFieldUnicodePath: function () {
  38868. var e = this.extraFields[28789];
  38869. if (e) {
  38870. var t = n(e.value);
  38871. return 1 !== t.readInt(1) ? null : a(this.fileName) !== t.readInt(4) ? null : o.utf8decode(t.readData(e.length - 5));
  38872. }
  38873. return null;
  38874. },
  38875. findExtraFieldUnicodeComment: function () {
  38876. var e = this.extraFields[25461];
  38877. if (e) {
  38878. var t = n(e.value);
  38879. return 1 !== t.readInt(1) ? null : a(this.fileComment) !== t.readInt(4) ? null : o.utf8decode(t.readData(e.length - 5));
  38880. }
  38881. return null;
  38882. }
  38883. }, t.exports = l;
  38884. }, {
  38885. "./compressedObject": 2,
  38886. "./compressions": 3,
  38887. "./crc32": 4,
  38888. "./reader/readerFor": 22,
  38889. "./support": 30,
  38890. "./utf8": 31,
  38891. "./utils": 32
  38892. }],
  38893. 35: [function (e, t, r) {
  38894. "use strict";
  38895. function n(e, t, r) {
  38896. this.name = e, this.dir = r.dir, this.date = r.date, this.comment = r.comment, this.unixPermissions = r.unixPermissions, this.dosPermissions = r.dosPermissions, this._data = t, this._dataBinary = r.binary, this.options = {
  38897. compression: r.compression,
  38898. compressionOptions: r.compressionOptions
  38899. };
  38900. }
  38901. var s = e("./stream/StreamHelper"),
  38902. i = e("./stream/DataWorker"),
  38903. a = e("./utf8"),
  38904. o = e("./compressedObject"),
  38905. h = e("./stream/GenericWorker");
  38906. n.prototype = {
  38907. internalStream: function (e) {
  38908. var t = null,
  38909. r = "string";
  38910. try {
  38911. if (!e) throw new Error("No output type specified.");
  38912. var n = "string" === (r = e.toLowerCase()) || "text" === r;
  38913. "binarystring" !== r && "text" !== r || (r = "string"), t = this._decompressWorker();
  38914. var i = !this._dataBinary;
  38915. i && !n && (t = t.pipe(new a.Utf8EncodeWorker())), !i && n && (t = t.pipe(new a.Utf8DecodeWorker()));
  38916. } catch (e) {
  38917. (t = new h("error")).error(e);
  38918. }
  38919. return new s(t, r, "");
  38920. },
  38921. async: function (e, t) {
  38922. return this.internalStream(e).accumulate(t);
  38923. },
  38924. nodeStream: function (e, t) {
  38925. return this.internalStream(e || "nodebuffer").toNodejsStream(t);
  38926. },
  38927. _compressWorker: function (e, t) {
  38928. if (this._data instanceof o && this._data.compression.magic === e.magic) return this._data.getCompressedWorker();
  38929. var r = this._decompressWorker();
  38930. return this._dataBinary || (r = r.pipe(new a.Utf8EncodeWorker())), o.createWorkerFrom(r, e, t);
  38931. },
  38932. _decompressWorker: function () {
  38933. return this._data instanceof o ? this._data.getContentWorker() : this._data instanceof h ? this._data : new i(this._data);
  38934. }
  38935. };
  38936. for (var u = ["asText", "asBinary", "asNodeBuffer", "asUint8Array", "asArrayBuffer"], l = function () {
  38937. throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
  38938. }, f = 0; f < u.length; f++) n.prototype[u[f]] = l;
  38939. t.exports = n;
  38940. }, {
  38941. "./compressedObject": 2,
  38942. "./stream/DataWorker": 27,
  38943. "./stream/GenericWorker": 28,
  38944. "./stream/StreamHelper": 29,
  38945. "./utf8": 31
  38946. }],
  38947. 36: [function (e, l, t) {
  38948. (function (t) {
  38949. "use strict";
  38950. var r,
  38951. n,
  38952. e = t.MutationObserver || t.WebKitMutationObserver;
  38953. if (e) {
  38954. var i = 0,
  38955. s = new e(u),
  38956. a = t.document.createTextNode("");
  38957. s.observe(a, {
  38958. characterData: !0
  38959. }), r = function () {
  38960. a.data = i = ++i % 2;
  38961. };
  38962. } else if (t.setImmediate || void 0 === t.MessageChannel) r = "document" in t && "onreadystatechange" in t.document.createElement("script") ? function () {
  38963. var e = t.document.createElement("script");
  38964. e.onreadystatechange = function () {
  38965. u(), e.onreadystatechange = null, e.parentNode.removeChild(e), e = null;
  38966. }, t.document.documentElement.appendChild(e);
  38967. } : function () {
  38968. setTimeout(u, 0);
  38969. };else {
  38970. var o = new t.MessageChannel();
  38971. o.port1.onmessage = u, r = function () {
  38972. o.port2.postMessage(0);
  38973. };
  38974. }
  38975. var h = [];
  38976. function u() {
  38977. var e, t;
  38978. n = !0;
  38979. for (var r = h.length; r;) {
  38980. for (t = h, h = [], e = -1; ++e < r;) t[e]();
  38981. r = h.length;
  38982. }
  38983. n = !1;
  38984. }
  38985. l.exports = function (e) {
  38986. 1 !== h.push(e) || n || r();
  38987. };
  38988. }).call(this, "undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {});
  38989. }, {}],
  38990. 37: [function (e, t, r) {
  38991. "use strict";
  38992. var i = e("immediate");
  38993. function u() {}
  38994. var l = {},
  38995. s = ["REJECTED"],
  38996. a = ["FULFILLED"],
  38997. n = ["PENDING"];
  38998. function o(e) {
  38999. if ("function" != typeof e) throw new TypeError("resolver must be a function");
  39000. this.state = n, this.queue = [], this.outcome = void 0, e !== u && d(this, e);
  39001. }
  39002. function h(e, t, r) {
  39003. this.promise = e, "function" == typeof t && (this.onFulfilled = t, this.callFulfilled = this.otherCallFulfilled), "function" == typeof r && (this.onRejected = r, this.callRejected = this.otherCallRejected);
  39004. }
  39005. function f(t, r, n) {
  39006. i(function () {
  39007. var e;
  39008. try {
  39009. e = r(n);
  39010. } catch (e) {
  39011. return l.reject(t, e);
  39012. }
  39013. e === t ? l.reject(t, new TypeError("Cannot resolve promise with itself")) : l.resolve(t, e);
  39014. });
  39015. }
  39016. function c(e) {
  39017. var t = e && e.then;
  39018. if (e && ("object" == typeof e || "function" == typeof e) && "function" == typeof t) return function () {
  39019. t.apply(e, arguments);
  39020. };
  39021. }
  39022. function d(t, e) {
  39023. var r = !1;
  39024. function n(e) {
  39025. r || (r = !0, l.reject(t, e));
  39026. }
  39027. function i(e) {
  39028. r || (r = !0, l.resolve(t, e));
  39029. }
  39030. var s = p(function () {
  39031. e(i, n);
  39032. });
  39033. "error" === s.status && n(s.value);
  39034. }
  39035. function p(e, t) {
  39036. var r = {};
  39037. try {
  39038. r.value = e(t), r.status = "success";
  39039. } catch (e) {
  39040. r.status = "error", r.value = e;
  39041. }
  39042. return r;
  39043. }
  39044. (t.exports = o).prototype.finally = function (t) {
  39045. if ("function" != typeof t) return this;
  39046. var r = this.constructor;
  39047. return this.then(function (e) {
  39048. return r.resolve(t()).then(function () {
  39049. return e;
  39050. });
  39051. }, function (e) {
  39052. return r.resolve(t()).then(function () {
  39053. throw e;
  39054. });
  39055. });
  39056. }, o.prototype.catch = function (e) {
  39057. return this.then(null, e);
  39058. }, o.prototype.then = function (e, t) {
  39059. if ("function" != typeof e && this.state === a || "function" != typeof t && this.state === s) return this;
  39060. var r = new this.constructor(u);
  39061. this.state !== n ? f(r, this.state === a ? e : t, this.outcome) : this.queue.push(new h(r, e, t));
  39062. return r;
  39063. }, h.prototype.callFulfilled = function (e) {
  39064. l.resolve(this.promise, e);
  39065. }, h.prototype.otherCallFulfilled = function (e) {
  39066. f(this.promise, this.onFulfilled, e);
  39067. }, h.prototype.callRejected = function (e) {
  39068. l.reject(this.promise, e);
  39069. }, h.prototype.otherCallRejected = function (e) {
  39070. f(this.promise, this.onRejected, e);
  39071. }, l.resolve = function (e, t) {
  39072. var r = p(c, t);
  39073. if ("error" === r.status) return l.reject(e, r.value);
  39074. var n = r.value;
  39075. if (n) d(e, n);else {
  39076. e.state = a, e.outcome = t;
  39077. for (var i = -1, s = e.queue.length; ++i < s;) e.queue[i].callFulfilled(t);
  39078. }
  39079. return e;
  39080. }, l.reject = function (e, t) {
  39081. e.state = s, e.outcome = t;
  39082. for (var r = -1, n = e.queue.length; ++r < n;) e.queue[r].callRejected(t);
  39083. return e;
  39084. }, o.resolve = function (e) {
  39085. if (e instanceof this) return e;
  39086. return l.resolve(new this(u), e);
  39087. }, o.reject = function (e) {
  39088. var t = new this(u);
  39089. return l.reject(t, e);
  39090. }, o.all = function (e) {
  39091. var r = this;
  39092. if ("[object Array]" !== Object.prototype.toString.call(e)) return this.reject(new TypeError("must be an array"));
  39093. var n = e.length,
  39094. i = !1;
  39095. if (!n) return this.resolve([]);
  39096. var s = new Array(n),
  39097. a = 0,
  39098. t = -1,
  39099. o = new this(u);
  39100. for (; ++t < n;) h(e[t], t);
  39101. return o;
  39102. function h(e, t) {
  39103. r.resolve(e).then(function (e) {
  39104. s[t] = e, ++a !== n || i || (i = !0, l.resolve(o, s));
  39105. }, function (e) {
  39106. i || (i = !0, l.reject(o, e));
  39107. });
  39108. }
  39109. }, o.race = function (e) {
  39110. var t = this;
  39111. if ("[object Array]" !== Object.prototype.toString.call(e)) return this.reject(new TypeError("must be an array"));
  39112. var r = e.length,
  39113. n = !1;
  39114. if (!r) return this.resolve([]);
  39115. var i = -1,
  39116. s = new this(u);
  39117. for (; ++i < r;) a = e[i], t.resolve(a).then(function (e) {
  39118. n || (n = !0, l.resolve(s, e));
  39119. }, function (e) {
  39120. n || (n = !0, l.reject(s, e));
  39121. });
  39122. var a;
  39123. return s;
  39124. };
  39125. }, {
  39126. immediate: 36
  39127. }],
  39128. 38: [function (e, t, r) {
  39129. "use strict";
  39130. var n = {};
  39131. (0, e("./lib/utils/common").assign)(n, e("./lib/deflate"), e("./lib/inflate"), e("./lib/zlib/constants")), t.exports = n;
  39132. }, {
  39133. "./lib/deflate": 39,
  39134. "./lib/inflate": 40,
  39135. "./lib/utils/common": 41,
  39136. "./lib/zlib/constants": 44
  39137. }],
  39138. 39: [function (e, t, r) {
  39139. "use strict";
  39140. var a = e("./zlib/deflate"),
  39141. o = e("./utils/common"),
  39142. h = e("./utils/strings"),
  39143. i = e("./zlib/messages"),
  39144. s = e("./zlib/zstream"),
  39145. u = Object.prototype.toString,
  39146. l = 0,
  39147. f = -1,
  39148. c = 0,
  39149. d = 8;
  39150. function p(e) {
  39151. if (!(this instanceof p)) return new p(e);
  39152. this.options = o.assign({
  39153. level: f,
  39154. method: d,
  39155. chunkSize: 16384,
  39156. windowBits: 15,
  39157. memLevel: 8,
  39158. strategy: c,
  39159. to: ""
  39160. }, e || {});
  39161. var t = this.options;
  39162. t.raw && 0 < t.windowBits ? t.windowBits = -t.windowBits : t.gzip && 0 < t.windowBits && t.windowBits < 16 && (t.windowBits += 16), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new s(), this.strm.avail_out = 0;
  39163. var r = a.deflateInit2(this.strm, t.level, t.method, t.windowBits, t.memLevel, t.strategy);
  39164. if (r !== l) throw new Error(i[r]);
  39165. if (t.header && a.deflateSetHeader(this.strm, t.header), t.dictionary) {
  39166. var n;
  39167. if (n = "string" == typeof t.dictionary ? h.string2buf(t.dictionary) : "[object ArrayBuffer]" === u.call(t.dictionary) ? new Uint8Array(t.dictionary) : t.dictionary, (r = a.deflateSetDictionary(this.strm, n)) !== l) throw new Error(i[r]);
  39168. this._dict_set = !0;
  39169. }
  39170. }
  39171. function n(e, t) {
  39172. var r = new p(t);
  39173. if (r.push(e, !0), r.err) throw r.msg || i[r.err];
  39174. return r.result;
  39175. }
  39176. p.prototype.push = function (e, t) {
  39177. var r,
  39178. n,
  39179. i = this.strm,
  39180. s = this.options.chunkSize;
  39181. if (this.ended) return !1;
  39182. n = t === ~~t ? t : !0 === t ? 4 : 0, "string" == typeof e ? i.input = h.string2buf(e) : "[object ArrayBuffer]" === u.call(e) ? i.input = new Uint8Array(e) : i.input = e, i.next_in = 0, i.avail_in = i.input.length;
  39183. do {
  39184. if (0 === i.avail_out && (i.output = new o.Buf8(s), i.next_out = 0, i.avail_out = s), 1 !== (r = a.deflate(i, n)) && r !== l) return this.onEnd(r), !(this.ended = !0);
  39185. 0 !== i.avail_out && (0 !== i.avail_in || 4 !== n && 2 !== n) || ("string" === this.options.to ? this.onData(h.buf2binstring(o.shrinkBuf(i.output, i.next_out))) : this.onData(o.shrinkBuf(i.output, i.next_out)));
  39186. } while ((0 < i.avail_in || 0 === i.avail_out) && 1 !== r);
  39187. return 4 === n ? (r = a.deflateEnd(this.strm), this.onEnd(r), this.ended = !0, r === l) : 2 !== n || (this.onEnd(l), !(i.avail_out = 0));
  39188. }, p.prototype.onData = function (e) {
  39189. this.chunks.push(e);
  39190. }, p.prototype.onEnd = function (e) {
  39191. e === l && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = o.flattenChunks(this.chunks)), this.chunks = [], this.err = e, this.msg = this.strm.msg;
  39192. }, r.Deflate = p, r.deflate = n, r.deflateRaw = function (e, t) {
  39193. return (t = t || {}).raw = !0, n(e, t);
  39194. }, r.gzip = function (e, t) {
  39195. return (t = t || {}).gzip = !0, n(e, t);
  39196. };
  39197. }, {
  39198. "./utils/common": 41,
  39199. "./utils/strings": 42,
  39200. "./zlib/deflate": 46,
  39201. "./zlib/messages": 51,
  39202. "./zlib/zstream": 53
  39203. }],
  39204. 40: [function (e, t, r) {
  39205. "use strict";
  39206. var c = e("./zlib/inflate"),
  39207. d = e("./utils/common"),
  39208. p = e("./utils/strings"),
  39209. m = e("./zlib/constants"),
  39210. n = e("./zlib/messages"),
  39211. i = e("./zlib/zstream"),
  39212. s = e("./zlib/gzheader"),
  39213. _ = Object.prototype.toString;
  39214. function a(e) {
  39215. if (!(this instanceof a)) return new a(e);
  39216. this.options = d.assign({
  39217. chunkSize: 16384,
  39218. windowBits: 0,
  39219. to: ""
  39220. }, e || {});
  39221. var t = this.options;
  39222. t.raw && 0 <= t.windowBits && t.windowBits < 16 && (t.windowBits = -t.windowBits, 0 === t.windowBits && (t.windowBits = -15)), !(0 <= t.windowBits && t.windowBits < 16) || e && e.windowBits || (t.windowBits += 32), 15 < t.windowBits && t.windowBits < 48 && 0 == (15 & t.windowBits) && (t.windowBits |= 15), this.err = 0, this.msg = "", this.ended = !1, this.chunks = [], this.strm = new i(), this.strm.avail_out = 0;
  39223. var r = c.inflateInit2(this.strm, t.windowBits);
  39224. if (r !== m.Z_OK) throw new Error(n[r]);
  39225. this.header = new s(), c.inflateGetHeader(this.strm, this.header);
  39226. }
  39227. function o(e, t) {
  39228. var r = new a(t);
  39229. if (r.push(e, !0), r.err) throw r.msg || n[r.err];
  39230. return r.result;
  39231. }
  39232. a.prototype.push = function (e, t) {
  39233. var r,
  39234. n,
  39235. i,
  39236. s,
  39237. a,
  39238. o,
  39239. h = this.strm,
  39240. u = this.options.chunkSize,
  39241. l = this.options.dictionary,
  39242. f = !1;
  39243. if (this.ended) return !1;
  39244. n = t === ~~t ? t : !0 === t ? m.Z_FINISH : m.Z_NO_FLUSH, "string" == typeof e ? h.input = p.binstring2buf(e) : "[object ArrayBuffer]" === _.call(e) ? h.input = new Uint8Array(e) : h.input = e, h.next_in = 0, h.avail_in = h.input.length;
  39245. do {
  39246. if (0 === h.avail_out && (h.output = new d.Buf8(u), h.next_out = 0, h.avail_out = u), (r = c.inflate(h, m.Z_NO_FLUSH)) === m.Z_NEED_DICT && l && (o = "string" == typeof l ? p.string2buf(l) : "[object ArrayBuffer]" === _.call(l) ? new Uint8Array(l) : l, r = c.inflateSetDictionary(this.strm, o)), r === m.Z_BUF_ERROR && !0 === f && (r = m.Z_OK, f = !1), r !== m.Z_STREAM_END && r !== m.Z_OK) return this.onEnd(r), !(this.ended = !0);
  39247. h.next_out && (0 !== h.avail_out && r !== m.Z_STREAM_END && (0 !== h.avail_in || n !== m.Z_FINISH && n !== m.Z_SYNC_FLUSH) || ("string" === this.options.to ? (i = p.utf8border(h.output, h.next_out), s = h.next_out - i, a = p.buf2string(h.output, i), h.next_out = s, h.avail_out = u - s, s && d.arraySet(h.output, h.output, i, s, 0), this.onData(a)) : this.onData(d.shrinkBuf(h.output, h.next_out)))), 0 === h.avail_in && 0 === h.avail_out && (f = !0);
  39248. } while ((0 < h.avail_in || 0 === h.avail_out) && r !== m.Z_STREAM_END);
  39249. return r === m.Z_STREAM_END && (n = m.Z_FINISH), n === m.Z_FINISH ? (r = c.inflateEnd(this.strm), this.onEnd(r), this.ended = !0, r === m.Z_OK) : n !== m.Z_SYNC_FLUSH || (this.onEnd(m.Z_OK), !(h.avail_out = 0));
  39250. }, a.prototype.onData = function (e) {
  39251. this.chunks.push(e);
  39252. }, a.prototype.onEnd = function (e) {
  39253. e === m.Z_OK && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = d.flattenChunks(this.chunks)), this.chunks = [], this.err = e, this.msg = this.strm.msg;
  39254. }, r.Inflate = a, r.inflate = o, r.inflateRaw = function (e, t) {
  39255. return (t = t || {}).raw = !0, o(e, t);
  39256. }, r.ungzip = o;
  39257. }, {
  39258. "./utils/common": 41,
  39259. "./utils/strings": 42,
  39260. "./zlib/constants": 44,
  39261. "./zlib/gzheader": 47,
  39262. "./zlib/inflate": 49,
  39263. "./zlib/messages": 51,
  39264. "./zlib/zstream": 53
  39265. }],
  39266. 41: [function (e, t, r) {
  39267. "use strict";
  39268. var n = "undefined" != typeof Uint8Array && "undefined" != typeof Uint16Array && "undefined" != typeof Int32Array;
  39269. r.assign = function (e) {
  39270. for (var t = Array.prototype.slice.call(arguments, 1); t.length;) {
  39271. var r = t.shift();
  39272. if (r) {
  39273. if ("object" != typeof r) throw new TypeError(r + "must be non-object");
  39274. for (var n in r) r.hasOwnProperty(n) && (e[n] = r[n]);
  39275. }
  39276. }
  39277. return e;
  39278. }, r.shrinkBuf = function (e, t) {
  39279. return e.length === t ? e : e.subarray ? e.subarray(0, t) : (e.length = t, e);
  39280. };
  39281. var i = {
  39282. arraySet: function (e, t, r, n, i) {
  39283. if (t.subarray && e.subarray) e.set(t.subarray(r, r + n), i);else for (var s = 0; s < n; s++) e[i + s] = t[r + s];
  39284. },
  39285. flattenChunks: function (e) {
  39286. var t, r, n, i, s, a;
  39287. for (t = n = 0, r = e.length; t < r; t++) n += e[t].length;
  39288. for (a = new Uint8Array(n), t = i = 0, r = e.length; t < r; t++) s = e[t], a.set(s, i), i += s.length;
  39289. return a;
  39290. }
  39291. },
  39292. s = {
  39293. arraySet: function (e, t, r, n, i) {
  39294. for (var s = 0; s < n; s++) e[i + s] = t[r + s];
  39295. },
  39296. flattenChunks: function (e) {
  39297. return [].concat.apply([], e);
  39298. }
  39299. };
  39300. r.setTyped = function (e) {
  39301. e ? (r.Buf8 = Uint8Array, r.Buf16 = Uint16Array, r.Buf32 = Int32Array, r.assign(r, i)) : (r.Buf8 = Array, r.Buf16 = Array, r.Buf32 = Array, r.assign(r, s));
  39302. }, r.setTyped(n);
  39303. }, {}],
  39304. 42: [function (e, t, r) {
  39305. "use strict";
  39306. var h = e("./common"),
  39307. i = !0,
  39308. s = !0;
  39309. try {
  39310. String.fromCharCode.apply(null, [0]);
  39311. } catch (e) {
  39312. i = !1;
  39313. }
  39314. try {
  39315. String.fromCharCode.apply(null, new Uint8Array(1));
  39316. } catch (e) {
  39317. s = !1;
  39318. }
  39319. for (var u = new h.Buf8(256), n = 0; n < 256; n++) u[n] = 252 <= n ? 6 : 248 <= n ? 5 : 240 <= n ? 4 : 224 <= n ? 3 : 192 <= n ? 2 : 1;
  39320. function l(e, t) {
  39321. if (t < 65537 && (e.subarray && s || !e.subarray && i)) return String.fromCharCode.apply(null, h.shrinkBuf(e, t));
  39322. for (var r = "", n = 0; n < t; n++) r += String.fromCharCode(e[n]);
  39323. return r;
  39324. }
  39325. u[254] = u[254] = 1, r.string2buf = function (e) {
  39326. var t,
  39327. r,
  39328. n,
  39329. i,
  39330. s,
  39331. a = e.length,
  39332. o = 0;
  39333. for (i = 0; i < a; i++) 55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), o += r < 128 ? 1 : r < 2048 ? 2 : r < 65536 ? 3 : 4;
  39334. for (t = new h.Buf8(o), i = s = 0; s < o; i++) 55296 == (64512 & (r = e.charCodeAt(i))) && i + 1 < a && 56320 == (64512 & (n = e.charCodeAt(i + 1))) && (r = 65536 + (r - 55296 << 10) + (n - 56320), i++), r < 128 ? t[s++] = r : (r < 2048 ? t[s++] = 192 | r >>> 6 : (r < 65536 ? t[s++] = 224 | r >>> 12 : (t[s++] = 240 | r >>> 18, t[s++] = 128 | r >>> 12 & 63), t[s++] = 128 | r >>> 6 & 63), t[s++] = 128 | 63 & r);
  39335. return t;
  39336. }, r.buf2binstring = function (e) {
  39337. return l(e, e.length);
  39338. }, r.binstring2buf = function (e) {
  39339. for (var t = new h.Buf8(e.length), r = 0, n = t.length; r < n; r++) t[r] = e.charCodeAt(r);
  39340. return t;
  39341. }, r.buf2string = function (e, t) {
  39342. var r,
  39343. n,
  39344. i,
  39345. s,
  39346. a = t || e.length,
  39347. o = new Array(2 * a);
  39348. for (r = n = 0; r < a;) if ((i = e[r++]) < 128) o[n++] = i;else if (4 < (s = u[i])) o[n++] = 65533, r += s - 1;else {
  39349. for (i &= 2 === s ? 31 : 3 === s ? 15 : 7; 1 < s && r < a;) i = i << 6 | 63 & e[r++], s--;
  39350. 1 < s ? o[n++] = 65533 : i < 65536 ? o[n++] = i : (i -= 65536, o[n++] = 55296 | i >> 10 & 1023, o[n++] = 56320 | 1023 & i);
  39351. }
  39352. return l(o, n);
  39353. }, r.utf8border = function (e, t) {
  39354. var r;
  39355. for ((t = t || e.length) > e.length && (t = e.length), r = t - 1; 0 <= r && 128 == (192 & e[r]);) r--;
  39356. return r < 0 ? t : 0 === r ? t : r + u[e[r]] > t ? r : t;
  39357. };
  39358. }, {
  39359. "./common": 41
  39360. }],
  39361. 43: [function (e, t, r) {
  39362. "use strict";
  39363. t.exports = function (e, t, r, n) {
  39364. for (var i = 65535 & e | 0, s = e >>> 16 & 65535 | 0, a = 0; 0 !== r;) {
  39365. for (r -= a = 2e3 < r ? 2e3 : r; s = s + (i = i + t[n++] | 0) | 0, --a;);
  39366. i %= 65521, s %= 65521;
  39367. }
  39368. return i | s << 16 | 0;
  39369. };
  39370. }, {}],
  39371. 44: [function (e, t, r) {
  39372. "use strict";
  39373. t.exports = {
  39374. Z_NO_FLUSH: 0,
  39375. Z_PARTIAL_FLUSH: 1,
  39376. Z_SYNC_FLUSH: 2,
  39377. Z_FULL_FLUSH: 3,
  39378. Z_FINISH: 4,
  39379. Z_BLOCK: 5,
  39380. Z_TREES: 6,
  39381. Z_OK: 0,
  39382. Z_STREAM_END: 1,
  39383. Z_NEED_DICT: 2,
  39384. Z_ERRNO: -1,
  39385. Z_STREAM_ERROR: -2,
  39386. Z_DATA_ERROR: -3,
  39387. Z_BUF_ERROR: -5,
  39388. Z_NO_COMPRESSION: 0,
  39389. Z_BEST_SPEED: 1,
  39390. Z_BEST_COMPRESSION: 9,
  39391. Z_DEFAULT_COMPRESSION: -1,
  39392. Z_FILTERED: 1,
  39393. Z_HUFFMAN_ONLY: 2,
  39394. Z_RLE: 3,
  39395. Z_FIXED: 4,
  39396. Z_DEFAULT_STRATEGY: 0,
  39397. Z_BINARY: 0,
  39398. Z_TEXT: 1,
  39399. Z_UNKNOWN: 2,
  39400. Z_DEFLATED: 8
  39401. };
  39402. }, {}],
  39403. 45: [function (e, t, r) {
  39404. "use strict";
  39405. var o = function () {
  39406. for (var e, t = [], r = 0; r < 256; r++) {
  39407. e = r;
  39408. for (var n = 0; n < 8; n++) e = 1 & e ? 3988292384 ^ e >>> 1 : e >>> 1;
  39409. t[r] = e;
  39410. }
  39411. return t;
  39412. }();
  39413. t.exports = function (e, t, r, n) {
  39414. var i = o,
  39415. s = n + r;
  39416. e ^= -1;
  39417. for (var a = n; a < s; a++) e = e >>> 8 ^ i[255 & (e ^ t[a])];
  39418. return -1 ^ e;
  39419. };
  39420. }, {}],
  39421. 46: [function (e, t, r) {
  39422. "use strict";
  39423. var h,
  39424. c = e("../utils/common"),
  39425. u = e("./trees"),
  39426. d = e("./adler32"),
  39427. p = e("./crc32"),
  39428. n = e("./messages"),
  39429. l = 0,
  39430. f = 4,
  39431. m = 0,
  39432. _ = -2,
  39433. g = -1,
  39434. b = 4,
  39435. i = 2,
  39436. v = 8,
  39437. y = 9,
  39438. s = 286,
  39439. a = 30,
  39440. o = 19,
  39441. w = 2 * s + 1,
  39442. k = 15,
  39443. x = 3,
  39444. S = 258,
  39445. z = S + x + 1,
  39446. C = 42,
  39447. E = 113,
  39448. A = 1,
  39449. I = 2,
  39450. O = 3,
  39451. B = 4;
  39452. function R(e, t) {
  39453. return e.msg = n[t], t;
  39454. }
  39455. function T(e) {
  39456. return (e << 1) - (4 < e ? 9 : 0);
  39457. }
  39458. function D(e) {
  39459. for (var t = e.length; 0 <= --t;) e[t] = 0;
  39460. }
  39461. function F(e) {
  39462. var t = e.state,
  39463. r = t.pending;
  39464. r > e.avail_out && (r = e.avail_out), 0 !== r && (c.arraySet(e.output, t.pending_buf, t.pending_out, r, e.next_out), e.next_out += r, t.pending_out += r, e.total_out += r, e.avail_out -= r, t.pending -= r, 0 === t.pending && (t.pending_out = 0));
  39465. }
  39466. function N(e, t) {
  39467. u._tr_flush_block(e, 0 <= e.block_start ? e.block_start : -1, e.strstart - e.block_start, t), e.block_start = e.strstart, F(e.strm);
  39468. }
  39469. function U(e, t) {
  39470. e.pending_buf[e.pending++] = t;
  39471. }
  39472. function P(e, t) {
  39473. e.pending_buf[e.pending++] = t >>> 8 & 255, e.pending_buf[e.pending++] = 255 & t;
  39474. }
  39475. function L(e, t) {
  39476. var r,
  39477. n,
  39478. i = e.max_chain_length,
  39479. s = e.strstart,
  39480. a = e.prev_length,
  39481. o = e.nice_match,
  39482. h = e.strstart > e.w_size - z ? e.strstart - (e.w_size - z) : 0,
  39483. u = e.window,
  39484. l = e.w_mask,
  39485. f = e.prev,
  39486. c = e.strstart + S,
  39487. d = u[s + a - 1],
  39488. p = u[s + a];
  39489. e.prev_length >= e.good_match && (i >>= 2), o > e.lookahead && (o = e.lookahead);
  39490. do {
  39491. if (u[(r = t) + a] === p && u[r + a - 1] === d && u[r] === u[s] && u[++r] === u[s + 1]) {
  39492. s += 2, r++;
  39493. do {} while (u[++s] === u[++r] && u[++s] === u[++r] && u[++s] === u[++r] && u[++s] === u[++r] && u[++s] === u[++r] && u[++s] === u[++r] && u[++s] === u[++r] && u[++s] === u[++r] && s < c);
  39494. if (n = S - (c - s), s = c - S, a < n) {
  39495. if (e.match_start = t, o <= (a = n)) break;
  39496. d = u[s + a - 1], p = u[s + a];
  39497. }
  39498. }
  39499. } while ((t = f[t & l]) > h && 0 != --i);
  39500. return a <= e.lookahead ? a : e.lookahead;
  39501. }
  39502. function j(e) {
  39503. var t,
  39504. r,
  39505. n,
  39506. i,
  39507. s,
  39508. a,
  39509. o,
  39510. h,
  39511. u,
  39512. l,
  39513. f = e.w_size;
  39514. do {
  39515. if (i = e.window_size - e.lookahead - e.strstart, e.strstart >= f + (f - z)) {
  39516. for (c.arraySet(e.window, e.window, f, f, 0), e.match_start -= f, e.strstart -= f, e.block_start -= f, t = r = e.hash_size; n = e.head[--t], e.head[t] = f <= n ? n - f : 0, --r;);
  39517. for (t = r = f; n = e.prev[--t], e.prev[t] = f <= n ? n - f : 0, --r;);
  39518. i += f;
  39519. }
  39520. if (0 === e.strm.avail_in) break;
  39521. if (a = e.strm, o = e.window, h = e.strstart + e.lookahead, u = i, l = void 0, l = a.avail_in, u < l && (l = u), r = 0 === l ? 0 : (a.avail_in -= l, c.arraySet(o, a.input, a.next_in, l, h), 1 === a.state.wrap ? a.adler = d(a.adler, o, l, h) : 2 === a.state.wrap && (a.adler = p(a.adler, o, l, h)), a.next_in += l, a.total_in += l, l), e.lookahead += r, e.lookahead + e.insert >= x) for (s = e.strstart - e.insert, e.ins_h = e.window[s], e.ins_h = (e.ins_h << e.hash_shift ^ e.window[s + 1]) & e.hash_mask; e.insert && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[s + x - 1]) & e.hash_mask, e.prev[s & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = s, s++, e.insert--, !(e.lookahead + e.insert < x)););
  39522. } while (e.lookahead < z && 0 !== e.strm.avail_in);
  39523. }
  39524. function Z(e, t) {
  39525. for (var r, n;;) {
  39526. if (e.lookahead < z) {
  39527. if (j(e), e.lookahead < z && t === l) return A;
  39528. if (0 === e.lookahead) break;
  39529. }
  39530. if (r = 0, e.lookahead >= x && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + x - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart), 0 !== r && e.strstart - r <= e.w_size - z && (e.match_length = L(e, r)), e.match_length >= x) {
  39531. if (n = u._tr_tally(e, e.strstart - e.match_start, e.match_length - x), e.lookahead -= e.match_length, e.match_length <= e.max_lazy_match && e.lookahead >= x) {
  39532. for (e.match_length--; e.strstart++, e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + x - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart, 0 != --e.match_length;);
  39533. e.strstart++;
  39534. } else e.strstart += e.match_length, e.match_length = 0, e.ins_h = e.window[e.strstart], e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + 1]) & e.hash_mask;
  39535. } else n = u._tr_tally(e, 0, e.window[e.strstart]), e.lookahead--, e.strstart++;
  39536. if (n && (N(e, !1), 0 === e.strm.avail_out)) return A;
  39537. }
  39538. return e.insert = e.strstart < x - 1 ? e.strstart : x - 1, t === f ? (N(e, !0), 0 === e.strm.avail_out ? O : B) : e.last_lit && (N(e, !1), 0 === e.strm.avail_out) ? A : I;
  39539. }
  39540. function W(e, t) {
  39541. for (var r, n, i;;) {
  39542. if (e.lookahead < z) {
  39543. if (j(e), e.lookahead < z && t === l) return A;
  39544. if (0 === e.lookahead) break;
  39545. }
  39546. if (r = 0, e.lookahead >= x && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + x - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart), e.prev_length = e.match_length, e.prev_match = e.match_start, e.match_length = x - 1, 0 !== r && e.prev_length < e.max_lazy_match && e.strstart - r <= e.w_size - z && (e.match_length = L(e, r), e.match_length <= 5 && (1 === e.strategy || e.match_length === x && 4096 < e.strstart - e.match_start) && (e.match_length = x - 1)), e.prev_length >= x && e.match_length <= e.prev_length) {
  39547. for (i = e.strstart + e.lookahead - x, n = u._tr_tally(e, e.strstart - 1 - e.prev_match, e.prev_length - x), e.lookahead -= e.prev_length - 1, e.prev_length -= 2; ++e.strstart <= i && (e.ins_h = (e.ins_h << e.hash_shift ^ e.window[e.strstart + x - 1]) & e.hash_mask, r = e.prev[e.strstart & e.w_mask] = e.head[e.ins_h], e.head[e.ins_h] = e.strstart), 0 != --e.prev_length;);
  39548. if (e.match_available = 0, e.match_length = x - 1, e.strstart++, n && (N(e, !1), 0 === e.strm.avail_out)) return A;
  39549. } else if (e.match_available) {
  39550. if ((n = u._tr_tally(e, 0, e.window[e.strstart - 1])) && N(e, !1), e.strstart++, e.lookahead--, 0 === e.strm.avail_out) return A;
  39551. } else e.match_available = 1, e.strstart++, e.lookahead--;
  39552. }
  39553. return e.match_available && (n = u._tr_tally(e, 0, e.window[e.strstart - 1]), e.match_available = 0), e.insert = e.strstart < x - 1 ? e.strstart : x - 1, t === f ? (N(e, !0), 0 === e.strm.avail_out ? O : B) : e.last_lit && (N(e, !1), 0 === e.strm.avail_out) ? A : I;
  39554. }
  39555. function M(e, t, r, n, i) {
  39556. this.good_length = e, this.max_lazy = t, this.nice_length = r, this.max_chain = n, this.func = i;
  39557. }
  39558. function H() {
  39559. this.strm = null, this.status = 0, this.pending_buf = null, this.pending_buf_size = 0, this.pending_out = 0, this.pending = 0, this.wrap = 0, this.gzhead = null, this.gzindex = 0, this.method = v, this.last_flush = -1, this.w_size = 0, this.w_bits = 0, this.w_mask = 0, this.window = null, this.window_size = 0, this.prev = null, this.head = null, this.ins_h = 0, this.hash_size = 0, this.hash_bits = 0, this.hash_mask = 0, this.hash_shift = 0, this.block_start = 0, this.match_length = 0, this.prev_match = 0, this.match_available = 0, this.strstart = 0, this.match_start = 0, this.lookahead = 0, this.prev_length = 0, this.max_chain_length = 0, this.max_lazy_match = 0, this.level = 0, this.strategy = 0, this.good_match = 0, this.nice_match = 0, this.dyn_ltree = new c.Buf16(2 * w), this.dyn_dtree = new c.Buf16(2 * (2 * a + 1)), this.bl_tree = new c.Buf16(2 * (2 * o + 1)), D(this.dyn_ltree), D(this.dyn_dtree), D(this.bl_tree), this.l_desc = null, this.d_desc = null, this.bl_desc = null, this.bl_count = new c.Buf16(k + 1), this.heap = new c.Buf16(2 * s + 1), D(this.heap), this.heap_len = 0, this.heap_max = 0, this.depth = new c.Buf16(2 * s + 1), D(this.depth), this.l_buf = 0, this.lit_bufsize = 0, this.last_lit = 0, this.d_buf = 0, this.opt_len = 0, this.static_len = 0, this.matches = 0, this.insert = 0, this.bi_buf = 0, this.bi_valid = 0;
  39560. }
  39561. function G(e) {
  39562. var t;
  39563. return e && e.state ? (e.total_in = e.total_out = 0, e.data_type = i, (t = e.state).pending = 0, t.pending_out = 0, t.wrap < 0 && (t.wrap = -t.wrap), t.status = t.wrap ? C : E, e.adler = 2 === t.wrap ? 0 : 1, t.last_flush = l, u._tr_init(t), m) : R(e, _);
  39564. }
  39565. function K(e) {
  39566. var t = G(e);
  39567. return t === m && function (e) {
  39568. e.window_size = 2 * e.w_size, D(e.head), e.max_lazy_match = h[e.level].max_lazy, e.good_match = h[e.level].good_length, e.nice_match = h[e.level].nice_length, e.max_chain_length = h[e.level].max_chain, e.strstart = 0, e.block_start = 0, e.lookahead = 0, e.insert = 0, e.match_length = e.prev_length = x - 1, e.match_available = 0, e.ins_h = 0;
  39569. }(e.state), t;
  39570. }
  39571. function Y(e, t, r, n, i, s) {
  39572. if (!e) return _;
  39573. var a = 1;
  39574. if (t === g && (t = 6), n < 0 ? (a = 0, n = -n) : 15 < n && (a = 2, n -= 16), i < 1 || y < i || r !== v || n < 8 || 15 < n || t < 0 || 9 < t || s < 0 || b < s) return R(e, _);
  39575. 8 === n && (n = 9);
  39576. var o = new H();
  39577. return (e.state = o).strm = e, o.wrap = a, o.gzhead = null, o.w_bits = n, o.w_size = 1 << o.w_bits, o.w_mask = o.w_size - 1, o.hash_bits = i + 7, o.hash_size = 1 << o.hash_bits, o.hash_mask = o.hash_size - 1, o.hash_shift = ~~((o.hash_bits + x - 1) / x), o.window = new c.Buf8(2 * o.w_size), o.head = new c.Buf16(o.hash_size), o.prev = new c.Buf16(o.w_size), o.lit_bufsize = 1 << i + 6, o.pending_buf_size = 4 * o.lit_bufsize, o.pending_buf = new c.Buf8(o.pending_buf_size), o.d_buf = 1 * o.lit_bufsize, o.l_buf = 3 * o.lit_bufsize, o.level = t, o.strategy = s, o.method = r, K(e);
  39578. }
  39579. h = [new M(0, 0, 0, 0, function (e, t) {
  39580. var r = 65535;
  39581. for (r > e.pending_buf_size - 5 && (r = e.pending_buf_size - 5);;) {
  39582. if (e.lookahead <= 1) {
  39583. if (j(e), 0 === e.lookahead && t === l) return A;
  39584. if (0 === e.lookahead) break;
  39585. }
  39586. e.strstart += e.lookahead, e.lookahead = 0;
  39587. var n = e.block_start + r;
  39588. if ((0 === e.strstart || e.strstart >= n) && (e.lookahead = e.strstart - n, e.strstart = n, N(e, !1), 0 === e.strm.avail_out)) return A;
  39589. if (e.strstart - e.block_start >= e.w_size - z && (N(e, !1), 0 === e.strm.avail_out)) return A;
  39590. }
  39591. return e.insert = 0, t === f ? (N(e, !0), 0 === e.strm.avail_out ? O : B) : (e.strstart > e.block_start && (N(e, !1), e.strm.avail_out), A);
  39592. }), new M(4, 4, 8, 4, Z), new M(4, 5, 16, 8, Z), new M(4, 6, 32, 32, Z), new M(4, 4, 16, 16, W), new M(8, 16, 32, 32, W), new M(8, 16, 128, 128, W), new M(8, 32, 128, 256, W), new M(32, 128, 258, 1024, W), new M(32, 258, 258, 4096, W)], r.deflateInit = function (e, t) {
  39593. return Y(e, t, v, 15, 8, 0);
  39594. }, r.deflateInit2 = Y, r.deflateReset = K, r.deflateResetKeep = G, r.deflateSetHeader = function (e, t) {
  39595. return e && e.state ? 2 !== e.state.wrap ? _ : (e.state.gzhead = t, m) : _;
  39596. }, r.deflate = function (e, t) {
  39597. var r, n, i, s;
  39598. if (!e || !e.state || 5 < t || t < 0) return e ? R(e, _) : _;
  39599. if (n = e.state, !e.output || !e.input && 0 !== e.avail_in || 666 === n.status && t !== f) return R(e, 0 === e.avail_out ? -5 : _);
  39600. if (n.strm = e, r = n.last_flush, n.last_flush = t, n.status === C) if (2 === n.wrap) e.adler = 0, U(n, 31), U(n, 139), U(n, 8), n.gzhead ? (U(n, (n.gzhead.text ? 1 : 0) + (n.gzhead.hcrc ? 2 : 0) + (n.gzhead.extra ? 4 : 0) + (n.gzhead.name ? 8 : 0) + (n.gzhead.comment ? 16 : 0)), U(n, 255 & n.gzhead.time), U(n, n.gzhead.time >> 8 & 255), U(n, n.gzhead.time >> 16 & 255), U(n, n.gzhead.time >> 24 & 255), U(n, 9 === n.level ? 2 : 2 <= n.strategy || n.level < 2 ? 4 : 0), U(n, 255 & n.gzhead.os), n.gzhead.extra && n.gzhead.extra.length && (U(n, 255 & n.gzhead.extra.length), U(n, n.gzhead.extra.length >> 8 & 255)), n.gzhead.hcrc && (e.adler = p(e.adler, n.pending_buf, n.pending, 0)), n.gzindex = 0, n.status = 69) : (U(n, 0), U(n, 0), U(n, 0), U(n, 0), U(n, 0), U(n, 9 === n.level ? 2 : 2 <= n.strategy || n.level < 2 ? 4 : 0), U(n, 3), n.status = E);else {
  39601. var a = v + (n.w_bits - 8 << 4) << 8;
  39602. a |= (2 <= n.strategy || n.level < 2 ? 0 : n.level < 6 ? 1 : 6 === n.level ? 2 : 3) << 6, 0 !== n.strstart && (a |= 32), a += 31 - a % 31, n.status = E, P(n, a), 0 !== n.strstart && (P(n, e.adler >>> 16), P(n, 65535 & e.adler)), e.adler = 1;
  39603. }
  39604. if (69 === n.status) if (n.gzhead.extra) {
  39605. for (i = n.pending; n.gzindex < (65535 & n.gzhead.extra.length) && (n.pending !== n.pending_buf_size || (n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), F(e), i = n.pending, n.pending !== n.pending_buf_size));) U(n, 255 & n.gzhead.extra[n.gzindex]), n.gzindex++;
  39606. n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), n.gzindex === n.gzhead.extra.length && (n.gzindex = 0, n.status = 73);
  39607. } else n.status = 73;
  39608. if (73 === n.status) if (n.gzhead.name) {
  39609. i = n.pending;
  39610. do {
  39611. if (n.pending === n.pending_buf_size && (n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), F(e), i = n.pending, n.pending === n.pending_buf_size)) {
  39612. s = 1;
  39613. break;
  39614. }
  39615. s = n.gzindex < n.gzhead.name.length ? 255 & n.gzhead.name.charCodeAt(n.gzindex++) : 0, U(n, s);
  39616. } while (0 !== s);
  39617. n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), 0 === s && (n.gzindex = 0, n.status = 91);
  39618. } else n.status = 91;
  39619. if (91 === n.status) if (n.gzhead.comment) {
  39620. i = n.pending;
  39621. do {
  39622. if (n.pending === n.pending_buf_size && (n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), F(e), i = n.pending, n.pending === n.pending_buf_size)) {
  39623. s = 1;
  39624. break;
  39625. }
  39626. s = n.gzindex < n.gzhead.comment.length ? 255 & n.gzhead.comment.charCodeAt(n.gzindex++) : 0, U(n, s);
  39627. } while (0 !== s);
  39628. n.gzhead.hcrc && n.pending > i && (e.adler = p(e.adler, n.pending_buf, n.pending - i, i)), 0 === s && (n.status = 103);
  39629. } else n.status = 103;
  39630. if (103 === n.status && (n.gzhead.hcrc ? (n.pending + 2 > n.pending_buf_size && F(e), n.pending + 2 <= n.pending_buf_size && (U(n, 255 & e.adler), U(n, e.adler >> 8 & 255), e.adler = 0, n.status = E)) : n.status = E), 0 !== n.pending) {
  39631. if (F(e), 0 === e.avail_out) return n.last_flush = -1, m;
  39632. } else if (0 === e.avail_in && T(t) <= T(r) && t !== f) return R(e, -5);
  39633. if (666 === n.status && 0 !== e.avail_in) return R(e, -5);
  39634. if (0 !== e.avail_in || 0 !== n.lookahead || t !== l && 666 !== n.status) {
  39635. var o = 2 === n.strategy ? function (e, t) {
  39636. for (var r;;) {
  39637. if (0 === e.lookahead && (j(e), 0 === e.lookahead)) {
  39638. if (t === l) return A;
  39639. break;
  39640. }
  39641. if (e.match_length = 0, r = u._tr_tally(e, 0, e.window[e.strstart]), e.lookahead--, e.strstart++, r && (N(e, !1), 0 === e.strm.avail_out)) return A;
  39642. }
  39643. return e.insert = 0, t === f ? (N(e, !0), 0 === e.strm.avail_out ? O : B) : e.last_lit && (N(e, !1), 0 === e.strm.avail_out) ? A : I;
  39644. }(n, t) : 3 === n.strategy ? function (e, t) {
  39645. for (var r, n, i, s, a = e.window;;) {
  39646. if (e.lookahead <= S) {
  39647. if (j(e), e.lookahead <= S && t === l) return A;
  39648. if (0 === e.lookahead) break;
  39649. }
  39650. if (e.match_length = 0, e.lookahead >= x && 0 < e.strstart && (n = a[i = e.strstart - 1]) === a[++i] && n === a[++i] && n === a[++i]) {
  39651. s = e.strstart + S;
  39652. do {} while (n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && n === a[++i] && i < s);
  39653. e.match_length = S - (s - i), e.match_length > e.lookahead && (e.match_length = e.lookahead);
  39654. }
  39655. if (e.match_length >= x ? (r = u._tr_tally(e, 1, e.match_length - x), e.lookahead -= e.match_length, e.strstart += e.match_length, e.match_length = 0) : (r = u._tr_tally(e, 0, e.window[e.strstart]), e.lookahead--, e.strstart++), r && (N(e, !1), 0 === e.strm.avail_out)) return A;
  39656. }
  39657. return e.insert = 0, t === f ? (N(e, !0), 0 === e.strm.avail_out ? O : B) : e.last_lit && (N(e, !1), 0 === e.strm.avail_out) ? A : I;
  39658. }(n, t) : h[n.level].func(n, t);
  39659. if (o !== O && o !== B || (n.status = 666), o === A || o === O) return 0 === e.avail_out && (n.last_flush = -1), m;
  39660. if (o === I && (1 === t ? u._tr_align(n) : 5 !== t && (u._tr_stored_block(n, 0, 0, !1), 3 === t && (D(n.head), 0 === n.lookahead && (n.strstart = 0, n.block_start = 0, n.insert = 0))), F(e), 0 === e.avail_out)) return n.last_flush = -1, m;
  39661. }
  39662. return t !== f ? m : n.wrap <= 0 ? 1 : (2 === n.wrap ? (U(n, 255 & e.adler), U(n, e.adler >> 8 & 255), U(n, e.adler >> 16 & 255), U(n, e.adler >> 24 & 255), U(n, 255 & e.total_in), U(n, e.total_in >> 8 & 255), U(n, e.total_in >> 16 & 255), U(n, e.total_in >> 24 & 255)) : (P(n, e.adler >>> 16), P(n, 65535 & e.adler)), F(e), 0 < n.wrap && (n.wrap = -n.wrap), 0 !== n.pending ? m : 1);
  39663. }, r.deflateEnd = function (e) {
  39664. var t;
  39665. return e && e.state ? (t = e.state.status) !== C && 69 !== t && 73 !== t && 91 !== t && 103 !== t && t !== E && 666 !== t ? R(e, _) : (e.state = null, t === E ? R(e, -3) : m) : _;
  39666. }, r.deflateSetDictionary = function (e, t) {
  39667. var r,
  39668. n,
  39669. i,
  39670. s,
  39671. a,
  39672. o,
  39673. h,
  39674. u,
  39675. l = t.length;
  39676. if (!e || !e.state) return _;
  39677. if (2 === (s = (r = e.state).wrap) || 1 === s && r.status !== C || r.lookahead) return _;
  39678. for (1 === s && (e.adler = d(e.adler, t, l, 0)), r.wrap = 0, l >= r.w_size && (0 === s && (D(r.head), r.strstart = 0, r.block_start = 0, r.insert = 0), u = new c.Buf8(r.w_size), c.arraySet(u, t, l - r.w_size, r.w_size, 0), t = u, l = r.w_size), a = e.avail_in, o = e.next_in, h = e.input, e.avail_in = l, e.next_in = 0, e.input = t, j(r); r.lookahead >= x;) {
  39679. for (n = r.strstart, i = r.lookahead - (x - 1); r.ins_h = (r.ins_h << r.hash_shift ^ r.window[n + x - 1]) & r.hash_mask, r.prev[n & r.w_mask] = r.head[r.ins_h], r.head[r.ins_h] = n, n++, --i;);
  39680. r.strstart = n, r.lookahead = x - 1, j(r);
  39681. }
  39682. return r.strstart += r.lookahead, r.block_start = r.strstart, r.insert = r.lookahead, r.lookahead = 0, r.match_length = r.prev_length = x - 1, r.match_available = 0, e.next_in = o, e.input = h, e.avail_in = a, r.wrap = s, m;
  39683. }, r.deflateInfo = "pako deflate (from Nodeca project)";
  39684. }, {
  39685. "../utils/common": 41,
  39686. "./adler32": 43,
  39687. "./crc32": 45,
  39688. "./messages": 51,
  39689. "./trees": 52
  39690. }],
  39691. 47: [function (e, t, r) {
  39692. "use strict";
  39693. t.exports = function () {
  39694. this.text = 0, this.time = 0, this.xflags = 0, this.os = 0, this.extra = null, this.extra_len = 0, this.name = "", this.comment = "", this.hcrc = 0, this.done = !1;
  39695. };
  39696. }, {}],
  39697. 48: [function (e, t, r) {
  39698. "use strict";
  39699. t.exports = function (e, t) {
  39700. var r, n, i, s, a, o, h, u, l, f, c, d, p, m, _, g, b, v, y, w, k, x, S, z, C;
  39701. r = e.state, n = e.next_in, z = e.input, i = n + (e.avail_in - 5), s = e.next_out, C = e.output, a = s - (t - e.avail_out), o = s + (e.avail_out - 257), h = r.dmax, u = r.wsize, l = r.whave, f = r.wnext, c = r.window, d = r.hold, p = r.bits, m = r.lencode, _ = r.distcode, g = (1 << r.lenbits) - 1, b = (1 << r.distbits) - 1;
  39702. e: do {
  39703. p < 15 && (d += z[n++] << p, p += 8, d += z[n++] << p, p += 8), v = m[d & g];
  39704. t: for (;;) {
  39705. if (d >>>= y = v >>> 24, p -= y, 0 === (y = v >>> 16 & 255)) C[s++] = 65535 & v;else {
  39706. if (!(16 & y)) {
  39707. if (0 == (64 & y)) {
  39708. v = m[(65535 & v) + (d & (1 << y) - 1)];
  39709. continue t;
  39710. }
  39711. if (32 & y) {
  39712. r.mode = 12;
  39713. break e;
  39714. }
  39715. e.msg = "invalid literal/length code", r.mode = 30;
  39716. break e;
  39717. }
  39718. w = 65535 & v, (y &= 15) && (p < y && (d += z[n++] << p, p += 8), w += d & (1 << y) - 1, d >>>= y, p -= y), p < 15 && (d += z[n++] << p, p += 8, d += z[n++] << p, p += 8), v = _[d & b];
  39719. r: for (;;) {
  39720. if (d >>>= y = v >>> 24, p -= y, !(16 & (y = v >>> 16 & 255))) {
  39721. if (0 == (64 & y)) {
  39722. v = _[(65535 & v) + (d & (1 << y) - 1)];
  39723. continue r;
  39724. }
  39725. e.msg = "invalid distance code", r.mode = 30;
  39726. break e;
  39727. }
  39728. if (k = 65535 & v, p < (y &= 15) && (d += z[n++] << p, (p += 8) < y && (d += z[n++] << p, p += 8)), h < (k += d & (1 << y) - 1)) {
  39729. e.msg = "invalid distance too far back", r.mode = 30;
  39730. break e;
  39731. }
  39732. if (d >>>= y, p -= y, (y = s - a) < k) {
  39733. if (l < (y = k - y) && r.sane) {
  39734. e.msg = "invalid distance too far back", r.mode = 30;
  39735. break e;
  39736. }
  39737. if (S = c, (x = 0) === f) {
  39738. if (x += u - y, y < w) {
  39739. for (w -= y; C[s++] = c[x++], --y;);
  39740. x = s - k, S = C;
  39741. }
  39742. } else if (f < y) {
  39743. if (x += u + f - y, (y -= f) < w) {
  39744. for (w -= y; C[s++] = c[x++], --y;);
  39745. if (x = 0, f < w) {
  39746. for (w -= y = f; C[s++] = c[x++], --y;);
  39747. x = s - k, S = C;
  39748. }
  39749. }
  39750. } else if (x += f - y, y < w) {
  39751. for (w -= y; C[s++] = c[x++], --y;);
  39752. x = s - k, S = C;
  39753. }
  39754. for (; 2 < w;) C[s++] = S[x++], C[s++] = S[x++], C[s++] = S[x++], w -= 3;
  39755. w && (C[s++] = S[x++], 1 < w && (C[s++] = S[x++]));
  39756. } else {
  39757. for (x = s - k; C[s++] = C[x++], C[s++] = C[x++], C[s++] = C[x++], 2 < (w -= 3););
  39758. w && (C[s++] = C[x++], 1 < w && (C[s++] = C[x++]));
  39759. }
  39760. break;
  39761. }
  39762. }
  39763. break;
  39764. }
  39765. } while (n < i && s < o);
  39766. n -= w = p >> 3, d &= (1 << (p -= w << 3)) - 1, e.next_in = n, e.next_out = s, e.avail_in = n < i ? i - n + 5 : 5 - (n - i), e.avail_out = s < o ? o - s + 257 : 257 - (s - o), r.hold = d, r.bits = p;
  39767. };
  39768. }, {}],
  39769. 49: [function (e, t, r) {
  39770. "use strict";
  39771. var I = e("../utils/common"),
  39772. O = e("./adler32"),
  39773. B = e("./crc32"),
  39774. R = e("./inffast"),
  39775. T = e("./inftrees"),
  39776. D = 1,
  39777. F = 2,
  39778. N = 0,
  39779. U = -2,
  39780. P = 1,
  39781. n = 852,
  39782. i = 592;
  39783. function L(e) {
  39784. return (e >>> 24 & 255) + (e >>> 8 & 65280) + ((65280 & e) << 8) + ((255 & e) << 24);
  39785. }
  39786. function s() {
  39787. this.mode = 0, this.last = !1, this.wrap = 0, this.havedict = !1, this.flags = 0, this.dmax = 0, this.check = 0, this.total = 0, this.head = null, this.wbits = 0, this.wsize = 0, this.whave = 0, this.wnext = 0, this.window = null, this.hold = 0, this.bits = 0, this.length = 0, this.offset = 0, this.extra = 0, this.lencode = null, this.distcode = null, this.lenbits = 0, this.distbits = 0, this.ncode = 0, this.nlen = 0, this.ndist = 0, this.have = 0, this.next = null, this.lens = new I.Buf16(320), this.work = new I.Buf16(288), this.lendyn = null, this.distdyn = null, this.sane = 0, this.back = 0, this.was = 0;
  39788. }
  39789. function a(e) {
  39790. var t;
  39791. return e && e.state ? (t = e.state, e.total_in = e.total_out = t.total = 0, e.msg = "", t.wrap && (e.adler = 1 & t.wrap), t.mode = P, t.last = 0, t.havedict = 0, t.dmax = 32768, t.head = null, t.hold = 0, t.bits = 0, t.lencode = t.lendyn = new I.Buf32(n), t.distcode = t.distdyn = new I.Buf32(i), t.sane = 1, t.back = -1, N) : U;
  39792. }
  39793. function o(e) {
  39794. var t;
  39795. return e && e.state ? ((t = e.state).wsize = 0, t.whave = 0, t.wnext = 0, a(e)) : U;
  39796. }
  39797. function h(e, t) {
  39798. var r, n;
  39799. return e && e.state ? (n = e.state, t < 0 ? (r = 0, t = -t) : (r = 1 + (t >> 4), t < 48 && (t &= 15)), t && (t < 8 || 15 < t) ? U : (null !== n.window && n.wbits !== t && (n.window = null), n.wrap = r, n.wbits = t, o(e))) : U;
  39800. }
  39801. function u(e, t) {
  39802. var r, n;
  39803. return e ? (n = new s(), (e.state = n).window = null, (r = h(e, t)) !== N && (e.state = null), r) : U;
  39804. }
  39805. var l,
  39806. f,
  39807. c = !0;
  39808. function j(e) {
  39809. if (c) {
  39810. var t;
  39811. for (l = new I.Buf32(512), f = new I.Buf32(32), t = 0; t < 144;) e.lens[t++] = 8;
  39812. for (; t < 256;) e.lens[t++] = 9;
  39813. for (; t < 280;) e.lens[t++] = 7;
  39814. for (; t < 288;) e.lens[t++] = 8;
  39815. for (T(D, e.lens, 0, 288, l, 0, e.work, {
  39816. bits: 9
  39817. }), t = 0; t < 32;) e.lens[t++] = 5;
  39818. T(F, e.lens, 0, 32, f, 0, e.work, {
  39819. bits: 5
  39820. }), c = !1;
  39821. }
  39822. e.lencode = l, e.lenbits = 9, e.distcode = f, e.distbits = 5;
  39823. }
  39824. function Z(e, t, r, n) {
  39825. var i,
  39826. s = e.state;
  39827. return null === s.window && (s.wsize = 1 << s.wbits, s.wnext = 0, s.whave = 0, s.window = new I.Buf8(s.wsize)), n >= s.wsize ? (I.arraySet(s.window, t, r - s.wsize, s.wsize, 0), s.wnext = 0, s.whave = s.wsize) : (n < (i = s.wsize - s.wnext) && (i = n), I.arraySet(s.window, t, r - n, i, s.wnext), (n -= i) ? (I.arraySet(s.window, t, r - n, n, 0), s.wnext = n, s.whave = s.wsize) : (s.wnext += i, s.wnext === s.wsize && (s.wnext = 0), s.whave < s.wsize && (s.whave += i))), 0;
  39828. }
  39829. r.inflateReset = o, r.inflateReset2 = h, r.inflateResetKeep = a, r.inflateInit = function (e) {
  39830. return u(e, 15);
  39831. }, r.inflateInit2 = u, r.inflate = function (e, t) {
  39832. var r,
  39833. n,
  39834. i,
  39835. s,
  39836. a,
  39837. o,
  39838. h,
  39839. u,
  39840. l,
  39841. f,
  39842. c,
  39843. d,
  39844. p,
  39845. m,
  39846. _,
  39847. g,
  39848. b,
  39849. v,
  39850. y,
  39851. w,
  39852. k,
  39853. x,
  39854. S,
  39855. z,
  39856. C = 0,
  39857. E = new I.Buf8(4),
  39858. A = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  39859. if (!e || !e.state || !e.output || !e.input && 0 !== e.avail_in) return U;
  39860. 12 === (r = e.state).mode && (r.mode = 13), a = e.next_out, i = e.output, h = e.avail_out, s = e.next_in, n = e.input, o = e.avail_in, u = r.hold, l = r.bits, f = o, c = h, x = N;
  39861. e: for (;;) switch (r.mode) {
  39862. case P:
  39863. if (0 === r.wrap) {
  39864. r.mode = 13;
  39865. break;
  39866. }
  39867. for (; l < 16;) {
  39868. if (0 === o) break e;
  39869. o--, u += n[s++] << l, l += 8;
  39870. }
  39871. if (2 & r.wrap && 35615 === u) {
  39872. E[r.check = 0] = 255 & u, E[1] = u >>> 8 & 255, r.check = B(r.check, E, 2, 0), l = u = 0, r.mode = 2;
  39873. break;
  39874. }
  39875. if (r.flags = 0, r.head && (r.head.done = !1), !(1 & r.wrap) || (((255 & u) << 8) + (u >> 8)) % 31) {
  39876. e.msg = "incorrect header check", r.mode = 30;
  39877. break;
  39878. }
  39879. if (8 != (15 & u)) {
  39880. e.msg = "unknown compression method", r.mode = 30;
  39881. break;
  39882. }
  39883. if (l -= 4, k = 8 + (15 & (u >>>= 4)), 0 === r.wbits) r.wbits = k;else if (k > r.wbits) {
  39884. e.msg = "invalid window size", r.mode = 30;
  39885. break;
  39886. }
  39887. r.dmax = 1 << k, e.adler = r.check = 1, r.mode = 512 & u ? 10 : 12, l = u = 0;
  39888. break;
  39889. case 2:
  39890. for (; l < 16;) {
  39891. if (0 === o) break e;
  39892. o--, u += n[s++] << l, l += 8;
  39893. }
  39894. if (r.flags = u, 8 != (255 & r.flags)) {
  39895. e.msg = "unknown compression method", r.mode = 30;
  39896. break;
  39897. }
  39898. if (57344 & r.flags) {
  39899. e.msg = "unknown header flags set", r.mode = 30;
  39900. break;
  39901. }
  39902. r.head && (r.head.text = u >> 8 & 1), 512 & r.flags && (E[0] = 255 & u, E[1] = u >>> 8 & 255, r.check = B(r.check, E, 2, 0)), l = u = 0, r.mode = 3;
  39903. case 3:
  39904. for (; l < 32;) {
  39905. if (0 === o) break e;
  39906. o--, u += n[s++] << l, l += 8;
  39907. }
  39908. r.head && (r.head.time = u), 512 & r.flags && (E[0] = 255 & u, E[1] = u >>> 8 & 255, E[2] = u >>> 16 & 255, E[3] = u >>> 24 & 255, r.check = B(r.check, E, 4, 0)), l = u = 0, r.mode = 4;
  39909. case 4:
  39910. for (; l < 16;) {
  39911. if (0 === o) break e;
  39912. o--, u += n[s++] << l, l += 8;
  39913. }
  39914. r.head && (r.head.xflags = 255 & u, r.head.os = u >> 8), 512 & r.flags && (E[0] = 255 & u, E[1] = u >>> 8 & 255, r.check = B(r.check, E, 2, 0)), l = u = 0, r.mode = 5;
  39915. case 5:
  39916. if (1024 & r.flags) {
  39917. for (; l < 16;) {
  39918. if (0 === o) break e;
  39919. o--, u += n[s++] << l, l += 8;
  39920. }
  39921. r.length = u, r.head && (r.head.extra_len = u), 512 & r.flags && (E[0] = 255 & u, E[1] = u >>> 8 & 255, r.check = B(r.check, E, 2, 0)), l = u = 0;
  39922. } else r.head && (r.head.extra = null);
  39923. r.mode = 6;
  39924. case 6:
  39925. if (1024 & r.flags && (o < (d = r.length) && (d = o), d && (r.head && (k = r.head.extra_len - r.length, r.head.extra || (r.head.extra = new Array(r.head.extra_len)), I.arraySet(r.head.extra, n, s, d, k)), 512 & r.flags && (r.check = B(r.check, n, d, s)), o -= d, s += d, r.length -= d), r.length)) break e;
  39926. r.length = 0, r.mode = 7;
  39927. case 7:
  39928. if (2048 & r.flags) {
  39929. if (0 === o) break e;
  39930. for (d = 0; k = n[s + d++], r.head && k && r.length < 65536 && (r.head.name += String.fromCharCode(k)), k && d < o;);
  39931. if (512 & r.flags && (r.check = B(r.check, n, d, s)), o -= d, s += d, k) break e;
  39932. } else r.head && (r.head.name = null);
  39933. r.length = 0, r.mode = 8;
  39934. case 8:
  39935. if (4096 & r.flags) {
  39936. if (0 === o) break e;
  39937. for (d = 0; k = n[s + d++], r.head && k && r.length < 65536 && (r.head.comment += String.fromCharCode(k)), k && d < o;);
  39938. if (512 & r.flags && (r.check = B(r.check, n, d, s)), o -= d, s += d, k) break e;
  39939. } else r.head && (r.head.comment = null);
  39940. r.mode = 9;
  39941. case 9:
  39942. if (512 & r.flags) {
  39943. for (; l < 16;) {
  39944. if (0 === o) break e;
  39945. o--, u += n[s++] << l, l += 8;
  39946. }
  39947. if (u !== (65535 & r.check)) {
  39948. e.msg = "header crc mismatch", r.mode = 30;
  39949. break;
  39950. }
  39951. l = u = 0;
  39952. }
  39953. r.head && (r.head.hcrc = r.flags >> 9 & 1, r.head.done = !0), e.adler = r.check = 0, r.mode = 12;
  39954. break;
  39955. case 10:
  39956. for (; l < 32;) {
  39957. if (0 === o) break e;
  39958. o--, u += n[s++] << l, l += 8;
  39959. }
  39960. e.adler = r.check = L(u), l = u = 0, r.mode = 11;
  39961. case 11:
  39962. if (0 === r.havedict) return e.next_out = a, e.avail_out = h, e.next_in = s, e.avail_in = o, r.hold = u, r.bits = l, 2;
  39963. e.adler = r.check = 1, r.mode = 12;
  39964. case 12:
  39965. if (5 === t || 6 === t) break e;
  39966. case 13:
  39967. if (r.last) {
  39968. u >>>= 7 & l, l -= 7 & l, r.mode = 27;
  39969. break;
  39970. }
  39971. for (; l < 3;) {
  39972. if (0 === o) break e;
  39973. o--, u += n[s++] << l, l += 8;
  39974. }
  39975. switch (r.last = 1 & u, l -= 1, 3 & (u >>>= 1)) {
  39976. case 0:
  39977. r.mode = 14;
  39978. break;
  39979. case 1:
  39980. if (j(r), r.mode = 20, 6 !== t) break;
  39981. u >>>= 2, l -= 2;
  39982. break e;
  39983. case 2:
  39984. r.mode = 17;
  39985. break;
  39986. case 3:
  39987. e.msg = "invalid block type", r.mode = 30;
  39988. }
  39989. u >>>= 2, l -= 2;
  39990. break;
  39991. case 14:
  39992. for (u >>>= 7 & l, l -= 7 & l; l < 32;) {
  39993. if (0 === o) break e;
  39994. o--, u += n[s++] << l, l += 8;
  39995. }
  39996. if ((65535 & u) != (u >>> 16 ^ 65535)) {
  39997. e.msg = "invalid stored block lengths", r.mode = 30;
  39998. break;
  39999. }
  40000. if (r.length = 65535 & u, l = u = 0, r.mode = 15, 6 === t) break e;
  40001. case 15:
  40002. r.mode = 16;
  40003. case 16:
  40004. if (d = r.length) {
  40005. if (o < d && (d = o), h < d && (d = h), 0 === d) break e;
  40006. I.arraySet(i, n, s, d, a), o -= d, s += d, h -= d, a += d, r.length -= d;
  40007. break;
  40008. }
  40009. r.mode = 12;
  40010. break;
  40011. case 17:
  40012. for (; l < 14;) {
  40013. if (0 === o) break e;
  40014. o--, u += n[s++] << l, l += 8;
  40015. }
  40016. if (r.nlen = 257 + (31 & u), u >>>= 5, l -= 5, r.ndist = 1 + (31 & u), u >>>= 5, l -= 5, r.ncode = 4 + (15 & u), u >>>= 4, l -= 4, 286 < r.nlen || 30 < r.ndist) {
  40017. e.msg = "too many length or distance symbols", r.mode = 30;
  40018. break;
  40019. }
  40020. r.have = 0, r.mode = 18;
  40021. case 18:
  40022. for (; r.have < r.ncode;) {
  40023. for (; l < 3;) {
  40024. if (0 === o) break e;
  40025. o--, u += n[s++] << l, l += 8;
  40026. }
  40027. r.lens[A[r.have++]] = 7 & u, u >>>= 3, l -= 3;
  40028. }
  40029. for (; r.have < 19;) r.lens[A[r.have++]] = 0;
  40030. if (r.lencode = r.lendyn, r.lenbits = 7, S = {
  40031. bits: r.lenbits
  40032. }, x = T(0, r.lens, 0, 19, r.lencode, 0, r.work, S), r.lenbits = S.bits, x) {
  40033. e.msg = "invalid code lengths set", r.mode = 30;
  40034. break;
  40035. }
  40036. r.have = 0, r.mode = 19;
  40037. case 19:
  40038. for (; r.have < r.nlen + r.ndist;) {
  40039. for (; g = (C = r.lencode[u & (1 << r.lenbits) - 1]) >>> 16 & 255, b = 65535 & C, !((_ = C >>> 24) <= l);) {
  40040. if (0 === o) break e;
  40041. o--, u += n[s++] << l, l += 8;
  40042. }
  40043. if (b < 16) u >>>= _, l -= _, r.lens[r.have++] = b;else {
  40044. if (16 === b) {
  40045. for (z = _ + 2; l < z;) {
  40046. if (0 === o) break e;
  40047. o--, u += n[s++] << l, l += 8;
  40048. }
  40049. if (u >>>= _, l -= _, 0 === r.have) {
  40050. e.msg = "invalid bit length repeat", r.mode = 30;
  40051. break;
  40052. }
  40053. k = r.lens[r.have - 1], d = 3 + (3 & u), u >>>= 2, l -= 2;
  40054. } else if (17 === b) {
  40055. for (z = _ + 3; l < z;) {
  40056. if (0 === o) break e;
  40057. o--, u += n[s++] << l, l += 8;
  40058. }
  40059. l -= _, k = 0, d = 3 + (7 & (u >>>= _)), u >>>= 3, l -= 3;
  40060. } else {
  40061. for (z = _ + 7; l < z;) {
  40062. if (0 === o) break e;
  40063. o--, u += n[s++] << l, l += 8;
  40064. }
  40065. l -= _, k = 0, d = 11 + (127 & (u >>>= _)), u >>>= 7, l -= 7;
  40066. }
  40067. if (r.have + d > r.nlen + r.ndist) {
  40068. e.msg = "invalid bit length repeat", r.mode = 30;
  40069. break;
  40070. }
  40071. for (; d--;) r.lens[r.have++] = k;
  40072. }
  40073. }
  40074. if (30 === r.mode) break;
  40075. if (0 === r.lens[256]) {
  40076. e.msg = "invalid code -- missing end-of-block", r.mode = 30;
  40077. break;
  40078. }
  40079. if (r.lenbits = 9, S = {
  40080. bits: r.lenbits
  40081. }, x = T(D, r.lens, 0, r.nlen, r.lencode, 0, r.work, S), r.lenbits = S.bits, x) {
  40082. e.msg = "invalid literal/lengths set", r.mode = 30;
  40083. break;
  40084. }
  40085. if (r.distbits = 6, r.distcode = r.distdyn, S = {
  40086. bits: r.distbits
  40087. }, x = T(F, r.lens, r.nlen, r.ndist, r.distcode, 0, r.work, S), r.distbits = S.bits, x) {
  40088. e.msg = "invalid distances set", r.mode = 30;
  40089. break;
  40090. }
  40091. if (r.mode = 20, 6 === t) break e;
  40092. case 20:
  40093. r.mode = 21;
  40094. case 21:
  40095. if (6 <= o && 258 <= h) {
  40096. e.next_out = a, e.avail_out = h, e.next_in = s, e.avail_in = o, r.hold = u, r.bits = l, R(e, c), a = e.next_out, i = e.output, h = e.avail_out, s = e.next_in, n = e.input, o = e.avail_in, u = r.hold, l = r.bits, 12 === r.mode && (r.back = -1);
  40097. break;
  40098. }
  40099. for (r.back = 0; g = (C = r.lencode[u & (1 << r.lenbits) - 1]) >>> 16 & 255, b = 65535 & C, !((_ = C >>> 24) <= l);) {
  40100. if (0 === o) break e;
  40101. o--, u += n[s++] << l, l += 8;
  40102. }
  40103. if (g && 0 == (240 & g)) {
  40104. for (v = _, y = g, w = b; g = (C = r.lencode[w + ((u & (1 << v + y) - 1) >> v)]) >>> 16 & 255, b = 65535 & C, !(v + (_ = C >>> 24) <= l);) {
  40105. if (0 === o) break e;
  40106. o--, u += n[s++] << l, l += 8;
  40107. }
  40108. u >>>= v, l -= v, r.back += v;
  40109. }
  40110. if (u >>>= _, l -= _, r.back += _, r.length = b, 0 === g) {
  40111. r.mode = 26;
  40112. break;
  40113. }
  40114. if (32 & g) {
  40115. r.back = -1, r.mode = 12;
  40116. break;
  40117. }
  40118. if (64 & g) {
  40119. e.msg = "invalid literal/length code", r.mode = 30;
  40120. break;
  40121. }
  40122. r.extra = 15 & g, r.mode = 22;
  40123. case 22:
  40124. if (r.extra) {
  40125. for (z = r.extra; l < z;) {
  40126. if (0 === o) break e;
  40127. o--, u += n[s++] << l, l += 8;
  40128. }
  40129. r.length += u & (1 << r.extra) - 1, u >>>= r.extra, l -= r.extra, r.back += r.extra;
  40130. }
  40131. r.was = r.length, r.mode = 23;
  40132. case 23:
  40133. for (; g = (C = r.distcode[u & (1 << r.distbits) - 1]) >>> 16 & 255, b = 65535 & C, !((_ = C >>> 24) <= l);) {
  40134. if (0 === o) break e;
  40135. o--, u += n[s++] << l, l += 8;
  40136. }
  40137. if (0 == (240 & g)) {
  40138. for (v = _, y = g, w = b; g = (C = r.distcode[w + ((u & (1 << v + y) - 1) >> v)]) >>> 16 & 255, b = 65535 & C, !(v + (_ = C >>> 24) <= l);) {
  40139. if (0 === o) break e;
  40140. o--, u += n[s++] << l, l += 8;
  40141. }
  40142. u >>>= v, l -= v, r.back += v;
  40143. }
  40144. if (u >>>= _, l -= _, r.back += _, 64 & g) {
  40145. e.msg = "invalid distance code", r.mode = 30;
  40146. break;
  40147. }
  40148. r.offset = b, r.extra = 15 & g, r.mode = 24;
  40149. case 24:
  40150. if (r.extra) {
  40151. for (z = r.extra; l < z;) {
  40152. if (0 === o) break e;
  40153. o--, u += n[s++] << l, l += 8;
  40154. }
  40155. r.offset += u & (1 << r.extra) - 1, u >>>= r.extra, l -= r.extra, r.back += r.extra;
  40156. }
  40157. if (r.offset > r.dmax) {
  40158. e.msg = "invalid distance too far back", r.mode = 30;
  40159. break;
  40160. }
  40161. r.mode = 25;
  40162. case 25:
  40163. if (0 === h) break e;
  40164. if (d = c - h, r.offset > d) {
  40165. if ((d = r.offset - d) > r.whave && r.sane) {
  40166. e.msg = "invalid distance too far back", r.mode = 30;
  40167. break;
  40168. }
  40169. p = d > r.wnext ? (d -= r.wnext, r.wsize - d) : r.wnext - d, d > r.length && (d = r.length), m = r.window;
  40170. } else m = i, p = a - r.offset, d = r.length;
  40171. for (h < d && (d = h), h -= d, r.length -= d; i[a++] = m[p++], --d;);
  40172. 0 === r.length && (r.mode = 21);
  40173. break;
  40174. case 26:
  40175. if (0 === h) break e;
  40176. i[a++] = r.length, h--, r.mode = 21;
  40177. break;
  40178. case 27:
  40179. if (r.wrap) {
  40180. for (; l < 32;) {
  40181. if (0 === o) break e;
  40182. o--, u |= n[s++] << l, l += 8;
  40183. }
  40184. if (c -= h, e.total_out += c, r.total += c, c && (e.adler = r.check = r.flags ? B(r.check, i, c, a - c) : O(r.check, i, c, a - c)), c = h, (r.flags ? u : L(u)) !== r.check) {
  40185. e.msg = "incorrect data check", r.mode = 30;
  40186. break;
  40187. }
  40188. l = u = 0;
  40189. }
  40190. r.mode = 28;
  40191. case 28:
  40192. if (r.wrap && r.flags) {
  40193. for (; l < 32;) {
  40194. if (0 === o) break e;
  40195. o--, u += n[s++] << l, l += 8;
  40196. }
  40197. if (u !== (4294967295 & r.total)) {
  40198. e.msg = "incorrect length check", r.mode = 30;
  40199. break;
  40200. }
  40201. l = u = 0;
  40202. }
  40203. r.mode = 29;
  40204. case 29:
  40205. x = 1;
  40206. break e;
  40207. case 30:
  40208. x = -3;
  40209. break e;
  40210. case 31:
  40211. return -4;
  40212. case 32:
  40213. default:
  40214. return U;
  40215. }
  40216. return e.next_out = a, e.avail_out = h, e.next_in = s, e.avail_in = o, r.hold = u, r.bits = l, (r.wsize || c !== e.avail_out && r.mode < 30 && (r.mode < 27 || 4 !== t)) && Z(e, e.output, e.next_out, c - e.avail_out) ? (r.mode = 31, -4) : (f -= e.avail_in, c -= e.avail_out, e.total_in += f, e.total_out += c, r.total += c, r.wrap && c && (e.adler = r.check = r.flags ? B(r.check, i, c, e.next_out - c) : O(r.check, i, c, e.next_out - c)), e.data_type = r.bits + (r.last ? 64 : 0) + (12 === r.mode ? 128 : 0) + (20 === r.mode || 15 === r.mode ? 256 : 0), (0 == f && 0 === c || 4 === t) && x === N && (x = -5), x);
  40217. }, r.inflateEnd = function (e) {
  40218. if (!e || !e.state) return U;
  40219. var t = e.state;
  40220. return t.window && (t.window = null), e.state = null, N;
  40221. }, r.inflateGetHeader = function (e, t) {
  40222. var r;
  40223. return e && e.state ? 0 == (2 & (r = e.state).wrap) ? U : ((r.head = t).done = !1, N) : U;
  40224. }, r.inflateSetDictionary = function (e, t) {
  40225. var r,
  40226. n = t.length;
  40227. return e && e.state ? 0 !== (r = e.state).wrap && 11 !== r.mode ? U : 11 === r.mode && O(1, t, n, 0) !== r.check ? -3 : Z(e, t, n, n) ? (r.mode = 31, -4) : (r.havedict = 1, N) : U;
  40228. }, r.inflateInfo = "pako inflate (from Nodeca project)";
  40229. }, {
  40230. "../utils/common": 41,
  40231. "./adler32": 43,
  40232. "./crc32": 45,
  40233. "./inffast": 48,
  40234. "./inftrees": 50
  40235. }],
  40236. 50: [function (e, t, r) {
  40237. "use strict";
  40238. var D = e("../utils/common"),
  40239. F = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0],
  40240. N = [16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78],
  40241. U = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0],
  40242. P = [16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64];
  40243. t.exports = function (e, t, r, n, i, s, a, o) {
  40244. var h,
  40245. u,
  40246. l,
  40247. f,
  40248. c,
  40249. d,
  40250. p,
  40251. m,
  40252. _,
  40253. g = o.bits,
  40254. b = 0,
  40255. v = 0,
  40256. y = 0,
  40257. w = 0,
  40258. k = 0,
  40259. x = 0,
  40260. S = 0,
  40261. z = 0,
  40262. C = 0,
  40263. E = 0,
  40264. A = null,
  40265. I = 0,
  40266. O = new D.Buf16(16),
  40267. B = new D.Buf16(16),
  40268. R = null,
  40269. T = 0;
  40270. for (b = 0; b <= 15; b++) O[b] = 0;
  40271. for (v = 0; v < n; v++) O[t[r + v]]++;
  40272. for (k = g, w = 15; 1 <= w && 0 === O[w]; w--);
  40273. if (w < k && (k = w), 0 === w) return i[s++] = 20971520, i[s++] = 20971520, o.bits = 1, 0;
  40274. for (y = 1; y < w && 0 === O[y]; y++);
  40275. for (k < y && (k = y), b = z = 1; b <= 15; b++) if (z <<= 1, (z -= O[b]) < 0) return -1;
  40276. if (0 < z && (0 === e || 1 !== w)) return -1;
  40277. for (B[1] = 0, b = 1; b < 15; b++) B[b + 1] = B[b] + O[b];
  40278. for (v = 0; v < n; v++) 0 !== t[r + v] && (a[B[t[r + v]]++] = v);
  40279. if (d = 0 === e ? (A = R = a, 19) : 1 === e ? (A = F, I -= 257, R = N, T -= 257, 256) : (A = U, R = P, -1), b = y, c = s, S = v = E = 0, l = -1, f = (C = 1 << (x = k)) - 1, 1 === e && 852 < C || 2 === e && 592 < C) return 1;
  40280. for (;;) {
  40281. for (p = b - S, _ = a[v] < d ? (m = 0, a[v]) : a[v] > d ? (m = R[T + a[v]], A[I + a[v]]) : (m = 96, 0), h = 1 << b - S, y = u = 1 << x; i[c + (E >> S) + (u -= h)] = p << 24 | m << 16 | _ | 0, 0 !== u;);
  40282. for (h = 1 << b - 1; E & h;) h >>= 1;
  40283. if (0 !== h ? (E &= h - 1, E += h) : E = 0, v++, 0 == --O[b]) {
  40284. if (b === w) break;
  40285. b = t[r + a[v]];
  40286. }
  40287. if (k < b && (E & f) !== l) {
  40288. for (0 === S && (S = k), c += y, z = 1 << (x = b - S); x + S < w && !((z -= O[x + S]) <= 0);) x++, z <<= 1;
  40289. if (C += 1 << x, 1 === e && 852 < C || 2 === e && 592 < C) return 1;
  40290. i[l = E & f] = k << 24 | x << 16 | c - s | 0;
  40291. }
  40292. }
  40293. return 0 !== E && (i[c + E] = b - S << 24 | 64 << 16 | 0), o.bits = k, 0;
  40294. };
  40295. }, {
  40296. "../utils/common": 41
  40297. }],
  40298. 51: [function (e, t, r) {
  40299. "use strict";
  40300. t.exports = {
  40301. 2: "need dictionary",
  40302. 1: "stream end",
  40303. 0: "",
  40304. "-1": "file error",
  40305. "-2": "stream error",
  40306. "-3": "data error",
  40307. "-4": "insufficient memory",
  40308. "-5": "buffer error",
  40309. "-6": "incompatible version"
  40310. };
  40311. }, {}],
  40312. 52: [function (e, t, r) {
  40313. "use strict";
  40314. var i = e("../utils/common"),
  40315. o = 0,
  40316. h = 1;
  40317. function n(e) {
  40318. for (var t = e.length; 0 <= --t;) e[t] = 0;
  40319. }
  40320. var s = 0,
  40321. a = 29,
  40322. u = 256,
  40323. l = u + 1 + a,
  40324. f = 30,
  40325. c = 19,
  40326. _ = 2 * l + 1,
  40327. g = 15,
  40328. d = 16,
  40329. p = 7,
  40330. m = 256,
  40331. b = 16,
  40332. v = 17,
  40333. y = 18,
  40334. w = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0],
  40335. k = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13],
  40336. x = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7],
  40337. S = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15],
  40338. z = new Array(2 * (l + 2));
  40339. n(z);
  40340. var C = new Array(2 * f);
  40341. n(C);
  40342. var E = new Array(512);
  40343. n(E);
  40344. var A = new Array(256);
  40345. n(A);
  40346. var I = new Array(a);
  40347. n(I);
  40348. var O,
  40349. B,
  40350. R,
  40351. T = new Array(f);
  40352. function D(e, t, r, n, i) {
  40353. this.static_tree = e, this.extra_bits = t, this.extra_base = r, this.elems = n, this.max_length = i, this.has_stree = e && e.length;
  40354. }
  40355. function F(e, t) {
  40356. this.dyn_tree = e, this.max_code = 0, this.stat_desc = t;
  40357. }
  40358. function N(e) {
  40359. return e < 256 ? E[e] : E[256 + (e >>> 7)];
  40360. }
  40361. function U(e, t) {
  40362. e.pending_buf[e.pending++] = 255 & t, e.pending_buf[e.pending++] = t >>> 8 & 255;
  40363. }
  40364. function P(e, t, r) {
  40365. e.bi_valid > d - r ? (e.bi_buf |= t << e.bi_valid & 65535, U(e, e.bi_buf), e.bi_buf = t >> d - e.bi_valid, e.bi_valid += r - d) : (e.bi_buf |= t << e.bi_valid & 65535, e.bi_valid += r);
  40366. }
  40367. function L(e, t, r) {
  40368. P(e, r[2 * t], r[2 * t + 1]);
  40369. }
  40370. function j(e, t) {
  40371. for (var r = 0; r |= 1 & e, e >>>= 1, r <<= 1, 0 < --t;);
  40372. return r >>> 1;
  40373. }
  40374. function Z(e, t, r) {
  40375. var n,
  40376. i,
  40377. s = new Array(g + 1),
  40378. a = 0;
  40379. for (n = 1; n <= g; n++) s[n] = a = a + r[n - 1] << 1;
  40380. for (i = 0; i <= t; i++) {
  40381. var o = e[2 * i + 1];
  40382. 0 !== o && (e[2 * i] = j(s[o]++, o));
  40383. }
  40384. }
  40385. function W(e) {
  40386. var t;
  40387. for (t = 0; t < l; t++) e.dyn_ltree[2 * t] = 0;
  40388. for (t = 0; t < f; t++) e.dyn_dtree[2 * t] = 0;
  40389. for (t = 0; t < c; t++) e.bl_tree[2 * t] = 0;
  40390. e.dyn_ltree[2 * m] = 1, e.opt_len = e.static_len = 0, e.last_lit = e.matches = 0;
  40391. }
  40392. function M(e) {
  40393. 8 < e.bi_valid ? U(e, e.bi_buf) : 0 < e.bi_valid && (e.pending_buf[e.pending++] = e.bi_buf), e.bi_buf = 0, e.bi_valid = 0;
  40394. }
  40395. function H(e, t, r, n) {
  40396. var i = 2 * t,
  40397. s = 2 * r;
  40398. return e[i] < e[s] || e[i] === e[s] && n[t] <= n[r];
  40399. }
  40400. function G(e, t, r) {
  40401. for (var n = e.heap[r], i = r << 1; i <= e.heap_len && (i < e.heap_len && H(t, e.heap[i + 1], e.heap[i], e.depth) && i++, !H(t, n, e.heap[i], e.depth));) e.heap[r] = e.heap[i], r = i, i <<= 1;
  40402. e.heap[r] = n;
  40403. }
  40404. function K(e, t, r) {
  40405. var n,
  40406. i,
  40407. s,
  40408. a,
  40409. o = 0;
  40410. if (0 !== e.last_lit) for (; n = e.pending_buf[e.d_buf + 2 * o] << 8 | e.pending_buf[e.d_buf + 2 * o + 1], i = e.pending_buf[e.l_buf + o], o++, 0 === n ? L(e, i, t) : (L(e, (s = A[i]) + u + 1, t), 0 !== (a = w[s]) && P(e, i -= I[s], a), L(e, s = N(--n), r), 0 !== (a = k[s]) && P(e, n -= T[s], a)), o < e.last_lit;);
  40411. L(e, m, t);
  40412. }
  40413. function Y(e, t) {
  40414. var r,
  40415. n,
  40416. i,
  40417. s = t.dyn_tree,
  40418. a = t.stat_desc.static_tree,
  40419. o = t.stat_desc.has_stree,
  40420. h = t.stat_desc.elems,
  40421. u = -1;
  40422. for (e.heap_len = 0, e.heap_max = _, r = 0; r < h; r++) 0 !== s[2 * r] ? (e.heap[++e.heap_len] = u = r, e.depth[r] = 0) : s[2 * r + 1] = 0;
  40423. for (; e.heap_len < 2;) s[2 * (i = e.heap[++e.heap_len] = u < 2 ? ++u : 0)] = 1, e.depth[i] = 0, e.opt_len--, o && (e.static_len -= a[2 * i + 1]);
  40424. for (t.max_code = u, r = e.heap_len >> 1; 1 <= r; r--) G(e, s, r);
  40425. for (i = h; r = e.heap[1], e.heap[1] = e.heap[e.heap_len--], G(e, s, 1), n = e.heap[1], e.heap[--e.heap_max] = r, e.heap[--e.heap_max] = n, s[2 * i] = s[2 * r] + s[2 * n], e.depth[i] = (e.depth[r] >= e.depth[n] ? e.depth[r] : e.depth[n]) + 1, s[2 * r + 1] = s[2 * n + 1] = i, e.heap[1] = i++, G(e, s, 1), 2 <= e.heap_len;);
  40426. e.heap[--e.heap_max] = e.heap[1], function (e, t) {
  40427. var r,
  40428. n,
  40429. i,
  40430. s,
  40431. a,
  40432. o,
  40433. h = t.dyn_tree,
  40434. u = t.max_code,
  40435. l = t.stat_desc.static_tree,
  40436. f = t.stat_desc.has_stree,
  40437. c = t.stat_desc.extra_bits,
  40438. d = t.stat_desc.extra_base,
  40439. p = t.stat_desc.max_length,
  40440. m = 0;
  40441. for (s = 0; s <= g; s++) e.bl_count[s] = 0;
  40442. for (h[2 * e.heap[e.heap_max] + 1] = 0, r = e.heap_max + 1; r < _; r++) p < (s = h[2 * h[2 * (n = e.heap[r]) + 1] + 1] + 1) && (s = p, m++), h[2 * n + 1] = s, u < n || (e.bl_count[s]++, a = 0, d <= n && (a = c[n - d]), o = h[2 * n], e.opt_len += o * (s + a), f && (e.static_len += o * (l[2 * n + 1] + a)));
  40443. if (0 !== m) {
  40444. do {
  40445. for (s = p - 1; 0 === e.bl_count[s];) s--;
  40446. e.bl_count[s]--, e.bl_count[s + 1] += 2, e.bl_count[p]--, m -= 2;
  40447. } while (0 < m);
  40448. for (s = p; 0 !== s; s--) for (n = e.bl_count[s]; 0 !== n;) u < (i = e.heap[--r]) || (h[2 * i + 1] !== s && (e.opt_len += (s - h[2 * i + 1]) * h[2 * i], h[2 * i + 1] = s), n--);
  40449. }
  40450. }(e, t), Z(s, u, e.bl_count);
  40451. }
  40452. function X(e, t, r) {
  40453. var n,
  40454. i,
  40455. s = -1,
  40456. a = t[1],
  40457. o = 0,
  40458. h = 7,
  40459. u = 4;
  40460. for (0 === a && (h = 138, u = 3), t[2 * (r + 1) + 1] = 65535, n = 0; n <= r; n++) i = a, a = t[2 * (n + 1) + 1], ++o < h && i === a || (o < u ? e.bl_tree[2 * i] += o : 0 !== i ? (i !== s && e.bl_tree[2 * i]++, e.bl_tree[2 * b]++) : o <= 10 ? e.bl_tree[2 * v]++ : e.bl_tree[2 * y]++, s = i, u = (o = 0) === a ? (h = 138, 3) : i === a ? (h = 6, 3) : (h = 7, 4));
  40461. }
  40462. function V(e, t, r) {
  40463. var n,
  40464. i,
  40465. s = -1,
  40466. a = t[1],
  40467. o = 0,
  40468. h = 7,
  40469. u = 4;
  40470. for (0 === a && (h = 138, u = 3), n = 0; n <= r; n++) if (i = a, a = t[2 * (n + 1) + 1], !(++o < h && i === a)) {
  40471. if (o < u) for (; L(e, i, e.bl_tree), 0 != --o;);else 0 !== i ? (i !== s && (L(e, i, e.bl_tree), o--), L(e, b, e.bl_tree), P(e, o - 3, 2)) : o <= 10 ? (L(e, v, e.bl_tree), P(e, o - 3, 3)) : (L(e, y, e.bl_tree), P(e, o - 11, 7));
  40472. s = i, u = (o = 0) === a ? (h = 138, 3) : i === a ? (h = 6, 3) : (h = 7, 4);
  40473. }
  40474. }
  40475. n(T);
  40476. var q = !1;
  40477. function J(e, t, r, n) {
  40478. P(e, (s << 1) + (n ? 1 : 0), 3), function (e, t, r, n) {
  40479. M(e), n && (U(e, r), U(e, ~r)), i.arraySet(e.pending_buf, e.window, t, r, e.pending), e.pending += r;
  40480. }(e, t, r, !0);
  40481. }
  40482. r._tr_init = function (e) {
  40483. q || (function () {
  40484. var e,
  40485. t,
  40486. r,
  40487. n,
  40488. i,
  40489. s = new Array(g + 1);
  40490. for (n = r = 0; n < a - 1; n++) for (I[n] = r, e = 0; e < 1 << w[n]; e++) A[r++] = n;
  40491. for (A[r - 1] = n, n = i = 0; n < 16; n++) for (T[n] = i, e = 0; e < 1 << k[n]; e++) E[i++] = n;
  40492. for (i >>= 7; n < f; n++) for (T[n] = i << 7, e = 0; e < 1 << k[n] - 7; e++) E[256 + i++] = n;
  40493. for (t = 0; t <= g; t++) s[t] = 0;
  40494. for (e = 0; e <= 143;) z[2 * e + 1] = 8, e++, s[8]++;
  40495. for (; e <= 255;) z[2 * e + 1] = 9, e++, s[9]++;
  40496. for (; e <= 279;) z[2 * e + 1] = 7, e++, s[7]++;
  40497. for (; e <= 287;) z[2 * e + 1] = 8, e++, s[8]++;
  40498. for (Z(z, l + 1, s), e = 0; e < f; e++) C[2 * e + 1] = 5, C[2 * e] = j(e, 5);
  40499. O = new D(z, w, u + 1, l, g), B = new D(C, k, 0, f, g), R = new D(new Array(0), x, 0, c, p);
  40500. }(), q = !0), e.l_desc = new F(e.dyn_ltree, O), e.d_desc = new F(e.dyn_dtree, B), e.bl_desc = new F(e.bl_tree, R), e.bi_buf = 0, e.bi_valid = 0, W(e);
  40501. }, r._tr_stored_block = J, r._tr_flush_block = function (e, t, r, n) {
  40502. var i,
  40503. s,
  40504. a = 0;
  40505. 0 < e.level ? (2 === e.strm.data_type && (e.strm.data_type = function (e) {
  40506. var t,
  40507. r = 4093624447;
  40508. for (t = 0; t <= 31; t++, r >>>= 1) if (1 & r && 0 !== e.dyn_ltree[2 * t]) return o;
  40509. if (0 !== e.dyn_ltree[18] || 0 !== e.dyn_ltree[20] || 0 !== e.dyn_ltree[26]) return h;
  40510. for (t = 32; t < u; t++) if (0 !== e.dyn_ltree[2 * t]) return h;
  40511. return o;
  40512. }(e)), Y(e, e.l_desc), Y(e, e.d_desc), a = function (e) {
  40513. var t;
  40514. for (X(e, e.dyn_ltree, e.l_desc.max_code), X(e, e.dyn_dtree, e.d_desc.max_code), Y(e, e.bl_desc), t = c - 1; 3 <= t && 0 === e.bl_tree[2 * S[t] + 1]; t--);
  40515. return e.opt_len += 3 * (t + 1) + 5 + 5 + 4, t;
  40516. }(e), i = e.opt_len + 3 + 7 >>> 3, (s = e.static_len + 3 + 7 >>> 3) <= i && (i = s)) : i = s = r + 5, r + 4 <= i && -1 !== t ? J(e, t, r, n) : 4 === e.strategy || s === i ? (P(e, 2 + (n ? 1 : 0), 3), K(e, z, C)) : (P(e, 4 + (n ? 1 : 0), 3), function (e, t, r, n) {
  40517. var i;
  40518. for (P(e, t - 257, 5), P(e, r - 1, 5), P(e, n - 4, 4), i = 0; i < n; i++) P(e, e.bl_tree[2 * S[i] + 1], 3);
  40519. V(e, e.dyn_ltree, t - 1), V(e, e.dyn_dtree, r - 1);
  40520. }(e, e.l_desc.max_code + 1, e.d_desc.max_code + 1, a + 1), K(e, e.dyn_ltree, e.dyn_dtree)), W(e), n && M(e);
  40521. }, r._tr_tally = function (e, t, r) {
  40522. return e.pending_buf[e.d_buf + 2 * e.last_lit] = t >>> 8 & 255, e.pending_buf[e.d_buf + 2 * e.last_lit + 1] = 255 & t, e.pending_buf[e.l_buf + e.last_lit] = 255 & r, e.last_lit++, 0 === t ? e.dyn_ltree[2 * r]++ : (e.matches++, t--, e.dyn_ltree[2 * (A[r] + u + 1)]++, e.dyn_dtree[2 * N(t)]++), e.last_lit === e.lit_bufsize - 1;
  40523. }, r._tr_align = function (e) {
  40524. P(e, 2, 3), L(e, m, z), function (e) {
  40525. 16 === e.bi_valid ? (U(e, e.bi_buf), e.bi_buf = 0, e.bi_valid = 0) : 8 <= e.bi_valid && (e.pending_buf[e.pending++] = 255 & e.bi_buf, e.bi_buf >>= 8, e.bi_valid -= 8);
  40526. }(e);
  40527. };
  40528. }, {
  40529. "../utils/common": 41
  40530. }],
  40531. 53: [function (e, t, r) {
  40532. "use strict";
  40533. t.exports = function () {
  40534. this.input = null, this.next_in = 0, this.avail_in = 0, this.total_in = 0, this.output = null, this.next_out = 0, this.avail_out = 0, this.total_out = 0, this.msg = "", this.state = null, this.data_type = 2, this.adler = 0;
  40535. };
  40536. }, {}],
  40537. 54: [function (e, t, r) {
  40538. (function (e) {
  40539. !function (r, n) {
  40540. "use strict";
  40541. if (!r.setImmediate) {
  40542. var i,
  40543. s,
  40544. t,
  40545. a,
  40546. o = 1,
  40547. h = {},
  40548. u = !1,
  40549. l = r.document,
  40550. e = Object.getPrototypeOf && Object.getPrototypeOf(r);
  40551. e = e && e.setTimeout ? e : r, i = "[object process]" === {}.toString.call(r.process) ? function (e) {
  40552. process.nextTick(function () {
  40553. c(e);
  40554. });
  40555. } : function () {
  40556. if (r.postMessage && !r.importScripts) {
  40557. var e = !0,
  40558. t = r.onmessage;
  40559. return r.onmessage = function () {
  40560. e = !1;
  40561. }, r.postMessage("", "*"), r.onmessage = t, e;
  40562. }
  40563. }() ? (a = "setImmediate$" + Math.random() + "$", r.addEventListener ? r.addEventListener("message", d, !1) : r.attachEvent("onmessage", d), function (e) {
  40564. r.postMessage(a + e, "*");
  40565. }) : r.MessageChannel ? ((t = new MessageChannel()).port1.onmessage = function (e) {
  40566. c(e.data);
  40567. }, function (e) {
  40568. t.port2.postMessage(e);
  40569. }) : l && "onreadystatechange" in l.createElement("script") ? (s = l.documentElement, function (e) {
  40570. var t = l.createElement("script");
  40571. t.onreadystatechange = function () {
  40572. c(e), t.onreadystatechange = null, s.removeChild(t), t = null;
  40573. }, s.appendChild(t);
  40574. }) : function (e) {
  40575. setTimeout(c, 0, e);
  40576. }, e.setImmediate = function (e) {
  40577. "function" != typeof e && (e = new Function("" + e));
  40578. for (var t = new Array(arguments.length - 1), r = 0; r < t.length; r++) t[r] = arguments[r + 1];
  40579. var n = {
  40580. callback: e,
  40581. args: t
  40582. };
  40583. return h[o] = n, i(o), o++;
  40584. }, e.clearImmediate = f;
  40585. }
  40586. function f(e) {
  40587. delete h[e];
  40588. }
  40589. function c(e) {
  40590. if (u) setTimeout(c, 0, e);else {
  40591. var t = h[e];
  40592. if (t) {
  40593. u = !0;
  40594. try {
  40595. !function (e) {
  40596. var t = e.callback,
  40597. r = e.args;
  40598. switch (r.length) {
  40599. case 0:
  40600. t();
  40601. break;
  40602. case 1:
  40603. t(r[0]);
  40604. break;
  40605. case 2:
  40606. t(r[0], r[1]);
  40607. break;
  40608. case 3:
  40609. t(r[0], r[1], r[2]);
  40610. break;
  40611. default:
  40612. t.apply(n, r);
  40613. }
  40614. }(t);
  40615. } finally {
  40616. f(e), u = !1;
  40617. }
  40618. }
  40619. }
  40620. }
  40621. function d(e) {
  40622. e.source === r && "string" == typeof e.data && 0 === e.data.indexOf(a) && c(+e.data.slice(a.length));
  40623. }
  40624. }("undefined" == typeof self ? void 0 === e ? this : e : self);
  40625. }).call(this, "undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {});
  40626. }, {}]
  40627. }, {}, [10])(10);
  40628. });
  40629. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],require("timers").setImmediate)
  40630. },{"_process":467,"buffer":220,"timers":523}],442:[function(require,module,exports){
  40631. (function (global){(function (){
  40632. "use strict";
  40633. /**
  40634. * lodash (Custom Build) <https://lodash.com/>
  40635. * Build: `lodash modularize exports="npm" -o ./`
  40636. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  40637. * Released under MIT license <https://lodash.com/license>
  40638. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  40639. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  40640. */
  40641. /** Used as references for various `Number` constants. */
  40642. var INFINITY = 1 / 0;
  40643. /** `Object#toString` result references. */
  40644. var symbolTag = '[object Symbol]';
  40645. /**
  40646. * Used to match `RegExp`
  40647. * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
  40648. */
  40649. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  40650. reHasRegExpChar = RegExp(reRegExpChar.source);
  40651. /** Detect free variable `global` from Node.js. */
  40652. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  40653. /** Detect free variable `self`. */
  40654. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  40655. /** Used as a reference to the global object. */
  40656. var root = freeGlobal || freeSelf || Function('return this')();
  40657. /** Used for built-in method references. */
  40658. var objectProto = Object.prototype;
  40659. /**
  40660. * Used to resolve the
  40661. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  40662. * of values.
  40663. */
  40664. var objectToString = objectProto.toString;
  40665. /** Built-in value references. */
  40666. var Symbol = root.Symbol;
  40667. /** Used to convert symbols to primitives and strings. */
  40668. var symbolProto = Symbol ? Symbol.prototype : undefined,
  40669. symbolToString = symbolProto ? symbolProto.toString : undefined;
  40670. /**
  40671. * The base implementation of `_.toString` which doesn't convert nullish
  40672. * values to empty strings.
  40673. *
  40674. * @private
  40675. * @param {*} value The value to process.
  40676. * @returns {string} Returns the string.
  40677. */
  40678. function baseToString(value) {
  40679. // Exit early for strings to avoid a performance hit in some environments.
  40680. if (typeof value == 'string') {
  40681. return value;
  40682. }
  40683. if (isSymbol(value)) {
  40684. return symbolToString ? symbolToString.call(value) : '';
  40685. }
  40686. var result = value + '';
  40687. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  40688. }
  40689. /**
  40690. * Checks if `value` is object-like. A value is object-like if it's not `null`
  40691. * and has a `typeof` result of "object".
  40692. *
  40693. * @static
  40694. * @memberOf _
  40695. * @since 4.0.0
  40696. * @category Lang
  40697. * @param {*} value The value to check.
  40698. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  40699. * @example
  40700. *
  40701. * _.isObjectLike({});
  40702. * // => true
  40703. *
  40704. * _.isObjectLike([1, 2, 3]);
  40705. * // => true
  40706. *
  40707. * _.isObjectLike(_.noop);
  40708. * // => false
  40709. *
  40710. * _.isObjectLike(null);
  40711. * // => false
  40712. */
  40713. function isObjectLike(value) {
  40714. return !!value && typeof value == 'object';
  40715. }
  40716. /**
  40717. * Checks if `value` is classified as a `Symbol` primitive or object.
  40718. *
  40719. * @static
  40720. * @memberOf _
  40721. * @since 4.0.0
  40722. * @category Lang
  40723. * @param {*} value The value to check.
  40724. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  40725. * @example
  40726. *
  40727. * _.isSymbol(Symbol.iterator);
  40728. * // => true
  40729. *
  40730. * _.isSymbol('abc');
  40731. * // => false
  40732. */
  40733. function isSymbol(value) {
  40734. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  40735. }
  40736. /**
  40737. * Converts `value` to a string. An empty string is returned for `null`
  40738. * and `undefined` values. The sign of `-0` is preserved.
  40739. *
  40740. * @static
  40741. * @memberOf _
  40742. * @since 4.0.0
  40743. * @category Lang
  40744. * @param {*} value The value to process.
  40745. * @returns {string} Returns the string.
  40746. * @example
  40747. *
  40748. * _.toString(null);
  40749. * // => ''
  40750. *
  40751. * _.toString(-0);
  40752. * // => '-0'
  40753. *
  40754. * _.toString([1, 2, 3]);
  40755. * // => '1,2,3'
  40756. */
  40757. function toString(value) {
  40758. return value == null ? '' : baseToString(value);
  40759. }
  40760. /**
  40761. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  40762. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  40763. *
  40764. * @static
  40765. * @memberOf _
  40766. * @since 3.0.0
  40767. * @category String
  40768. * @param {string} [string=''] The string to escape.
  40769. * @returns {string} Returns the escaped string.
  40770. * @example
  40771. *
  40772. * _.escapeRegExp('[lodash](https://lodash.com/)');
  40773. * // => '\[lodash\]\(https://lodash\.com/\)'
  40774. */
  40775. function escapeRegExp(string) {
  40776. string = toString(string);
  40777. return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string;
  40778. }
  40779. module.exports = escapeRegExp;
  40780. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  40781. },{}],443:[function(require,module,exports){
  40782. (function (global){(function (){
  40783. "use strict";
  40784. /**
  40785. * lodash (Custom Build) <https://lodash.com/>
  40786. * Build: `lodash modularize exports="npm" -o ./`
  40787. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  40788. * Released under MIT license <https://lodash.com/license>
  40789. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  40790. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  40791. */
  40792. /** Used as the size to enable large array optimizations. */
  40793. var LARGE_ARRAY_SIZE = 200;
  40794. /** Used as the `TypeError` message for "Functions" methods. */
  40795. var FUNC_ERROR_TEXT = 'Expected a function';
  40796. /** Used to stand-in for `undefined` hash values. */
  40797. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  40798. /** Used to compose bitmasks for comparison styles. */
  40799. var UNORDERED_COMPARE_FLAG = 1,
  40800. PARTIAL_COMPARE_FLAG = 2;
  40801. /** Used as references for various `Number` constants. */
  40802. var INFINITY = 1 / 0,
  40803. MAX_SAFE_INTEGER = 9007199254740991;
  40804. /** `Object#toString` result references. */
  40805. var argsTag = '[object Arguments]',
  40806. arrayTag = '[object Array]',
  40807. boolTag = '[object Boolean]',
  40808. dateTag = '[object Date]',
  40809. errorTag = '[object Error]',
  40810. funcTag = '[object Function]',
  40811. genTag = '[object GeneratorFunction]',
  40812. mapTag = '[object Map]',
  40813. numberTag = '[object Number]',
  40814. objectTag = '[object Object]',
  40815. promiseTag = '[object Promise]',
  40816. regexpTag = '[object RegExp]',
  40817. setTag = '[object Set]',
  40818. stringTag = '[object String]',
  40819. symbolTag = '[object Symbol]',
  40820. weakMapTag = '[object WeakMap]';
  40821. var arrayBufferTag = '[object ArrayBuffer]',
  40822. dataViewTag = '[object DataView]',
  40823. float32Tag = '[object Float32Array]',
  40824. float64Tag = '[object Float64Array]',
  40825. int8Tag = '[object Int8Array]',
  40826. int16Tag = '[object Int16Array]',
  40827. int32Tag = '[object Int32Array]',
  40828. uint8Tag = '[object Uint8Array]',
  40829. uint8ClampedTag = '[object Uint8ClampedArray]',
  40830. uint16Tag = '[object Uint16Array]',
  40831. uint32Tag = '[object Uint32Array]';
  40832. /** Used to match property names within property paths. */
  40833. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  40834. reIsPlainProp = /^\w*$/,
  40835. reLeadingDot = /^\./,
  40836. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  40837. /**
  40838. * Used to match `RegExp`
  40839. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  40840. */
  40841. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  40842. /** Used to match backslashes in property paths. */
  40843. var reEscapeChar = /\\(\\)?/g;
  40844. /** Used to detect host constructors (Safari). */
  40845. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  40846. /** Used to detect unsigned integer values. */
  40847. var reIsUint = /^(?:0|[1-9]\d*)$/;
  40848. /** Used to identify `toStringTag` values of typed arrays. */
  40849. var typedArrayTags = {};
  40850. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  40851. typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  40852. /** Detect free variable `global` from Node.js. */
  40853. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  40854. /** Detect free variable `self`. */
  40855. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  40856. /** Used as a reference to the global object. */
  40857. var root = freeGlobal || freeSelf || Function('return this')();
  40858. /** Detect free variable `exports`. */
  40859. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  40860. /** Detect free variable `module`. */
  40861. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  40862. /** Detect the popular CommonJS extension `module.exports`. */
  40863. var moduleExports = freeModule && freeModule.exports === freeExports;
  40864. /** Detect free variable `process` from Node.js. */
  40865. var freeProcess = moduleExports && freeGlobal.process;
  40866. /** Used to access faster Node.js helpers. */
  40867. var nodeUtil = function () {
  40868. try {
  40869. return freeProcess && freeProcess.binding('util');
  40870. } catch (e) {}
  40871. }();
  40872. /* Node.js helper references. */
  40873. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  40874. /**
  40875. * A specialized version of `baseAggregator` for arrays.
  40876. *
  40877. * @private
  40878. * @param {Array} [array] The array to iterate over.
  40879. * @param {Function} setter The function to set `accumulator` values.
  40880. * @param {Function} iteratee The iteratee to transform keys.
  40881. * @param {Object} accumulator The initial aggregated object.
  40882. * @returns {Function} Returns `accumulator`.
  40883. */
  40884. function arrayAggregator(array, setter, iteratee, accumulator) {
  40885. var index = -1,
  40886. length = array ? array.length : 0;
  40887. while (++index < length) {
  40888. var value = array[index];
  40889. setter(accumulator, value, iteratee(value), array);
  40890. }
  40891. return accumulator;
  40892. }
  40893. /**
  40894. * A specialized version of `_.some` for arrays without support for iteratee
  40895. * shorthands.
  40896. *
  40897. * @private
  40898. * @param {Array} [array] The array to iterate over.
  40899. * @param {Function} predicate The function invoked per iteration.
  40900. * @returns {boolean} Returns `true` if any element passes the predicate check,
  40901. * else `false`.
  40902. */
  40903. function arraySome(array, predicate) {
  40904. var index = -1,
  40905. length = array ? array.length : 0;
  40906. while (++index < length) {
  40907. if (predicate(array[index], index, array)) {
  40908. return true;
  40909. }
  40910. }
  40911. return false;
  40912. }
  40913. /**
  40914. * The base implementation of `_.property` without support for deep paths.
  40915. *
  40916. * @private
  40917. * @param {string} key The key of the property to get.
  40918. * @returns {Function} Returns the new accessor function.
  40919. */
  40920. function baseProperty(key) {
  40921. return function (object) {
  40922. return object == null ? undefined : object[key];
  40923. };
  40924. }
  40925. /**
  40926. * The base implementation of `_.times` without support for iteratee shorthands
  40927. * or max array length checks.
  40928. *
  40929. * @private
  40930. * @param {number} n The number of times to invoke `iteratee`.
  40931. * @param {Function} iteratee The function invoked per iteration.
  40932. * @returns {Array} Returns the array of results.
  40933. */
  40934. function baseTimes(n, iteratee) {
  40935. var index = -1,
  40936. result = Array(n);
  40937. while (++index < n) {
  40938. result[index] = iteratee(index);
  40939. }
  40940. return result;
  40941. }
  40942. /**
  40943. * The base implementation of `_.unary` without support for storing metadata.
  40944. *
  40945. * @private
  40946. * @param {Function} func The function to cap arguments for.
  40947. * @returns {Function} Returns the new capped function.
  40948. */
  40949. function baseUnary(func) {
  40950. return function (value) {
  40951. return func(value);
  40952. };
  40953. }
  40954. /**
  40955. * Gets the value at `key` of `object`.
  40956. *
  40957. * @private
  40958. * @param {Object} [object] The object to query.
  40959. * @param {string} key The key of the property to get.
  40960. * @returns {*} Returns the property value.
  40961. */
  40962. function getValue(object, key) {
  40963. return object == null ? undefined : object[key];
  40964. }
  40965. /**
  40966. * Checks if `value` is a host object in IE < 9.
  40967. *
  40968. * @private
  40969. * @param {*} value The value to check.
  40970. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  40971. */
  40972. function isHostObject(value) {
  40973. // Many host objects are `Object` objects that can coerce to strings
  40974. // despite having improperly defined `toString` methods.
  40975. var result = false;
  40976. if (value != null && typeof value.toString != 'function') {
  40977. try {
  40978. result = !!(value + '');
  40979. } catch (e) {}
  40980. }
  40981. return result;
  40982. }
  40983. /**
  40984. * Converts `map` to its key-value pairs.
  40985. *
  40986. * @private
  40987. * @param {Object} map The map to convert.
  40988. * @returns {Array} Returns the key-value pairs.
  40989. */
  40990. function mapToArray(map) {
  40991. var index = -1,
  40992. result = Array(map.size);
  40993. map.forEach(function (value, key) {
  40994. result[++index] = [key, value];
  40995. });
  40996. return result;
  40997. }
  40998. /**
  40999. * Creates a unary function that invokes `func` with its argument transformed.
  41000. *
  41001. * @private
  41002. * @param {Function} func The function to wrap.
  41003. * @param {Function} transform The argument transform.
  41004. * @returns {Function} Returns the new function.
  41005. */
  41006. function overArg(func, transform) {
  41007. return function (arg) {
  41008. return func(transform(arg));
  41009. };
  41010. }
  41011. /**
  41012. * Converts `set` to an array of its values.
  41013. *
  41014. * @private
  41015. * @param {Object} set The set to convert.
  41016. * @returns {Array} Returns the values.
  41017. */
  41018. function setToArray(set) {
  41019. var index = -1,
  41020. result = Array(set.size);
  41021. set.forEach(function (value) {
  41022. result[++index] = value;
  41023. });
  41024. return result;
  41025. }
  41026. /** Used for built-in method references. */
  41027. var arrayProto = Array.prototype,
  41028. funcProto = Function.prototype,
  41029. objectProto = Object.prototype;
  41030. /** Used to detect overreaching core-js shims. */
  41031. var coreJsData = root['__core-js_shared__'];
  41032. /** Used to detect methods masquerading as native. */
  41033. var maskSrcKey = function () {
  41034. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  41035. return uid ? 'Symbol(src)_1.' + uid : '';
  41036. }();
  41037. /** Used to resolve the decompiled source of functions. */
  41038. var funcToString = funcProto.toString;
  41039. /** Used to check objects for own properties. */
  41040. var hasOwnProperty = objectProto.hasOwnProperty;
  41041. /**
  41042. * Used to resolve the
  41043. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  41044. * of values.
  41045. */
  41046. var objectToString = objectProto.toString;
  41047. /** Used to detect if a method is native. */
  41048. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  41049. /** Built-in value references. */
  41050. var Symbol = root.Symbol,
  41051. Uint8Array = root.Uint8Array,
  41052. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  41053. splice = arrayProto.splice;
  41054. /* Built-in method references for those with the same name as other `lodash` methods. */
  41055. var nativeKeys = overArg(Object.keys, Object);
  41056. /* Built-in method references that are verified to be native. */
  41057. var DataView = getNative(root, 'DataView'),
  41058. Map = getNative(root, 'Map'),
  41059. Promise = getNative(root, 'Promise'),
  41060. Set = getNative(root, 'Set'),
  41061. WeakMap = getNative(root, 'WeakMap'),
  41062. nativeCreate = getNative(Object, 'create');
  41063. /** Used to detect maps, sets, and weakmaps. */
  41064. var dataViewCtorString = toSource(DataView),
  41065. mapCtorString = toSource(Map),
  41066. promiseCtorString = toSource(Promise),
  41067. setCtorString = toSource(Set),
  41068. weakMapCtorString = toSource(WeakMap);
  41069. /** Used to convert symbols to primitives and strings. */
  41070. var symbolProto = Symbol ? Symbol.prototype : undefined,
  41071. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  41072. symbolToString = symbolProto ? symbolProto.toString : undefined;
  41073. /**
  41074. * Creates a hash object.
  41075. *
  41076. * @private
  41077. * @constructor
  41078. * @param {Array} [entries] The key-value pairs to cache.
  41079. */
  41080. function Hash(entries) {
  41081. var index = -1,
  41082. length = entries ? entries.length : 0;
  41083. this.clear();
  41084. while (++index < length) {
  41085. var entry = entries[index];
  41086. this.set(entry[0], entry[1]);
  41087. }
  41088. }
  41089. /**
  41090. * Removes all key-value entries from the hash.
  41091. *
  41092. * @private
  41093. * @name clear
  41094. * @memberOf Hash
  41095. */
  41096. function hashClear() {
  41097. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  41098. }
  41099. /**
  41100. * Removes `key` and its value from the hash.
  41101. *
  41102. * @private
  41103. * @name delete
  41104. * @memberOf Hash
  41105. * @param {Object} hash The hash to modify.
  41106. * @param {string} key The key of the value to remove.
  41107. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  41108. */
  41109. function hashDelete(key) {
  41110. return this.has(key) && delete this.__data__[key];
  41111. }
  41112. /**
  41113. * Gets the hash value for `key`.
  41114. *
  41115. * @private
  41116. * @name get
  41117. * @memberOf Hash
  41118. * @param {string} key The key of the value to get.
  41119. * @returns {*} Returns the entry value.
  41120. */
  41121. function hashGet(key) {
  41122. var data = this.__data__;
  41123. if (nativeCreate) {
  41124. var result = data[key];
  41125. return result === HASH_UNDEFINED ? undefined : result;
  41126. }
  41127. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  41128. }
  41129. /**
  41130. * Checks if a hash value for `key` exists.
  41131. *
  41132. * @private
  41133. * @name has
  41134. * @memberOf Hash
  41135. * @param {string} key The key of the entry to check.
  41136. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  41137. */
  41138. function hashHas(key) {
  41139. var data = this.__data__;
  41140. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  41141. }
  41142. /**
  41143. * Sets the hash `key` to `value`.
  41144. *
  41145. * @private
  41146. * @name set
  41147. * @memberOf Hash
  41148. * @param {string} key The key of the value to set.
  41149. * @param {*} value The value to set.
  41150. * @returns {Object} Returns the hash instance.
  41151. */
  41152. function hashSet(key, value) {
  41153. var data = this.__data__;
  41154. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  41155. return this;
  41156. }
  41157. // Add methods to `Hash`.
  41158. Hash.prototype.clear = hashClear;
  41159. Hash.prototype['delete'] = hashDelete;
  41160. Hash.prototype.get = hashGet;
  41161. Hash.prototype.has = hashHas;
  41162. Hash.prototype.set = hashSet;
  41163. /**
  41164. * Creates an list cache object.
  41165. *
  41166. * @private
  41167. * @constructor
  41168. * @param {Array} [entries] The key-value pairs to cache.
  41169. */
  41170. function ListCache(entries) {
  41171. var index = -1,
  41172. length = entries ? entries.length : 0;
  41173. this.clear();
  41174. while (++index < length) {
  41175. var entry = entries[index];
  41176. this.set(entry[0], entry[1]);
  41177. }
  41178. }
  41179. /**
  41180. * Removes all key-value entries from the list cache.
  41181. *
  41182. * @private
  41183. * @name clear
  41184. * @memberOf ListCache
  41185. */
  41186. function listCacheClear() {
  41187. this.__data__ = [];
  41188. }
  41189. /**
  41190. * Removes `key` and its value from the list cache.
  41191. *
  41192. * @private
  41193. * @name delete
  41194. * @memberOf ListCache
  41195. * @param {string} key The key of the value to remove.
  41196. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  41197. */
  41198. function listCacheDelete(key) {
  41199. var data = this.__data__,
  41200. index = assocIndexOf(data, key);
  41201. if (index < 0) {
  41202. return false;
  41203. }
  41204. var lastIndex = data.length - 1;
  41205. if (index == lastIndex) {
  41206. data.pop();
  41207. } else {
  41208. splice.call(data, index, 1);
  41209. }
  41210. return true;
  41211. }
  41212. /**
  41213. * Gets the list cache value for `key`.
  41214. *
  41215. * @private
  41216. * @name get
  41217. * @memberOf ListCache
  41218. * @param {string} key The key of the value to get.
  41219. * @returns {*} Returns the entry value.
  41220. */
  41221. function listCacheGet(key) {
  41222. var data = this.__data__,
  41223. index = assocIndexOf(data, key);
  41224. return index < 0 ? undefined : data[index][1];
  41225. }
  41226. /**
  41227. * Checks if a list cache value for `key` exists.
  41228. *
  41229. * @private
  41230. * @name has
  41231. * @memberOf ListCache
  41232. * @param {string} key The key of the entry to check.
  41233. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  41234. */
  41235. function listCacheHas(key) {
  41236. return assocIndexOf(this.__data__, key) > -1;
  41237. }
  41238. /**
  41239. * Sets the list cache `key` to `value`.
  41240. *
  41241. * @private
  41242. * @name set
  41243. * @memberOf ListCache
  41244. * @param {string} key The key of the value to set.
  41245. * @param {*} value The value to set.
  41246. * @returns {Object} Returns the list cache instance.
  41247. */
  41248. function listCacheSet(key, value) {
  41249. var data = this.__data__,
  41250. index = assocIndexOf(data, key);
  41251. if (index < 0) {
  41252. data.push([key, value]);
  41253. } else {
  41254. data[index][1] = value;
  41255. }
  41256. return this;
  41257. }
  41258. // Add methods to `ListCache`.
  41259. ListCache.prototype.clear = listCacheClear;
  41260. ListCache.prototype['delete'] = listCacheDelete;
  41261. ListCache.prototype.get = listCacheGet;
  41262. ListCache.prototype.has = listCacheHas;
  41263. ListCache.prototype.set = listCacheSet;
  41264. /**
  41265. * Creates a map cache object to store key-value pairs.
  41266. *
  41267. * @private
  41268. * @constructor
  41269. * @param {Array} [entries] The key-value pairs to cache.
  41270. */
  41271. function MapCache(entries) {
  41272. var index = -1,
  41273. length = entries ? entries.length : 0;
  41274. this.clear();
  41275. while (++index < length) {
  41276. var entry = entries[index];
  41277. this.set(entry[0], entry[1]);
  41278. }
  41279. }
  41280. /**
  41281. * Removes all key-value entries from the map.
  41282. *
  41283. * @private
  41284. * @name clear
  41285. * @memberOf MapCache
  41286. */
  41287. function mapCacheClear() {
  41288. this.__data__ = {
  41289. 'hash': new Hash(),
  41290. 'map': new (Map || ListCache)(),
  41291. 'string': new Hash()
  41292. };
  41293. }
  41294. /**
  41295. * Removes `key` and its value from the map.
  41296. *
  41297. * @private
  41298. * @name delete
  41299. * @memberOf MapCache
  41300. * @param {string} key The key of the value to remove.
  41301. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  41302. */
  41303. function mapCacheDelete(key) {
  41304. return getMapData(this, key)['delete'](key);
  41305. }
  41306. /**
  41307. * Gets the map value for `key`.
  41308. *
  41309. * @private
  41310. * @name get
  41311. * @memberOf MapCache
  41312. * @param {string} key The key of the value to get.
  41313. * @returns {*} Returns the entry value.
  41314. */
  41315. function mapCacheGet(key) {
  41316. return getMapData(this, key).get(key);
  41317. }
  41318. /**
  41319. * Checks if a map value for `key` exists.
  41320. *
  41321. * @private
  41322. * @name has
  41323. * @memberOf MapCache
  41324. * @param {string} key The key of the entry to check.
  41325. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  41326. */
  41327. function mapCacheHas(key) {
  41328. return getMapData(this, key).has(key);
  41329. }
  41330. /**
  41331. * Sets the map `key` to `value`.
  41332. *
  41333. * @private
  41334. * @name set
  41335. * @memberOf MapCache
  41336. * @param {string} key The key of the value to set.
  41337. * @param {*} value The value to set.
  41338. * @returns {Object} Returns the map cache instance.
  41339. */
  41340. function mapCacheSet(key, value) {
  41341. getMapData(this, key).set(key, value);
  41342. return this;
  41343. }
  41344. // Add methods to `MapCache`.
  41345. MapCache.prototype.clear = mapCacheClear;
  41346. MapCache.prototype['delete'] = mapCacheDelete;
  41347. MapCache.prototype.get = mapCacheGet;
  41348. MapCache.prototype.has = mapCacheHas;
  41349. MapCache.prototype.set = mapCacheSet;
  41350. /**
  41351. *
  41352. * Creates an array cache object to store unique values.
  41353. *
  41354. * @private
  41355. * @constructor
  41356. * @param {Array} [values] The values to cache.
  41357. */
  41358. function SetCache(values) {
  41359. var index = -1,
  41360. length = values ? values.length : 0;
  41361. this.__data__ = new MapCache();
  41362. while (++index < length) {
  41363. this.add(values[index]);
  41364. }
  41365. }
  41366. /**
  41367. * Adds `value` to the array cache.
  41368. *
  41369. * @private
  41370. * @name add
  41371. * @memberOf SetCache
  41372. * @alias push
  41373. * @param {*} value The value to cache.
  41374. * @returns {Object} Returns the cache instance.
  41375. */
  41376. function setCacheAdd(value) {
  41377. this.__data__.set(value, HASH_UNDEFINED);
  41378. return this;
  41379. }
  41380. /**
  41381. * Checks if `value` is in the array cache.
  41382. *
  41383. * @private
  41384. * @name has
  41385. * @memberOf SetCache
  41386. * @param {*} value The value to search for.
  41387. * @returns {number} Returns `true` if `value` is found, else `false`.
  41388. */
  41389. function setCacheHas(value) {
  41390. return this.__data__.has(value);
  41391. }
  41392. // Add methods to `SetCache`.
  41393. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  41394. SetCache.prototype.has = setCacheHas;
  41395. /**
  41396. * Creates a stack cache object to store key-value pairs.
  41397. *
  41398. * @private
  41399. * @constructor
  41400. * @param {Array} [entries] The key-value pairs to cache.
  41401. */
  41402. function Stack(entries) {
  41403. this.__data__ = new ListCache(entries);
  41404. }
  41405. /**
  41406. * Removes all key-value entries from the stack.
  41407. *
  41408. * @private
  41409. * @name clear
  41410. * @memberOf Stack
  41411. */
  41412. function stackClear() {
  41413. this.__data__ = new ListCache();
  41414. }
  41415. /**
  41416. * Removes `key` and its value from the stack.
  41417. *
  41418. * @private
  41419. * @name delete
  41420. * @memberOf Stack
  41421. * @param {string} key The key of the value to remove.
  41422. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  41423. */
  41424. function stackDelete(key) {
  41425. return this.__data__['delete'](key);
  41426. }
  41427. /**
  41428. * Gets the stack value for `key`.
  41429. *
  41430. * @private
  41431. * @name get
  41432. * @memberOf Stack
  41433. * @param {string} key The key of the value to get.
  41434. * @returns {*} Returns the entry value.
  41435. */
  41436. function stackGet(key) {
  41437. return this.__data__.get(key);
  41438. }
  41439. /**
  41440. * Checks if a stack value for `key` exists.
  41441. *
  41442. * @private
  41443. * @name has
  41444. * @memberOf Stack
  41445. * @param {string} key The key of the entry to check.
  41446. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  41447. */
  41448. function stackHas(key) {
  41449. return this.__data__.has(key);
  41450. }
  41451. /**
  41452. * Sets the stack `key` to `value`.
  41453. *
  41454. * @private
  41455. * @name set
  41456. * @memberOf Stack
  41457. * @param {string} key The key of the value to set.
  41458. * @param {*} value The value to set.
  41459. * @returns {Object} Returns the stack cache instance.
  41460. */
  41461. function stackSet(key, value) {
  41462. var cache = this.__data__;
  41463. if (cache instanceof ListCache) {
  41464. var pairs = cache.__data__;
  41465. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  41466. pairs.push([key, value]);
  41467. return this;
  41468. }
  41469. cache = this.__data__ = new MapCache(pairs);
  41470. }
  41471. cache.set(key, value);
  41472. return this;
  41473. }
  41474. // Add methods to `Stack`.
  41475. Stack.prototype.clear = stackClear;
  41476. Stack.prototype['delete'] = stackDelete;
  41477. Stack.prototype.get = stackGet;
  41478. Stack.prototype.has = stackHas;
  41479. Stack.prototype.set = stackSet;
  41480. /**
  41481. * Creates an array of the enumerable property names of the array-like `value`.
  41482. *
  41483. * @private
  41484. * @param {*} value The value to query.
  41485. * @param {boolean} inherited Specify returning inherited property names.
  41486. * @returns {Array} Returns the array of property names.
  41487. */
  41488. function arrayLikeKeys(value, inherited) {
  41489. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  41490. // Safari 9 makes `arguments.length` enumerable in strict mode.
  41491. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  41492. var length = result.length,
  41493. skipIndexes = !!length;
  41494. for (var key in value) {
  41495. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  41496. result.push(key);
  41497. }
  41498. }
  41499. return result;
  41500. }
  41501. /**
  41502. * Gets the index at which the `key` is found in `array` of key-value pairs.
  41503. *
  41504. * @private
  41505. * @param {Array} array The array to inspect.
  41506. * @param {*} key The key to search for.
  41507. * @returns {number} Returns the index of the matched value, else `-1`.
  41508. */
  41509. function assocIndexOf(array, key) {
  41510. var length = array.length;
  41511. while (length--) {
  41512. if (eq(array[length][0], key)) {
  41513. return length;
  41514. }
  41515. }
  41516. return -1;
  41517. }
  41518. /**
  41519. * Aggregates elements of `collection` on `accumulator` with keys transformed
  41520. * by `iteratee` and values set by `setter`.
  41521. *
  41522. * @private
  41523. * @param {Array|Object} collection The collection to iterate over.
  41524. * @param {Function} setter The function to set `accumulator` values.
  41525. * @param {Function} iteratee The iteratee to transform keys.
  41526. * @param {Object} accumulator The initial aggregated object.
  41527. * @returns {Function} Returns `accumulator`.
  41528. */
  41529. function baseAggregator(collection, setter, iteratee, accumulator) {
  41530. baseEach(collection, function (value, key, collection) {
  41531. setter(accumulator, value, iteratee(value), collection);
  41532. });
  41533. return accumulator;
  41534. }
  41535. /**
  41536. * The base implementation of `_.forEach` without support for iteratee shorthands.
  41537. *
  41538. * @private
  41539. * @param {Array|Object} collection The collection to iterate over.
  41540. * @param {Function} iteratee The function invoked per iteration.
  41541. * @returns {Array|Object} Returns `collection`.
  41542. */
  41543. var baseEach = createBaseEach(baseForOwn);
  41544. /**
  41545. * The base implementation of `baseForOwn` which iterates over `object`
  41546. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  41547. * Iteratee functions may exit iteration early by explicitly returning `false`.
  41548. *
  41549. * @private
  41550. * @param {Object} object The object to iterate over.
  41551. * @param {Function} iteratee The function invoked per iteration.
  41552. * @param {Function} keysFunc The function to get the keys of `object`.
  41553. * @returns {Object} Returns `object`.
  41554. */
  41555. var baseFor = createBaseFor();
  41556. /**
  41557. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  41558. *
  41559. * @private
  41560. * @param {Object} object The object to iterate over.
  41561. * @param {Function} iteratee The function invoked per iteration.
  41562. * @returns {Object} Returns `object`.
  41563. */
  41564. function baseForOwn(object, iteratee) {
  41565. return object && baseFor(object, iteratee, keys);
  41566. }
  41567. /**
  41568. * The base implementation of `_.get` without support for default values.
  41569. *
  41570. * @private
  41571. * @param {Object} object The object to query.
  41572. * @param {Array|string} path The path of the property to get.
  41573. * @returns {*} Returns the resolved value.
  41574. */
  41575. function baseGet(object, path) {
  41576. path = isKey(path, object) ? [path] : castPath(path);
  41577. var index = 0,
  41578. length = path.length;
  41579. while (object != null && index < length) {
  41580. object = object[toKey(path[index++])];
  41581. }
  41582. return index && index == length ? object : undefined;
  41583. }
  41584. /**
  41585. * The base implementation of `getTag`.
  41586. *
  41587. * @private
  41588. * @param {*} value The value to query.
  41589. * @returns {string} Returns the `toStringTag`.
  41590. */
  41591. function baseGetTag(value) {
  41592. return objectToString.call(value);
  41593. }
  41594. /**
  41595. * The base implementation of `_.hasIn` without support for deep paths.
  41596. *
  41597. * @private
  41598. * @param {Object} [object] The object to query.
  41599. * @param {Array|string} key The key to check.
  41600. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  41601. */
  41602. function baseHasIn(object, key) {
  41603. return object != null && key in Object(object);
  41604. }
  41605. /**
  41606. * The base implementation of `_.isEqual` which supports partial comparisons
  41607. * and tracks traversed objects.
  41608. *
  41609. * @private
  41610. * @param {*} value The value to compare.
  41611. * @param {*} other The other value to compare.
  41612. * @param {Function} [customizer] The function to customize comparisons.
  41613. * @param {boolean} [bitmask] The bitmask of comparison flags.
  41614. * The bitmask may be composed of the following flags:
  41615. * 1 - Unordered comparison
  41616. * 2 - Partial comparison
  41617. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  41618. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  41619. */
  41620. function baseIsEqual(value, other, customizer, bitmask, stack) {
  41621. if (value === other) {
  41622. return true;
  41623. }
  41624. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  41625. return value !== value && other !== other;
  41626. }
  41627. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  41628. }
  41629. /**
  41630. * A specialized version of `baseIsEqual` for arrays and objects which performs
  41631. * deep comparisons and tracks traversed objects enabling objects with circular
  41632. * references to be compared.
  41633. *
  41634. * @private
  41635. * @param {Object} object The object to compare.
  41636. * @param {Object} other The other object to compare.
  41637. * @param {Function} equalFunc The function to determine equivalents of values.
  41638. * @param {Function} [customizer] The function to customize comparisons.
  41639. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  41640. * for more details.
  41641. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  41642. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  41643. */
  41644. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  41645. var objIsArr = isArray(object),
  41646. othIsArr = isArray(other),
  41647. objTag = arrayTag,
  41648. othTag = arrayTag;
  41649. if (!objIsArr) {
  41650. objTag = getTag(object);
  41651. objTag = objTag == argsTag ? objectTag : objTag;
  41652. }
  41653. if (!othIsArr) {
  41654. othTag = getTag(other);
  41655. othTag = othTag == argsTag ? objectTag : othTag;
  41656. }
  41657. var objIsObj = objTag == objectTag && !isHostObject(object),
  41658. othIsObj = othTag == objectTag && !isHostObject(other),
  41659. isSameTag = objTag == othTag;
  41660. if (isSameTag && !objIsObj) {
  41661. stack || (stack = new Stack());
  41662. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  41663. }
  41664. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  41665. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  41666. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  41667. if (objIsWrapped || othIsWrapped) {
  41668. var objUnwrapped = objIsWrapped ? object.value() : object,
  41669. othUnwrapped = othIsWrapped ? other.value() : other;
  41670. stack || (stack = new Stack());
  41671. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  41672. }
  41673. }
  41674. if (!isSameTag) {
  41675. return false;
  41676. }
  41677. stack || (stack = new Stack());
  41678. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  41679. }
  41680. /**
  41681. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  41682. *
  41683. * @private
  41684. * @param {Object} object The object to inspect.
  41685. * @param {Object} source The object of property values to match.
  41686. * @param {Array} matchData The property names, values, and compare flags to match.
  41687. * @param {Function} [customizer] The function to customize comparisons.
  41688. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  41689. */
  41690. function baseIsMatch(object, source, matchData, customizer) {
  41691. var index = matchData.length,
  41692. length = index,
  41693. noCustomizer = !customizer;
  41694. if (object == null) {
  41695. return !length;
  41696. }
  41697. object = Object(object);
  41698. while (index--) {
  41699. var data = matchData[index];
  41700. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  41701. return false;
  41702. }
  41703. }
  41704. while (++index < length) {
  41705. data = matchData[index];
  41706. var key = data[0],
  41707. objValue = object[key],
  41708. srcValue = data[1];
  41709. if (noCustomizer && data[2]) {
  41710. if (objValue === undefined && !(key in object)) {
  41711. return false;
  41712. }
  41713. } else {
  41714. var stack = new Stack();
  41715. if (customizer) {
  41716. var result = customizer(objValue, srcValue, key, object, source, stack);
  41717. }
  41718. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  41719. return false;
  41720. }
  41721. }
  41722. }
  41723. return true;
  41724. }
  41725. /**
  41726. * The base implementation of `_.isNative` without bad shim checks.
  41727. *
  41728. * @private
  41729. * @param {*} value The value to check.
  41730. * @returns {boolean} Returns `true` if `value` is a native function,
  41731. * else `false`.
  41732. */
  41733. function baseIsNative(value) {
  41734. if (!isObject(value) || isMasked(value)) {
  41735. return false;
  41736. }
  41737. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  41738. return pattern.test(toSource(value));
  41739. }
  41740. /**
  41741. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  41742. *
  41743. * @private
  41744. * @param {*} value The value to check.
  41745. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  41746. */
  41747. function baseIsTypedArray(value) {
  41748. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  41749. }
  41750. /**
  41751. * The base implementation of `_.iteratee`.
  41752. *
  41753. * @private
  41754. * @param {*} [value=_.identity] The value to convert to an iteratee.
  41755. * @returns {Function} Returns the iteratee.
  41756. */
  41757. function baseIteratee(value) {
  41758. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  41759. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  41760. if (typeof value == 'function') {
  41761. return value;
  41762. }
  41763. if (value == null) {
  41764. return identity;
  41765. }
  41766. if (typeof value == 'object') {
  41767. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  41768. }
  41769. return property(value);
  41770. }
  41771. /**
  41772. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  41773. *
  41774. * @private
  41775. * @param {Object} object The object to query.
  41776. * @returns {Array} Returns the array of property names.
  41777. */
  41778. function baseKeys(object) {
  41779. if (!isPrototype(object)) {
  41780. return nativeKeys(object);
  41781. }
  41782. var result = [];
  41783. for (var key in Object(object)) {
  41784. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  41785. result.push(key);
  41786. }
  41787. }
  41788. return result;
  41789. }
  41790. /**
  41791. * The base implementation of `_.matches` which doesn't clone `source`.
  41792. *
  41793. * @private
  41794. * @param {Object} source The object of property values to match.
  41795. * @returns {Function} Returns the new spec function.
  41796. */
  41797. function baseMatches(source) {
  41798. var matchData = getMatchData(source);
  41799. if (matchData.length == 1 && matchData[0][2]) {
  41800. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  41801. }
  41802. return function (object) {
  41803. return object === source || baseIsMatch(object, source, matchData);
  41804. };
  41805. }
  41806. /**
  41807. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  41808. *
  41809. * @private
  41810. * @param {string} path The path of the property to get.
  41811. * @param {*} srcValue The value to match.
  41812. * @returns {Function} Returns the new spec function.
  41813. */
  41814. function baseMatchesProperty(path, srcValue) {
  41815. if (isKey(path) && isStrictComparable(srcValue)) {
  41816. return matchesStrictComparable(toKey(path), srcValue);
  41817. }
  41818. return function (object) {
  41819. var objValue = get(object, path);
  41820. return objValue === undefined && objValue === srcValue ? hasIn(object, path) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  41821. };
  41822. }
  41823. /**
  41824. * A specialized version of `baseProperty` which supports deep paths.
  41825. *
  41826. * @private
  41827. * @param {Array|string} path The path of the property to get.
  41828. * @returns {Function} Returns the new accessor function.
  41829. */
  41830. function basePropertyDeep(path) {
  41831. return function (object) {
  41832. return baseGet(object, path);
  41833. };
  41834. }
  41835. /**
  41836. * The base implementation of `_.toString` which doesn't convert nullish
  41837. * values to empty strings.
  41838. *
  41839. * @private
  41840. * @param {*} value The value to process.
  41841. * @returns {string} Returns the string.
  41842. */
  41843. function baseToString(value) {
  41844. // Exit early for strings to avoid a performance hit in some environments.
  41845. if (typeof value == 'string') {
  41846. return value;
  41847. }
  41848. if (isSymbol(value)) {
  41849. return symbolToString ? symbolToString.call(value) : '';
  41850. }
  41851. var result = value + '';
  41852. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  41853. }
  41854. /**
  41855. * Casts `value` to a path array if it's not one.
  41856. *
  41857. * @private
  41858. * @param {*} value The value to inspect.
  41859. * @returns {Array} Returns the cast property path array.
  41860. */
  41861. function castPath(value) {
  41862. return isArray(value) ? value : stringToPath(value);
  41863. }
  41864. /**
  41865. * Creates a function like `_.groupBy`.
  41866. *
  41867. * @private
  41868. * @param {Function} setter The function to set accumulator values.
  41869. * @param {Function} [initializer] The accumulator object initializer.
  41870. * @returns {Function} Returns the new aggregator function.
  41871. */
  41872. function createAggregator(setter, initializer) {
  41873. return function (collection, iteratee) {
  41874. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  41875. accumulator = initializer ? initializer() : {};
  41876. return func(collection, setter, baseIteratee(iteratee, 2), accumulator);
  41877. };
  41878. }
  41879. /**
  41880. * Creates a `baseEach` or `baseEachRight` function.
  41881. *
  41882. * @private
  41883. * @param {Function} eachFunc The function to iterate over a collection.
  41884. * @param {boolean} [fromRight] Specify iterating from right to left.
  41885. * @returns {Function} Returns the new base function.
  41886. */
  41887. function createBaseEach(eachFunc, fromRight) {
  41888. return function (collection, iteratee) {
  41889. if (collection == null) {
  41890. return collection;
  41891. }
  41892. if (!isArrayLike(collection)) {
  41893. return eachFunc(collection, iteratee);
  41894. }
  41895. var length = collection.length,
  41896. index = fromRight ? length : -1,
  41897. iterable = Object(collection);
  41898. while (fromRight ? index-- : ++index < length) {
  41899. if (iteratee(iterable[index], index, iterable) === false) {
  41900. break;
  41901. }
  41902. }
  41903. return collection;
  41904. };
  41905. }
  41906. /**
  41907. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  41908. *
  41909. * @private
  41910. * @param {boolean} [fromRight] Specify iterating from right to left.
  41911. * @returns {Function} Returns the new base function.
  41912. */
  41913. function createBaseFor(fromRight) {
  41914. return function (object, iteratee, keysFunc) {
  41915. var index = -1,
  41916. iterable = Object(object),
  41917. props = keysFunc(object),
  41918. length = props.length;
  41919. while (length--) {
  41920. var key = props[fromRight ? length : ++index];
  41921. if (iteratee(iterable[key], key, iterable) === false) {
  41922. break;
  41923. }
  41924. }
  41925. return object;
  41926. };
  41927. }
  41928. /**
  41929. * A specialized version of `baseIsEqualDeep` for arrays with support for
  41930. * partial deep comparisons.
  41931. *
  41932. * @private
  41933. * @param {Array} array The array to compare.
  41934. * @param {Array} other The other array to compare.
  41935. * @param {Function} equalFunc The function to determine equivalents of values.
  41936. * @param {Function} customizer The function to customize comparisons.
  41937. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  41938. * for more details.
  41939. * @param {Object} stack Tracks traversed `array` and `other` objects.
  41940. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  41941. */
  41942. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  41943. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  41944. arrLength = array.length,
  41945. othLength = other.length;
  41946. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  41947. return false;
  41948. }
  41949. // Assume cyclic values are equal.
  41950. var stacked = stack.get(array);
  41951. if (stacked && stack.get(other)) {
  41952. return stacked == other;
  41953. }
  41954. var index = -1,
  41955. result = true,
  41956. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  41957. stack.set(array, other);
  41958. stack.set(other, array);
  41959. // Ignore non-index properties.
  41960. while (++index < arrLength) {
  41961. var arrValue = array[index],
  41962. othValue = other[index];
  41963. if (customizer) {
  41964. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  41965. }
  41966. if (compared !== undefined) {
  41967. if (compared) {
  41968. continue;
  41969. }
  41970. result = false;
  41971. break;
  41972. }
  41973. // Recursively compare arrays (susceptible to call stack limits).
  41974. if (seen) {
  41975. if (!arraySome(other, function (othValue, othIndex) {
  41976. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  41977. return seen.add(othIndex);
  41978. }
  41979. })) {
  41980. result = false;
  41981. break;
  41982. }
  41983. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  41984. result = false;
  41985. break;
  41986. }
  41987. }
  41988. stack['delete'](array);
  41989. stack['delete'](other);
  41990. return result;
  41991. }
  41992. /**
  41993. * A specialized version of `baseIsEqualDeep` for comparing objects of
  41994. * the same `toStringTag`.
  41995. *
  41996. * **Note:** This function only supports comparing values with tags of
  41997. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  41998. *
  41999. * @private
  42000. * @param {Object} object The object to compare.
  42001. * @param {Object} other The other object to compare.
  42002. * @param {string} tag The `toStringTag` of the objects to compare.
  42003. * @param {Function} equalFunc The function to determine equivalents of values.
  42004. * @param {Function} customizer The function to customize comparisons.
  42005. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  42006. * for more details.
  42007. * @param {Object} stack Tracks traversed `object` and `other` objects.
  42008. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  42009. */
  42010. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  42011. switch (tag) {
  42012. case dataViewTag:
  42013. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  42014. return false;
  42015. }
  42016. object = object.buffer;
  42017. other = other.buffer;
  42018. case arrayBufferTag:
  42019. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  42020. return false;
  42021. }
  42022. return true;
  42023. case boolTag:
  42024. case dateTag:
  42025. case numberTag:
  42026. // Coerce booleans to `1` or `0` and dates to milliseconds.
  42027. // Invalid dates are coerced to `NaN`.
  42028. return eq(+object, +other);
  42029. case errorTag:
  42030. return object.name == other.name && object.message == other.message;
  42031. case regexpTag:
  42032. case stringTag:
  42033. // Coerce regexes to strings and treat strings, primitives and objects,
  42034. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  42035. // for more details.
  42036. return object == other + '';
  42037. case mapTag:
  42038. var convert = mapToArray;
  42039. case setTag:
  42040. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  42041. convert || (convert = setToArray);
  42042. if (object.size != other.size && !isPartial) {
  42043. return false;
  42044. }
  42045. // Assume cyclic values are equal.
  42046. var stacked = stack.get(object);
  42047. if (stacked) {
  42048. return stacked == other;
  42049. }
  42050. bitmask |= UNORDERED_COMPARE_FLAG;
  42051. // Recursively compare objects (susceptible to call stack limits).
  42052. stack.set(object, other);
  42053. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  42054. stack['delete'](object);
  42055. return result;
  42056. case symbolTag:
  42057. if (symbolValueOf) {
  42058. return symbolValueOf.call(object) == symbolValueOf.call(other);
  42059. }
  42060. }
  42061. return false;
  42062. }
  42063. /**
  42064. * A specialized version of `baseIsEqualDeep` for objects with support for
  42065. * partial deep comparisons.
  42066. *
  42067. * @private
  42068. * @param {Object} object The object to compare.
  42069. * @param {Object} other The other object to compare.
  42070. * @param {Function} equalFunc The function to determine equivalents of values.
  42071. * @param {Function} customizer The function to customize comparisons.
  42072. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  42073. * for more details.
  42074. * @param {Object} stack Tracks traversed `object` and `other` objects.
  42075. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  42076. */
  42077. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  42078. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  42079. objProps = keys(object),
  42080. objLength = objProps.length,
  42081. othProps = keys(other),
  42082. othLength = othProps.length;
  42083. if (objLength != othLength && !isPartial) {
  42084. return false;
  42085. }
  42086. var index = objLength;
  42087. while (index--) {
  42088. var key = objProps[index];
  42089. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  42090. return false;
  42091. }
  42092. }
  42093. // Assume cyclic values are equal.
  42094. var stacked = stack.get(object);
  42095. if (stacked && stack.get(other)) {
  42096. return stacked == other;
  42097. }
  42098. var result = true;
  42099. stack.set(object, other);
  42100. stack.set(other, object);
  42101. var skipCtor = isPartial;
  42102. while (++index < objLength) {
  42103. key = objProps[index];
  42104. var objValue = object[key],
  42105. othValue = other[key];
  42106. if (customizer) {
  42107. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  42108. }
  42109. // Recursively compare objects (susceptible to call stack limits).
  42110. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  42111. result = false;
  42112. break;
  42113. }
  42114. skipCtor || (skipCtor = key == 'constructor');
  42115. }
  42116. if (result && !skipCtor) {
  42117. var objCtor = object.constructor,
  42118. othCtor = other.constructor;
  42119. // Non `Object` object instances with different constructors are not equal.
  42120. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  42121. result = false;
  42122. }
  42123. }
  42124. stack['delete'](object);
  42125. stack['delete'](other);
  42126. return result;
  42127. }
  42128. /**
  42129. * Gets the data for `map`.
  42130. *
  42131. * @private
  42132. * @param {Object} map The map to query.
  42133. * @param {string} key The reference key.
  42134. * @returns {*} Returns the map data.
  42135. */
  42136. function getMapData(map, key) {
  42137. var data = map.__data__;
  42138. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  42139. }
  42140. /**
  42141. * Gets the property names, values, and compare flags of `object`.
  42142. *
  42143. * @private
  42144. * @param {Object} object The object to query.
  42145. * @returns {Array} Returns the match data of `object`.
  42146. */
  42147. function getMatchData(object) {
  42148. var result = keys(object),
  42149. length = result.length;
  42150. while (length--) {
  42151. var key = result[length],
  42152. value = object[key];
  42153. result[length] = [key, value, isStrictComparable(value)];
  42154. }
  42155. return result;
  42156. }
  42157. /**
  42158. * Gets the native function at `key` of `object`.
  42159. *
  42160. * @private
  42161. * @param {Object} object The object to query.
  42162. * @param {string} key The key of the method to get.
  42163. * @returns {*} Returns the function if it's native, else `undefined`.
  42164. */
  42165. function getNative(object, key) {
  42166. var value = getValue(object, key);
  42167. return baseIsNative(value) ? value : undefined;
  42168. }
  42169. /**
  42170. * Gets the `toStringTag` of `value`.
  42171. *
  42172. * @private
  42173. * @param {*} value The value to query.
  42174. * @returns {string} Returns the `toStringTag`.
  42175. */
  42176. var getTag = baseGetTag;
  42177. // Fallback for data views, maps, sets, and weak maps in IE 11,
  42178. // for data views in Edge < 14, and promises in Node.js.
  42179. if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise && getTag(Promise.resolve()) != promiseTag || Set && getTag(new Set()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
  42180. getTag = function (value) {
  42181. var result = objectToString.call(value),
  42182. Ctor = result == objectTag ? value.constructor : undefined,
  42183. ctorString = Ctor ? toSource(Ctor) : undefined;
  42184. if (ctorString) {
  42185. switch (ctorString) {
  42186. case dataViewCtorString:
  42187. return dataViewTag;
  42188. case mapCtorString:
  42189. return mapTag;
  42190. case promiseCtorString:
  42191. return promiseTag;
  42192. case setCtorString:
  42193. return setTag;
  42194. case weakMapCtorString:
  42195. return weakMapTag;
  42196. }
  42197. }
  42198. return result;
  42199. };
  42200. }
  42201. /**
  42202. * Checks if `path` exists on `object`.
  42203. *
  42204. * @private
  42205. * @param {Object} object The object to query.
  42206. * @param {Array|string} path The path to check.
  42207. * @param {Function} hasFunc The function to check properties.
  42208. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  42209. */
  42210. function hasPath(object, path, hasFunc) {
  42211. path = isKey(path, object) ? [path] : castPath(path);
  42212. var result,
  42213. index = -1,
  42214. length = path.length;
  42215. while (++index < length) {
  42216. var key = toKey(path[index]);
  42217. if (!(result = object != null && hasFunc(object, key))) {
  42218. break;
  42219. }
  42220. object = object[key];
  42221. }
  42222. if (result) {
  42223. return result;
  42224. }
  42225. var length = object ? object.length : 0;
  42226. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  42227. }
  42228. /**
  42229. * Checks if `value` is a valid array-like index.
  42230. *
  42231. * @private
  42232. * @param {*} value The value to check.
  42233. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  42234. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  42235. */
  42236. function isIndex(value, length) {
  42237. length = length == null ? MAX_SAFE_INTEGER : length;
  42238. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  42239. }
  42240. /**
  42241. * Checks if `value` is a property name and not a property path.
  42242. *
  42243. * @private
  42244. * @param {*} value The value to check.
  42245. * @param {Object} [object] The object to query keys on.
  42246. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  42247. */
  42248. function isKey(value, object) {
  42249. if (isArray(value)) {
  42250. return false;
  42251. }
  42252. var type = typeof value;
  42253. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  42254. return true;
  42255. }
  42256. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  42257. }
  42258. /**
  42259. * Checks if `value` is suitable for use as unique object key.
  42260. *
  42261. * @private
  42262. * @param {*} value The value to check.
  42263. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  42264. */
  42265. function isKeyable(value) {
  42266. var type = typeof value;
  42267. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  42268. }
  42269. /**
  42270. * Checks if `func` has its source masked.
  42271. *
  42272. * @private
  42273. * @param {Function} func The function to check.
  42274. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  42275. */
  42276. function isMasked(func) {
  42277. return !!maskSrcKey && maskSrcKey in func;
  42278. }
  42279. /**
  42280. * Checks if `value` is likely a prototype object.
  42281. *
  42282. * @private
  42283. * @param {*} value The value to check.
  42284. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  42285. */
  42286. function isPrototype(value) {
  42287. var Ctor = value && value.constructor,
  42288. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  42289. return value === proto;
  42290. }
  42291. /**
  42292. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  42293. *
  42294. * @private
  42295. * @param {*} value The value to check.
  42296. * @returns {boolean} Returns `true` if `value` if suitable for strict
  42297. * equality comparisons, else `false`.
  42298. */
  42299. function isStrictComparable(value) {
  42300. return value === value && !isObject(value);
  42301. }
  42302. /**
  42303. * A specialized version of `matchesProperty` for source values suitable
  42304. * for strict equality comparisons, i.e. `===`.
  42305. *
  42306. * @private
  42307. * @param {string} key The key of the property to get.
  42308. * @param {*} srcValue The value to match.
  42309. * @returns {Function} Returns the new spec function.
  42310. */
  42311. function matchesStrictComparable(key, srcValue) {
  42312. return function (object) {
  42313. if (object == null) {
  42314. return false;
  42315. }
  42316. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  42317. };
  42318. }
  42319. /**
  42320. * Converts `string` to a property path array.
  42321. *
  42322. * @private
  42323. * @param {string} string The string to convert.
  42324. * @returns {Array} Returns the property path array.
  42325. */
  42326. var stringToPath = memoize(function (string) {
  42327. string = toString(string);
  42328. var result = [];
  42329. if (reLeadingDot.test(string)) {
  42330. result.push('');
  42331. }
  42332. string.replace(rePropName, function (match, number, quote, string) {
  42333. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  42334. });
  42335. return result;
  42336. });
  42337. /**
  42338. * Converts `value` to a string key if it's not a string or symbol.
  42339. *
  42340. * @private
  42341. * @param {*} value The value to inspect.
  42342. * @returns {string|symbol} Returns the key.
  42343. */
  42344. function toKey(value) {
  42345. if (typeof value == 'string' || isSymbol(value)) {
  42346. return value;
  42347. }
  42348. var result = value + '';
  42349. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  42350. }
  42351. /**
  42352. * Converts `func` to its source code.
  42353. *
  42354. * @private
  42355. * @param {Function} func The function to process.
  42356. * @returns {string} Returns the source code.
  42357. */
  42358. function toSource(func) {
  42359. if (func != null) {
  42360. try {
  42361. return funcToString.call(func);
  42362. } catch (e) {}
  42363. try {
  42364. return func + '';
  42365. } catch (e) {}
  42366. }
  42367. return '';
  42368. }
  42369. /**
  42370. * Creates an object composed of keys generated from the results of running
  42371. * each element of `collection` thru `iteratee`. The order of grouped values
  42372. * is determined by the order they occur in `collection`. The corresponding
  42373. * value of each key is an array of elements responsible for generating the
  42374. * key. The iteratee is invoked with one argument: (value).
  42375. *
  42376. * @static
  42377. * @memberOf _
  42378. * @since 0.1.0
  42379. * @category Collection
  42380. * @param {Array|Object} collection The collection to iterate over.
  42381. * @param {Function} [iteratee=_.identity]
  42382. * The iteratee to transform keys.
  42383. * @returns {Object} Returns the composed aggregate object.
  42384. * @example
  42385. *
  42386. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  42387. * // => { '4': [4.2], '6': [6.1, 6.3] }
  42388. *
  42389. * // The `_.property` iteratee shorthand.
  42390. * _.groupBy(['one', 'two', 'three'], 'length');
  42391. * // => { '3': ['one', 'two'], '5': ['three'] }
  42392. */
  42393. var groupBy = createAggregator(function (result, value, key) {
  42394. if (hasOwnProperty.call(result, key)) {
  42395. result[key].push(value);
  42396. } else {
  42397. result[key] = [value];
  42398. }
  42399. });
  42400. /**
  42401. * Creates a function that memoizes the result of `func`. If `resolver` is
  42402. * provided, it determines the cache key for storing the result based on the
  42403. * arguments provided to the memoized function. By default, the first argument
  42404. * provided to the memoized function is used as the map cache key. The `func`
  42405. * is invoked with the `this` binding of the memoized function.
  42406. *
  42407. * **Note:** The cache is exposed as the `cache` property on the memoized
  42408. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  42409. * constructor with one whose instances implement the
  42410. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  42411. * method interface of `delete`, `get`, `has`, and `set`.
  42412. *
  42413. * @static
  42414. * @memberOf _
  42415. * @since 0.1.0
  42416. * @category Function
  42417. * @param {Function} func The function to have its output memoized.
  42418. * @param {Function} [resolver] The function to resolve the cache key.
  42419. * @returns {Function} Returns the new memoized function.
  42420. * @example
  42421. *
  42422. * var object = { 'a': 1, 'b': 2 };
  42423. * var other = { 'c': 3, 'd': 4 };
  42424. *
  42425. * var values = _.memoize(_.values);
  42426. * values(object);
  42427. * // => [1, 2]
  42428. *
  42429. * values(other);
  42430. * // => [3, 4]
  42431. *
  42432. * object.a = 2;
  42433. * values(object);
  42434. * // => [1, 2]
  42435. *
  42436. * // Modify the result cache.
  42437. * values.cache.set(object, ['a', 'b']);
  42438. * values(object);
  42439. * // => ['a', 'b']
  42440. *
  42441. * // Replace `_.memoize.Cache`.
  42442. * _.memoize.Cache = WeakMap;
  42443. */
  42444. function memoize(func, resolver) {
  42445. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  42446. throw new TypeError(FUNC_ERROR_TEXT);
  42447. }
  42448. var memoized = function () {
  42449. var args = arguments,
  42450. key = resolver ? resolver.apply(this, args) : args[0],
  42451. cache = memoized.cache;
  42452. if (cache.has(key)) {
  42453. return cache.get(key);
  42454. }
  42455. var result = func.apply(this, args);
  42456. memoized.cache = cache.set(key, result);
  42457. return result;
  42458. };
  42459. memoized.cache = new (memoize.Cache || MapCache)();
  42460. return memoized;
  42461. }
  42462. // Assign cache to `_.memoize`.
  42463. memoize.Cache = MapCache;
  42464. /**
  42465. * Performs a
  42466. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  42467. * comparison between two values to determine if they are equivalent.
  42468. *
  42469. * @static
  42470. * @memberOf _
  42471. * @since 4.0.0
  42472. * @category Lang
  42473. * @param {*} value The value to compare.
  42474. * @param {*} other The other value to compare.
  42475. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  42476. * @example
  42477. *
  42478. * var object = { 'a': 1 };
  42479. * var other = { 'a': 1 };
  42480. *
  42481. * _.eq(object, object);
  42482. * // => true
  42483. *
  42484. * _.eq(object, other);
  42485. * // => false
  42486. *
  42487. * _.eq('a', 'a');
  42488. * // => true
  42489. *
  42490. * _.eq('a', Object('a'));
  42491. * // => false
  42492. *
  42493. * _.eq(NaN, NaN);
  42494. * // => true
  42495. */
  42496. function eq(value, other) {
  42497. return value === other || value !== value && other !== other;
  42498. }
  42499. /**
  42500. * Checks if `value` is likely an `arguments` object.
  42501. *
  42502. * @static
  42503. * @memberOf _
  42504. * @since 0.1.0
  42505. * @category Lang
  42506. * @param {*} value The value to check.
  42507. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  42508. * else `false`.
  42509. * @example
  42510. *
  42511. * _.isArguments(function() { return arguments; }());
  42512. * // => true
  42513. *
  42514. * _.isArguments([1, 2, 3]);
  42515. * // => false
  42516. */
  42517. function isArguments(value) {
  42518. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  42519. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  42520. }
  42521. /**
  42522. * Checks if `value` is classified as an `Array` object.
  42523. *
  42524. * @static
  42525. * @memberOf _
  42526. * @since 0.1.0
  42527. * @category Lang
  42528. * @param {*} value The value to check.
  42529. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  42530. * @example
  42531. *
  42532. * _.isArray([1, 2, 3]);
  42533. * // => true
  42534. *
  42535. * _.isArray(document.body.children);
  42536. * // => false
  42537. *
  42538. * _.isArray('abc');
  42539. * // => false
  42540. *
  42541. * _.isArray(_.noop);
  42542. * // => false
  42543. */
  42544. var isArray = Array.isArray;
  42545. /**
  42546. * Checks if `value` is array-like. A value is considered array-like if it's
  42547. * not a function and has a `value.length` that's an integer greater than or
  42548. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  42549. *
  42550. * @static
  42551. * @memberOf _
  42552. * @since 4.0.0
  42553. * @category Lang
  42554. * @param {*} value The value to check.
  42555. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  42556. * @example
  42557. *
  42558. * _.isArrayLike([1, 2, 3]);
  42559. * // => true
  42560. *
  42561. * _.isArrayLike(document.body.children);
  42562. * // => true
  42563. *
  42564. * _.isArrayLike('abc');
  42565. * // => true
  42566. *
  42567. * _.isArrayLike(_.noop);
  42568. * // => false
  42569. */
  42570. function isArrayLike(value) {
  42571. return value != null && isLength(value.length) && !isFunction(value);
  42572. }
  42573. /**
  42574. * This method is like `_.isArrayLike` except that it also checks if `value`
  42575. * is an object.
  42576. *
  42577. * @static
  42578. * @memberOf _
  42579. * @since 4.0.0
  42580. * @category Lang
  42581. * @param {*} value The value to check.
  42582. * @returns {boolean} Returns `true` if `value` is an array-like object,
  42583. * else `false`.
  42584. * @example
  42585. *
  42586. * _.isArrayLikeObject([1, 2, 3]);
  42587. * // => true
  42588. *
  42589. * _.isArrayLikeObject(document.body.children);
  42590. * // => true
  42591. *
  42592. * _.isArrayLikeObject('abc');
  42593. * // => false
  42594. *
  42595. * _.isArrayLikeObject(_.noop);
  42596. * // => false
  42597. */
  42598. function isArrayLikeObject(value) {
  42599. return isObjectLike(value) && isArrayLike(value);
  42600. }
  42601. /**
  42602. * Checks if `value` is classified as a `Function` object.
  42603. *
  42604. * @static
  42605. * @memberOf _
  42606. * @since 0.1.0
  42607. * @category Lang
  42608. * @param {*} value The value to check.
  42609. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  42610. * @example
  42611. *
  42612. * _.isFunction(_);
  42613. * // => true
  42614. *
  42615. * _.isFunction(/abc/);
  42616. * // => false
  42617. */
  42618. function isFunction(value) {
  42619. // The use of `Object#toString` avoids issues with the `typeof` operator
  42620. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  42621. var tag = isObject(value) ? objectToString.call(value) : '';
  42622. return tag == funcTag || tag == genTag;
  42623. }
  42624. /**
  42625. * Checks if `value` is a valid array-like length.
  42626. *
  42627. * **Note:** This method is loosely based on
  42628. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  42629. *
  42630. * @static
  42631. * @memberOf _
  42632. * @since 4.0.0
  42633. * @category Lang
  42634. * @param {*} value The value to check.
  42635. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  42636. * @example
  42637. *
  42638. * _.isLength(3);
  42639. * // => true
  42640. *
  42641. * _.isLength(Number.MIN_VALUE);
  42642. * // => false
  42643. *
  42644. * _.isLength(Infinity);
  42645. * // => false
  42646. *
  42647. * _.isLength('3');
  42648. * // => false
  42649. */
  42650. function isLength(value) {
  42651. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  42652. }
  42653. /**
  42654. * Checks if `value` is the
  42655. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  42656. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  42657. *
  42658. * @static
  42659. * @memberOf _
  42660. * @since 0.1.0
  42661. * @category Lang
  42662. * @param {*} value The value to check.
  42663. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  42664. * @example
  42665. *
  42666. * _.isObject({});
  42667. * // => true
  42668. *
  42669. * _.isObject([1, 2, 3]);
  42670. * // => true
  42671. *
  42672. * _.isObject(_.noop);
  42673. * // => true
  42674. *
  42675. * _.isObject(null);
  42676. * // => false
  42677. */
  42678. function isObject(value) {
  42679. var type = typeof value;
  42680. return !!value && (type == 'object' || type == 'function');
  42681. }
  42682. /**
  42683. * Checks if `value` is object-like. A value is object-like if it's not `null`
  42684. * and has a `typeof` result of "object".
  42685. *
  42686. * @static
  42687. * @memberOf _
  42688. * @since 4.0.0
  42689. * @category Lang
  42690. * @param {*} value The value to check.
  42691. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  42692. * @example
  42693. *
  42694. * _.isObjectLike({});
  42695. * // => true
  42696. *
  42697. * _.isObjectLike([1, 2, 3]);
  42698. * // => true
  42699. *
  42700. * _.isObjectLike(_.noop);
  42701. * // => false
  42702. *
  42703. * _.isObjectLike(null);
  42704. * // => false
  42705. */
  42706. function isObjectLike(value) {
  42707. return !!value && typeof value == 'object';
  42708. }
  42709. /**
  42710. * Checks if `value` is classified as a `Symbol` primitive or object.
  42711. *
  42712. * @static
  42713. * @memberOf _
  42714. * @since 4.0.0
  42715. * @category Lang
  42716. * @param {*} value The value to check.
  42717. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  42718. * @example
  42719. *
  42720. * _.isSymbol(Symbol.iterator);
  42721. * // => true
  42722. *
  42723. * _.isSymbol('abc');
  42724. * // => false
  42725. */
  42726. function isSymbol(value) {
  42727. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  42728. }
  42729. /**
  42730. * Checks if `value` is classified as a typed array.
  42731. *
  42732. * @static
  42733. * @memberOf _
  42734. * @since 3.0.0
  42735. * @category Lang
  42736. * @param {*} value The value to check.
  42737. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  42738. * @example
  42739. *
  42740. * _.isTypedArray(new Uint8Array);
  42741. * // => true
  42742. *
  42743. * _.isTypedArray([]);
  42744. * // => false
  42745. */
  42746. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  42747. /**
  42748. * Converts `value` to a string. An empty string is returned for `null`
  42749. * and `undefined` values. The sign of `-0` is preserved.
  42750. *
  42751. * @static
  42752. * @memberOf _
  42753. * @since 4.0.0
  42754. * @category Lang
  42755. * @param {*} value The value to process.
  42756. * @returns {string} Returns the string.
  42757. * @example
  42758. *
  42759. * _.toString(null);
  42760. * // => ''
  42761. *
  42762. * _.toString(-0);
  42763. * // => '-0'
  42764. *
  42765. * _.toString([1, 2, 3]);
  42766. * // => '1,2,3'
  42767. */
  42768. function toString(value) {
  42769. return value == null ? '' : baseToString(value);
  42770. }
  42771. /**
  42772. * Gets the value at `path` of `object`. If the resolved value is
  42773. * `undefined`, the `defaultValue` is returned in its place.
  42774. *
  42775. * @static
  42776. * @memberOf _
  42777. * @since 3.7.0
  42778. * @category Object
  42779. * @param {Object} object The object to query.
  42780. * @param {Array|string} path The path of the property to get.
  42781. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  42782. * @returns {*} Returns the resolved value.
  42783. * @example
  42784. *
  42785. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  42786. *
  42787. * _.get(object, 'a[0].b.c');
  42788. * // => 3
  42789. *
  42790. * _.get(object, ['a', '0', 'b', 'c']);
  42791. * // => 3
  42792. *
  42793. * _.get(object, 'a.b.c', 'default');
  42794. * // => 'default'
  42795. */
  42796. function get(object, path, defaultValue) {
  42797. var result = object == null ? undefined : baseGet(object, path);
  42798. return result === undefined ? defaultValue : result;
  42799. }
  42800. /**
  42801. * Checks if `path` is a direct or inherited property of `object`.
  42802. *
  42803. * @static
  42804. * @memberOf _
  42805. * @since 4.0.0
  42806. * @category Object
  42807. * @param {Object} object The object to query.
  42808. * @param {Array|string} path The path to check.
  42809. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  42810. * @example
  42811. *
  42812. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  42813. *
  42814. * _.hasIn(object, 'a');
  42815. * // => true
  42816. *
  42817. * _.hasIn(object, 'a.b');
  42818. * // => true
  42819. *
  42820. * _.hasIn(object, ['a', 'b']);
  42821. * // => true
  42822. *
  42823. * _.hasIn(object, 'b');
  42824. * // => false
  42825. */
  42826. function hasIn(object, path) {
  42827. return object != null && hasPath(object, path, baseHasIn);
  42828. }
  42829. /**
  42830. * Creates an array of the own enumerable property names of `object`.
  42831. *
  42832. * **Note:** Non-object values are coerced to objects. See the
  42833. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  42834. * for more details.
  42835. *
  42836. * @static
  42837. * @since 0.1.0
  42838. * @memberOf _
  42839. * @category Object
  42840. * @param {Object} object The object to query.
  42841. * @returns {Array} Returns the array of property names.
  42842. * @example
  42843. *
  42844. * function Foo() {
  42845. * this.a = 1;
  42846. * this.b = 2;
  42847. * }
  42848. *
  42849. * Foo.prototype.c = 3;
  42850. *
  42851. * _.keys(new Foo);
  42852. * // => ['a', 'b'] (iteration order is not guaranteed)
  42853. *
  42854. * _.keys('hi');
  42855. * // => ['0', '1']
  42856. */
  42857. function keys(object) {
  42858. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  42859. }
  42860. /**
  42861. * This method returns the first argument it receives.
  42862. *
  42863. * @static
  42864. * @since 0.1.0
  42865. * @memberOf _
  42866. * @category Util
  42867. * @param {*} value Any value.
  42868. * @returns {*} Returns `value`.
  42869. * @example
  42870. *
  42871. * var object = { 'a': 1 };
  42872. *
  42873. * console.log(_.identity(object) === object);
  42874. * // => true
  42875. */
  42876. function identity(value) {
  42877. return value;
  42878. }
  42879. /**
  42880. * Creates a function that returns the value at `path` of a given object.
  42881. *
  42882. * @static
  42883. * @memberOf _
  42884. * @since 2.4.0
  42885. * @category Util
  42886. * @param {Array|string} path The path of the property to get.
  42887. * @returns {Function} Returns the new accessor function.
  42888. * @example
  42889. *
  42890. * var objects = [
  42891. * { 'a': { 'b': 2 } },
  42892. * { 'a': { 'b': 1 } }
  42893. * ];
  42894. *
  42895. * _.map(objects, _.property('a.b'));
  42896. * // => [2, 1]
  42897. *
  42898. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  42899. * // => [1, 2]
  42900. */
  42901. function property(path) {
  42902. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  42903. }
  42904. module.exports = groupBy;
  42905. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  42906. },{}],444:[function(require,module,exports){
  42907. "use strict";
  42908. /**
  42909. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  42910. * Build: `lodash modularize exports="npm" -o ./`
  42911. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  42912. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  42913. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  42914. * Available under MIT license <https://lodash.com/license>
  42915. */
  42916. /** `Object#toString` result references. */
  42917. var boolTag = '[object Boolean]';
  42918. /** Used for built-in method references. */
  42919. var objectProto = Object.prototype;
  42920. /**
  42921. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  42922. * of values.
  42923. */
  42924. var objectToString = objectProto.toString;
  42925. /**
  42926. * Checks if `value` is classified as a boolean primitive or object.
  42927. *
  42928. * @static
  42929. * @memberOf _
  42930. * @category Lang
  42931. * @param {*} value The value to check.
  42932. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  42933. * @example
  42934. *
  42935. * _.isBoolean(false);
  42936. * // => true
  42937. *
  42938. * _.isBoolean(null);
  42939. * // => false
  42940. */
  42941. function isBoolean(value) {
  42942. return value === true || value === false || isObjectLike(value) && objectToString.call(value) == boolTag;
  42943. }
  42944. /**
  42945. * Checks if `value` is object-like. A value is object-like if it's not `null`
  42946. * and has a `typeof` result of "object".
  42947. *
  42948. * @static
  42949. * @memberOf _
  42950. * @category Lang
  42951. * @param {*} value The value to check.
  42952. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  42953. * @example
  42954. *
  42955. * _.isObjectLike({});
  42956. * // => true
  42957. *
  42958. * _.isObjectLike([1, 2, 3]);
  42959. * // => true
  42960. *
  42961. * _.isObjectLike(_.noop);
  42962. * // => false
  42963. *
  42964. * _.isObjectLike(null);
  42965. * // => false
  42966. */
  42967. function isObjectLike(value) {
  42968. return !!value && typeof value == 'object';
  42969. }
  42970. module.exports = isBoolean;
  42971. },{}],445:[function(require,module,exports){
  42972. (function (global){(function (){
  42973. "use strict";
  42974. /**
  42975. * Lodash (Custom Build) <https://lodash.com/>
  42976. * Build: `lodash modularize exports="npm" -o ./`
  42977. * Copyright JS Foundation and other contributors <https://js.foundation/>
  42978. * Released under MIT license <https://lodash.com/license>
  42979. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  42980. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  42981. */
  42982. /** Used as the size to enable large array optimizations. */
  42983. var LARGE_ARRAY_SIZE = 200;
  42984. /** Used to stand-in for `undefined` hash values. */
  42985. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  42986. /** Used to compose bitmasks for value comparisons. */
  42987. var COMPARE_PARTIAL_FLAG = 1,
  42988. COMPARE_UNORDERED_FLAG = 2;
  42989. /** Used as references for various `Number` constants. */
  42990. var MAX_SAFE_INTEGER = 9007199254740991;
  42991. /** `Object#toString` result references. */
  42992. var argsTag = '[object Arguments]',
  42993. arrayTag = '[object Array]',
  42994. asyncTag = '[object AsyncFunction]',
  42995. boolTag = '[object Boolean]',
  42996. dateTag = '[object Date]',
  42997. errorTag = '[object Error]',
  42998. funcTag = '[object Function]',
  42999. genTag = '[object GeneratorFunction]',
  43000. mapTag = '[object Map]',
  43001. numberTag = '[object Number]',
  43002. nullTag = '[object Null]',
  43003. objectTag = '[object Object]',
  43004. promiseTag = '[object Promise]',
  43005. proxyTag = '[object Proxy]',
  43006. regexpTag = '[object RegExp]',
  43007. setTag = '[object Set]',
  43008. stringTag = '[object String]',
  43009. symbolTag = '[object Symbol]',
  43010. undefinedTag = '[object Undefined]',
  43011. weakMapTag = '[object WeakMap]';
  43012. var arrayBufferTag = '[object ArrayBuffer]',
  43013. dataViewTag = '[object DataView]',
  43014. float32Tag = '[object Float32Array]',
  43015. float64Tag = '[object Float64Array]',
  43016. int8Tag = '[object Int8Array]',
  43017. int16Tag = '[object Int16Array]',
  43018. int32Tag = '[object Int32Array]',
  43019. uint8Tag = '[object Uint8Array]',
  43020. uint8ClampedTag = '[object Uint8ClampedArray]',
  43021. uint16Tag = '[object Uint16Array]',
  43022. uint32Tag = '[object Uint32Array]';
  43023. /**
  43024. * Used to match `RegExp`
  43025. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  43026. */
  43027. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  43028. /** Used to detect host constructors (Safari). */
  43029. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  43030. /** Used to detect unsigned integer values. */
  43031. var reIsUint = /^(?:0|[1-9]\d*)$/;
  43032. /** Used to identify `toStringTag` values of typed arrays. */
  43033. var typedArrayTags = {};
  43034. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  43035. typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  43036. /** Detect free variable `global` from Node.js. */
  43037. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  43038. /** Detect free variable `self`. */
  43039. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  43040. /** Used as a reference to the global object. */
  43041. var root = freeGlobal || freeSelf || Function('return this')();
  43042. /** Detect free variable `exports`. */
  43043. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  43044. /** Detect free variable `module`. */
  43045. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  43046. /** Detect the popular CommonJS extension `module.exports`. */
  43047. var moduleExports = freeModule && freeModule.exports === freeExports;
  43048. /** Detect free variable `process` from Node.js. */
  43049. var freeProcess = moduleExports && freeGlobal.process;
  43050. /** Used to access faster Node.js helpers. */
  43051. var nodeUtil = function () {
  43052. try {
  43053. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  43054. } catch (e) {}
  43055. }();
  43056. /* Node.js helper references. */
  43057. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  43058. /**
  43059. * A specialized version of `_.filter` for arrays without support for
  43060. * iteratee shorthands.
  43061. *
  43062. * @private
  43063. * @param {Array} [array] The array to iterate over.
  43064. * @param {Function} predicate The function invoked per iteration.
  43065. * @returns {Array} Returns the new filtered array.
  43066. */
  43067. function arrayFilter(array, predicate) {
  43068. var index = -1,
  43069. length = array == null ? 0 : array.length,
  43070. resIndex = 0,
  43071. result = [];
  43072. while (++index < length) {
  43073. var value = array[index];
  43074. if (predicate(value, index, array)) {
  43075. result[resIndex++] = value;
  43076. }
  43077. }
  43078. return result;
  43079. }
  43080. /**
  43081. * Appends the elements of `values` to `array`.
  43082. *
  43083. * @private
  43084. * @param {Array} array The array to modify.
  43085. * @param {Array} values The values to append.
  43086. * @returns {Array} Returns `array`.
  43087. */
  43088. function arrayPush(array, values) {
  43089. var index = -1,
  43090. length = values.length,
  43091. offset = array.length;
  43092. while (++index < length) {
  43093. array[offset + index] = values[index];
  43094. }
  43095. return array;
  43096. }
  43097. /**
  43098. * A specialized version of `_.some` for arrays without support for iteratee
  43099. * shorthands.
  43100. *
  43101. * @private
  43102. * @param {Array} [array] The array to iterate over.
  43103. * @param {Function} predicate The function invoked per iteration.
  43104. * @returns {boolean} Returns `true` if any element passes the predicate check,
  43105. * else `false`.
  43106. */
  43107. function arraySome(array, predicate) {
  43108. var index = -1,
  43109. length = array == null ? 0 : array.length;
  43110. while (++index < length) {
  43111. if (predicate(array[index], index, array)) {
  43112. return true;
  43113. }
  43114. }
  43115. return false;
  43116. }
  43117. /**
  43118. * The base implementation of `_.times` without support for iteratee shorthands
  43119. * or max array length checks.
  43120. *
  43121. * @private
  43122. * @param {number} n The number of times to invoke `iteratee`.
  43123. * @param {Function} iteratee The function invoked per iteration.
  43124. * @returns {Array} Returns the array of results.
  43125. */
  43126. function baseTimes(n, iteratee) {
  43127. var index = -1,
  43128. result = Array(n);
  43129. while (++index < n) {
  43130. result[index] = iteratee(index);
  43131. }
  43132. return result;
  43133. }
  43134. /**
  43135. * The base implementation of `_.unary` without support for storing metadata.
  43136. *
  43137. * @private
  43138. * @param {Function} func The function to cap arguments for.
  43139. * @returns {Function} Returns the new capped function.
  43140. */
  43141. function baseUnary(func) {
  43142. return function (value) {
  43143. return func(value);
  43144. };
  43145. }
  43146. /**
  43147. * Checks if a `cache` value for `key` exists.
  43148. *
  43149. * @private
  43150. * @param {Object} cache The cache to query.
  43151. * @param {string} key The key of the entry to check.
  43152. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  43153. */
  43154. function cacheHas(cache, key) {
  43155. return cache.has(key);
  43156. }
  43157. /**
  43158. * Gets the value at `key` of `object`.
  43159. *
  43160. * @private
  43161. * @param {Object} [object] The object to query.
  43162. * @param {string} key The key of the property to get.
  43163. * @returns {*} Returns the property value.
  43164. */
  43165. function getValue(object, key) {
  43166. return object == null ? undefined : object[key];
  43167. }
  43168. /**
  43169. * Converts `map` to its key-value pairs.
  43170. *
  43171. * @private
  43172. * @param {Object} map The map to convert.
  43173. * @returns {Array} Returns the key-value pairs.
  43174. */
  43175. function mapToArray(map) {
  43176. var index = -1,
  43177. result = Array(map.size);
  43178. map.forEach(function (value, key) {
  43179. result[++index] = [key, value];
  43180. });
  43181. return result;
  43182. }
  43183. /**
  43184. * Creates a unary function that invokes `func` with its argument transformed.
  43185. *
  43186. * @private
  43187. * @param {Function} func The function to wrap.
  43188. * @param {Function} transform The argument transform.
  43189. * @returns {Function} Returns the new function.
  43190. */
  43191. function overArg(func, transform) {
  43192. return function (arg) {
  43193. return func(transform(arg));
  43194. };
  43195. }
  43196. /**
  43197. * Converts `set` to an array of its values.
  43198. *
  43199. * @private
  43200. * @param {Object} set The set to convert.
  43201. * @returns {Array} Returns the values.
  43202. */
  43203. function setToArray(set) {
  43204. var index = -1,
  43205. result = Array(set.size);
  43206. set.forEach(function (value) {
  43207. result[++index] = value;
  43208. });
  43209. return result;
  43210. }
  43211. /** Used for built-in method references. */
  43212. var arrayProto = Array.prototype,
  43213. funcProto = Function.prototype,
  43214. objectProto = Object.prototype;
  43215. /** Used to detect overreaching core-js shims. */
  43216. var coreJsData = root['__core-js_shared__'];
  43217. /** Used to resolve the decompiled source of functions. */
  43218. var funcToString = funcProto.toString;
  43219. /** Used to check objects for own properties. */
  43220. var hasOwnProperty = objectProto.hasOwnProperty;
  43221. /** Used to detect methods masquerading as native. */
  43222. var maskSrcKey = function () {
  43223. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  43224. return uid ? 'Symbol(src)_1.' + uid : '';
  43225. }();
  43226. /**
  43227. * Used to resolve the
  43228. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  43229. * of values.
  43230. */
  43231. var nativeObjectToString = objectProto.toString;
  43232. /** Used to detect if a method is native. */
  43233. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  43234. /** Built-in value references. */
  43235. var Buffer = moduleExports ? root.Buffer : undefined,
  43236. Symbol = root.Symbol,
  43237. Uint8Array = root.Uint8Array,
  43238. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  43239. splice = arrayProto.splice,
  43240. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  43241. /* Built-in method references for those with the same name as other `lodash` methods. */
  43242. var nativeGetSymbols = Object.getOwnPropertySymbols,
  43243. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  43244. nativeKeys = overArg(Object.keys, Object);
  43245. /* Built-in method references that are verified to be native. */
  43246. var DataView = getNative(root, 'DataView'),
  43247. Map = getNative(root, 'Map'),
  43248. Promise = getNative(root, 'Promise'),
  43249. Set = getNative(root, 'Set'),
  43250. WeakMap = getNative(root, 'WeakMap'),
  43251. nativeCreate = getNative(Object, 'create');
  43252. /** Used to detect maps, sets, and weakmaps. */
  43253. var dataViewCtorString = toSource(DataView),
  43254. mapCtorString = toSource(Map),
  43255. promiseCtorString = toSource(Promise),
  43256. setCtorString = toSource(Set),
  43257. weakMapCtorString = toSource(WeakMap);
  43258. /** Used to convert symbols to primitives and strings. */
  43259. var symbolProto = Symbol ? Symbol.prototype : undefined,
  43260. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  43261. /**
  43262. * Creates a hash object.
  43263. *
  43264. * @private
  43265. * @constructor
  43266. * @param {Array} [entries] The key-value pairs to cache.
  43267. */
  43268. function Hash(entries) {
  43269. var index = -1,
  43270. length = entries == null ? 0 : entries.length;
  43271. this.clear();
  43272. while (++index < length) {
  43273. var entry = entries[index];
  43274. this.set(entry[0], entry[1]);
  43275. }
  43276. }
  43277. /**
  43278. * Removes all key-value entries from the hash.
  43279. *
  43280. * @private
  43281. * @name clear
  43282. * @memberOf Hash
  43283. */
  43284. function hashClear() {
  43285. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  43286. this.size = 0;
  43287. }
  43288. /**
  43289. * Removes `key` and its value from the hash.
  43290. *
  43291. * @private
  43292. * @name delete
  43293. * @memberOf Hash
  43294. * @param {Object} hash The hash to modify.
  43295. * @param {string} key The key of the value to remove.
  43296. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  43297. */
  43298. function hashDelete(key) {
  43299. var result = this.has(key) && delete this.__data__[key];
  43300. this.size -= result ? 1 : 0;
  43301. return result;
  43302. }
  43303. /**
  43304. * Gets the hash value for `key`.
  43305. *
  43306. * @private
  43307. * @name get
  43308. * @memberOf Hash
  43309. * @param {string} key The key of the value to get.
  43310. * @returns {*} Returns the entry value.
  43311. */
  43312. function hashGet(key) {
  43313. var data = this.__data__;
  43314. if (nativeCreate) {
  43315. var result = data[key];
  43316. return result === HASH_UNDEFINED ? undefined : result;
  43317. }
  43318. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  43319. }
  43320. /**
  43321. * Checks if a hash value for `key` exists.
  43322. *
  43323. * @private
  43324. * @name has
  43325. * @memberOf Hash
  43326. * @param {string} key The key of the entry to check.
  43327. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  43328. */
  43329. function hashHas(key) {
  43330. var data = this.__data__;
  43331. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  43332. }
  43333. /**
  43334. * Sets the hash `key` to `value`.
  43335. *
  43336. * @private
  43337. * @name set
  43338. * @memberOf Hash
  43339. * @param {string} key The key of the value to set.
  43340. * @param {*} value The value to set.
  43341. * @returns {Object} Returns the hash instance.
  43342. */
  43343. function hashSet(key, value) {
  43344. var data = this.__data__;
  43345. this.size += this.has(key) ? 0 : 1;
  43346. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  43347. return this;
  43348. }
  43349. // Add methods to `Hash`.
  43350. Hash.prototype.clear = hashClear;
  43351. Hash.prototype['delete'] = hashDelete;
  43352. Hash.prototype.get = hashGet;
  43353. Hash.prototype.has = hashHas;
  43354. Hash.prototype.set = hashSet;
  43355. /**
  43356. * Creates an list cache object.
  43357. *
  43358. * @private
  43359. * @constructor
  43360. * @param {Array} [entries] The key-value pairs to cache.
  43361. */
  43362. function ListCache(entries) {
  43363. var index = -1,
  43364. length = entries == null ? 0 : entries.length;
  43365. this.clear();
  43366. while (++index < length) {
  43367. var entry = entries[index];
  43368. this.set(entry[0], entry[1]);
  43369. }
  43370. }
  43371. /**
  43372. * Removes all key-value entries from the list cache.
  43373. *
  43374. * @private
  43375. * @name clear
  43376. * @memberOf ListCache
  43377. */
  43378. function listCacheClear() {
  43379. this.__data__ = [];
  43380. this.size = 0;
  43381. }
  43382. /**
  43383. * Removes `key` and its value from the list cache.
  43384. *
  43385. * @private
  43386. * @name delete
  43387. * @memberOf ListCache
  43388. * @param {string} key The key of the value to remove.
  43389. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  43390. */
  43391. function listCacheDelete(key) {
  43392. var data = this.__data__,
  43393. index = assocIndexOf(data, key);
  43394. if (index < 0) {
  43395. return false;
  43396. }
  43397. var lastIndex = data.length - 1;
  43398. if (index == lastIndex) {
  43399. data.pop();
  43400. } else {
  43401. splice.call(data, index, 1);
  43402. }
  43403. --this.size;
  43404. return true;
  43405. }
  43406. /**
  43407. * Gets the list cache value for `key`.
  43408. *
  43409. * @private
  43410. * @name get
  43411. * @memberOf ListCache
  43412. * @param {string} key The key of the value to get.
  43413. * @returns {*} Returns the entry value.
  43414. */
  43415. function listCacheGet(key) {
  43416. var data = this.__data__,
  43417. index = assocIndexOf(data, key);
  43418. return index < 0 ? undefined : data[index][1];
  43419. }
  43420. /**
  43421. * Checks if a list cache value for `key` exists.
  43422. *
  43423. * @private
  43424. * @name has
  43425. * @memberOf ListCache
  43426. * @param {string} key The key of the entry to check.
  43427. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  43428. */
  43429. function listCacheHas(key) {
  43430. return assocIndexOf(this.__data__, key) > -1;
  43431. }
  43432. /**
  43433. * Sets the list cache `key` to `value`.
  43434. *
  43435. * @private
  43436. * @name set
  43437. * @memberOf ListCache
  43438. * @param {string} key The key of the value to set.
  43439. * @param {*} value The value to set.
  43440. * @returns {Object} Returns the list cache instance.
  43441. */
  43442. function listCacheSet(key, value) {
  43443. var data = this.__data__,
  43444. index = assocIndexOf(data, key);
  43445. if (index < 0) {
  43446. ++this.size;
  43447. data.push([key, value]);
  43448. } else {
  43449. data[index][1] = value;
  43450. }
  43451. return this;
  43452. }
  43453. // Add methods to `ListCache`.
  43454. ListCache.prototype.clear = listCacheClear;
  43455. ListCache.prototype['delete'] = listCacheDelete;
  43456. ListCache.prototype.get = listCacheGet;
  43457. ListCache.prototype.has = listCacheHas;
  43458. ListCache.prototype.set = listCacheSet;
  43459. /**
  43460. * Creates a map cache object to store key-value pairs.
  43461. *
  43462. * @private
  43463. * @constructor
  43464. * @param {Array} [entries] The key-value pairs to cache.
  43465. */
  43466. function MapCache(entries) {
  43467. var index = -1,
  43468. length = entries == null ? 0 : entries.length;
  43469. this.clear();
  43470. while (++index < length) {
  43471. var entry = entries[index];
  43472. this.set(entry[0], entry[1]);
  43473. }
  43474. }
  43475. /**
  43476. * Removes all key-value entries from the map.
  43477. *
  43478. * @private
  43479. * @name clear
  43480. * @memberOf MapCache
  43481. */
  43482. function mapCacheClear() {
  43483. this.size = 0;
  43484. this.__data__ = {
  43485. 'hash': new Hash(),
  43486. 'map': new (Map || ListCache)(),
  43487. 'string': new Hash()
  43488. };
  43489. }
  43490. /**
  43491. * Removes `key` and its value from the map.
  43492. *
  43493. * @private
  43494. * @name delete
  43495. * @memberOf MapCache
  43496. * @param {string} key The key of the value to remove.
  43497. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  43498. */
  43499. function mapCacheDelete(key) {
  43500. var result = getMapData(this, key)['delete'](key);
  43501. this.size -= result ? 1 : 0;
  43502. return result;
  43503. }
  43504. /**
  43505. * Gets the map value for `key`.
  43506. *
  43507. * @private
  43508. * @name get
  43509. * @memberOf MapCache
  43510. * @param {string} key The key of the value to get.
  43511. * @returns {*} Returns the entry value.
  43512. */
  43513. function mapCacheGet(key) {
  43514. return getMapData(this, key).get(key);
  43515. }
  43516. /**
  43517. * Checks if a map value for `key` exists.
  43518. *
  43519. * @private
  43520. * @name has
  43521. * @memberOf MapCache
  43522. * @param {string} key The key of the entry to check.
  43523. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  43524. */
  43525. function mapCacheHas(key) {
  43526. return getMapData(this, key).has(key);
  43527. }
  43528. /**
  43529. * Sets the map `key` to `value`.
  43530. *
  43531. * @private
  43532. * @name set
  43533. * @memberOf MapCache
  43534. * @param {string} key The key of the value to set.
  43535. * @param {*} value The value to set.
  43536. * @returns {Object} Returns the map cache instance.
  43537. */
  43538. function mapCacheSet(key, value) {
  43539. var data = getMapData(this, key),
  43540. size = data.size;
  43541. data.set(key, value);
  43542. this.size += data.size == size ? 0 : 1;
  43543. return this;
  43544. }
  43545. // Add methods to `MapCache`.
  43546. MapCache.prototype.clear = mapCacheClear;
  43547. MapCache.prototype['delete'] = mapCacheDelete;
  43548. MapCache.prototype.get = mapCacheGet;
  43549. MapCache.prototype.has = mapCacheHas;
  43550. MapCache.prototype.set = mapCacheSet;
  43551. /**
  43552. *
  43553. * Creates an array cache object to store unique values.
  43554. *
  43555. * @private
  43556. * @constructor
  43557. * @param {Array} [values] The values to cache.
  43558. */
  43559. function SetCache(values) {
  43560. var index = -1,
  43561. length = values == null ? 0 : values.length;
  43562. this.__data__ = new MapCache();
  43563. while (++index < length) {
  43564. this.add(values[index]);
  43565. }
  43566. }
  43567. /**
  43568. * Adds `value` to the array cache.
  43569. *
  43570. * @private
  43571. * @name add
  43572. * @memberOf SetCache
  43573. * @alias push
  43574. * @param {*} value The value to cache.
  43575. * @returns {Object} Returns the cache instance.
  43576. */
  43577. function setCacheAdd(value) {
  43578. this.__data__.set(value, HASH_UNDEFINED);
  43579. return this;
  43580. }
  43581. /**
  43582. * Checks if `value` is in the array cache.
  43583. *
  43584. * @private
  43585. * @name has
  43586. * @memberOf SetCache
  43587. * @param {*} value The value to search for.
  43588. * @returns {number} Returns `true` if `value` is found, else `false`.
  43589. */
  43590. function setCacheHas(value) {
  43591. return this.__data__.has(value);
  43592. }
  43593. // Add methods to `SetCache`.
  43594. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  43595. SetCache.prototype.has = setCacheHas;
  43596. /**
  43597. * Creates a stack cache object to store key-value pairs.
  43598. *
  43599. * @private
  43600. * @constructor
  43601. * @param {Array} [entries] The key-value pairs to cache.
  43602. */
  43603. function Stack(entries) {
  43604. var data = this.__data__ = new ListCache(entries);
  43605. this.size = data.size;
  43606. }
  43607. /**
  43608. * Removes all key-value entries from the stack.
  43609. *
  43610. * @private
  43611. * @name clear
  43612. * @memberOf Stack
  43613. */
  43614. function stackClear() {
  43615. this.__data__ = new ListCache();
  43616. this.size = 0;
  43617. }
  43618. /**
  43619. * Removes `key` and its value from the stack.
  43620. *
  43621. * @private
  43622. * @name delete
  43623. * @memberOf Stack
  43624. * @param {string} key The key of the value to remove.
  43625. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  43626. */
  43627. function stackDelete(key) {
  43628. var data = this.__data__,
  43629. result = data['delete'](key);
  43630. this.size = data.size;
  43631. return result;
  43632. }
  43633. /**
  43634. * Gets the stack value for `key`.
  43635. *
  43636. * @private
  43637. * @name get
  43638. * @memberOf Stack
  43639. * @param {string} key The key of the value to get.
  43640. * @returns {*} Returns the entry value.
  43641. */
  43642. function stackGet(key) {
  43643. return this.__data__.get(key);
  43644. }
  43645. /**
  43646. * Checks if a stack value for `key` exists.
  43647. *
  43648. * @private
  43649. * @name has
  43650. * @memberOf Stack
  43651. * @param {string} key The key of the entry to check.
  43652. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  43653. */
  43654. function stackHas(key) {
  43655. return this.__data__.has(key);
  43656. }
  43657. /**
  43658. * Sets the stack `key` to `value`.
  43659. *
  43660. * @private
  43661. * @name set
  43662. * @memberOf Stack
  43663. * @param {string} key The key of the value to set.
  43664. * @param {*} value The value to set.
  43665. * @returns {Object} Returns the stack cache instance.
  43666. */
  43667. function stackSet(key, value) {
  43668. var data = this.__data__;
  43669. if (data instanceof ListCache) {
  43670. var pairs = data.__data__;
  43671. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  43672. pairs.push([key, value]);
  43673. this.size = ++data.size;
  43674. return this;
  43675. }
  43676. data = this.__data__ = new MapCache(pairs);
  43677. }
  43678. data.set(key, value);
  43679. this.size = data.size;
  43680. return this;
  43681. }
  43682. // Add methods to `Stack`.
  43683. Stack.prototype.clear = stackClear;
  43684. Stack.prototype['delete'] = stackDelete;
  43685. Stack.prototype.get = stackGet;
  43686. Stack.prototype.has = stackHas;
  43687. Stack.prototype.set = stackSet;
  43688. /**
  43689. * Creates an array of the enumerable property names of the array-like `value`.
  43690. *
  43691. * @private
  43692. * @param {*} value The value to query.
  43693. * @param {boolean} inherited Specify returning inherited property names.
  43694. * @returns {Array} Returns the array of property names.
  43695. */
  43696. function arrayLikeKeys(value, inherited) {
  43697. var isArr = isArray(value),
  43698. isArg = !isArr && isArguments(value),
  43699. isBuff = !isArr && !isArg && isBuffer(value),
  43700. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  43701. skipIndexes = isArr || isArg || isBuff || isType,
  43702. result = skipIndexes ? baseTimes(value.length, String) : [],
  43703. length = result.length;
  43704. for (var key in value) {
  43705. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (
  43706. // Safari 9 has enumerable `arguments.length` in strict mode.
  43707. key == 'length' ||
  43708. // Node.js 0.10 has enumerable non-index properties on buffers.
  43709. isBuff && (key == 'offset' || key == 'parent') ||
  43710. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  43711. isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') ||
  43712. // Skip index properties.
  43713. isIndex(key, length)))) {
  43714. result.push(key);
  43715. }
  43716. }
  43717. return result;
  43718. }
  43719. /**
  43720. * Gets the index at which the `key` is found in `array` of key-value pairs.
  43721. *
  43722. * @private
  43723. * @param {Array} array The array to inspect.
  43724. * @param {*} key The key to search for.
  43725. * @returns {number} Returns the index of the matched value, else `-1`.
  43726. */
  43727. function assocIndexOf(array, key) {
  43728. var length = array.length;
  43729. while (length--) {
  43730. if (eq(array[length][0], key)) {
  43731. return length;
  43732. }
  43733. }
  43734. return -1;
  43735. }
  43736. /**
  43737. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  43738. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  43739. * symbols of `object`.
  43740. *
  43741. * @private
  43742. * @param {Object} object The object to query.
  43743. * @param {Function} keysFunc The function to get the keys of `object`.
  43744. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  43745. * @returns {Array} Returns the array of property names and symbols.
  43746. */
  43747. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  43748. var result = keysFunc(object);
  43749. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  43750. }
  43751. /**
  43752. * The base implementation of `getTag` without fallbacks for buggy environments.
  43753. *
  43754. * @private
  43755. * @param {*} value The value to query.
  43756. * @returns {string} Returns the `toStringTag`.
  43757. */
  43758. function baseGetTag(value) {
  43759. if (value == null) {
  43760. return value === undefined ? undefinedTag : nullTag;
  43761. }
  43762. return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
  43763. }
  43764. /**
  43765. * The base implementation of `_.isArguments`.
  43766. *
  43767. * @private
  43768. * @param {*} value The value to check.
  43769. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  43770. */
  43771. function baseIsArguments(value) {
  43772. return isObjectLike(value) && baseGetTag(value) == argsTag;
  43773. }
  43774. /**
  43775. * The base implementation of `_.isEqual` which supports partial comparisons
  43776. * and tracks traversed objects.
  43777. *
  43778. * @private
  43779. * @param {*} value The value to compare.
  43780. * @param {*} other The other value to compare.
  43781. * @param {boolean} bitmask The bitmask flags.
  43782. * 1 - Unordered comparison
  43783. * 2 - Partial comparison
  43784. * @param {Function} [customizer] The function to customize comparisons.
  43785. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  43786. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  43787. */
  43788. function baseIsEqual(value, other, bitmask, customizer, stack) {
  43789. if (value === other) {
  43790. return true;
  43791. }
  43792. if (value == null || other == null || !isObjectLike(value) && !isObjectLike(other)) {
  43793. return value !== value && other !== other;
  43794. }
  43795. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  43796. }
  43797. /**
  43798. * A specialized version of `baseIsEqual` for arrays and objects which performs
  43799. * deep comparisons and tracks traversed objects enabling objects with circular
  43800. * references to be compared.
  43801. *
  43802. * @private
  43803. * @param {Object} object The object to compare.
  43804. * @param {Object} other The other object to compare.
  43805. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  43806. * @param {Function} customizer The function to customize comparisons.
  43807. * @param {Function} equalFunc The function to determine equivalents of values.
  43808. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  43809. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  43810. */
  43811. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  43812. var objIsArr = isArray(object),
  43813. othIsArr = isArray(other),
  43814. objTag = objIsArr ? arrayTag : getTag(object),
  43815. othTag = othIsArr ? arrayTag : getTag(other);
  43816. objTag = objTag == argsTag ? objectTag : objTag;
  43817. othTag = othTag == argsTag ? objectTag : othTag;
  43818. var objIsObj = objTag == objectTag,
  43819. othIsObj = othTag == objectTag,
  43820. isSameTag = objTag == othTag;
  43821. if (isSameTag && isBuffer(object)) {
  43822. if (!isBuffer(other)) {
  43823. return false;
  43824. }
  43825. objIsArr = true;
  43826. objIsObj = false;
  43827. }
  43828. if (isSameTag && !objIsObj) {
  43829. stack || (stack = new Stack());
  43830. return objIsArr || isTypedArray(object) ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  43831. }
  43832. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  43833. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  43834. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  43835. if (objIsWrapped || othIsWrapped) {
  43836. var objUnwrapped = objIsWrapped ? object.value() : object,
  43837. othUnwrapped = othIsWrapped ? other.value() : other;
  43838. stack || (stack = new Stack());
  43839. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  43840. }
  43841. }
  43842. if (!isSameTag) {
  43843. return false;
  43844. }
  43845. stack || (stack = new Stack());
  43846. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  43847. }
  43848. /**
  43849. * The base implementation of `_.isNative` without bad shim checks.
  43850. *
  43851. * @private
  43852. * @param {*} value The value to check.
  43853. * @returns {boolean} Returns `true` if `value` is a native function,
  43854. * else `false`.
  43855. */
  43856. function baseIsNative(value) {
  43857. if (!isObject(value) || isMasked(value)) {
  43858. return false;
  43859. }
  43860. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  43861. return pattern.test(toSource(value));
  43862. }
  43863. /**
  43864. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  43865. *
  43866. * @private
  43867. * @param {*} value The value to check.
  43868. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  43869. */
  43870. function baseIsTypedArray(value) {
  43871. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  43872. }
  43873. /**
  43874. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  43875. *
  43876. * @private
  43877. * @param {Object} object The object to query.
  43878. * @returns {Array} Returns the array of property names.
  43879. */
  43880. function baseKeys(object) {
  43881. if (!isPrototype(object)) {
  43882. return nativeKeys(object);
  43883. }
  43884. var result = [];
  43885. for (var key in Object(object)) {
  43886. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  43887. result.push(key);
  43888. }
  43889. }
  43890. return result;
  43891. }
  43892. /**
  43893. * A specialized version of `baseIsEqualDeep` for arrays with support for
  43894. * partial deep comparisons.
  43895. *
  43896. * @private
  43897. * @param {Array} array The array to compare.
  43898. * @param {Array} other The other array to compare.
  43899. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  43900. * @param {Function} customizer The function to customize comparisons.
  43901. * @param {Function} equalFunc The function to determine equivalents of values.
  43902. * @param {Object} stack Tracks traversed `array` and `other` objects.
  43903. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  43904. */
  43905. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  43906. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  43907. arrLength = array.length,
  43908. othLength = other.length;
  43909. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  43910. return false;
  43911. }
  43912. // Assume cyclic values are equal.
  43913. var stacked = stack.get(array);
  43914. if (stacked && stack.get(other)) {
  43915. return stacked == other;
  43916. }
  43917. var index = -1,
  43918. result = true,
  43919. seen = bitmask & COMPARE_UNORDERED_FLAG ? new SetCache() : undefined;
  43920. stack.set(array, other);
  43921. stack.set(other, array);
  43922. // Ignore non-index properties.
  43923. while (++index < arrLength) {
  43924. var arrValue = array[index],
  43925. othValue = other[index];
  43926. if (customizer) {
  43927. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  43928. }
  43929. if (compared !== undefined) {
  43930. if (compared) {
  43931. continue;
  43932. }
  43933. result = false;
  43934. break;
  43935. }
  43936. // Recursively compare arrays (susceptible to call stack limits).
  43937. if (seen) {
  43938. if (!arraySome(other, function (othValue, othIndex) {
  43939. if (!cacheHas(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  43940. return seen.push(othIndex);
  43941. }
  43942. })) {
  43943. result = false;
  43944. break;
  43945. }
  43946. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  43947. result = false;
  43948. break;
  43949. }
  43950. }
  43951. stack['delete'](array);
  43952. stack['delete'](other);
  43953. return result;
  43954. }
  43955. /**
  43956. * A specialized version of `baseIsEqualDeep` for comparing objects of
  43957. * the same `toStringTag`.
  43958. *
  43959. * **Note:** This function only supports comparing values with tags of
  43960. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  43961. *
  43962. * @private
  43963. * @param {Object} object The object to compare.
  43964. * @param {Object} other The other object to compare.
  43965. * @param {string} tag The `toStringTag` of the objects to compare.
  43966. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  43967. * @param {Function} customizer The function to customize comparisons.
  43968. * @param {Function} equalFunc The function to determine equivalents of values.
  43969. * @param {Object} stack Tracks traversed `object` and `other` objects.
  43970. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  43971. */
  43972. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  43973. switch (tag) {
  43974. case dataViewTag:
  43975. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  43976. return false;
  43977. }
  43978. object = object.buffer;
  43979. other = other.buffer;
  43980. case arrayBufferTag:
  43981. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  43982. return false;
  43983. }
  43984. return true;
  43985. case boolTag:
  43986. case dateTag:
  43987. case numberTag:
  43988. // Coerce booleans to `1` or `0` and dates to milliseconds.
  43989. // Invalid dates are coerced to `NaN`.
  43990. return eq(+object, +other);
  43991. case errorTag:
  43992. return object.name == other.name && object.message == other.message;
  43993. case regexpTag:
  43994. case stringTag:
  43995. // Coerce regexes to strings and treat strings, primitives and objects,
  43996. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  43997. // for more details.
  43998. return object == other + '';
  43999. case mapTag:
  44000. var convert = mapToArray;
  44001. case setTag:
  44002. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  44003. convert || (convert = setToArray);
  44004. if (object.size != other.size && !isPartial) {
  44005. return false;
  44006. }
  44007. // Assume cyclic values are equal.
  44008. var stacked = stack.get(object);
  44009. if (stacked) {
  44010. return stacked == other;
  44011. }
  44012. bitmask |= COMPARE_UNORDERED_FLAG;
  44013. // Recursively compare objects (susceptible to call stack limits).
  44014. stack.set(object, other);
  44015. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  44016. stack['delete'](object);
  44017. return result;
  44018. case symbolTag:
  44019. if (symbolValueOf) {
  44020. return symbolValueOf.call(object) == symbolValueOf.call(other);
  44021. }
  44022. }
  44023. return false;
  44024. }
  44025. /**
  44026. * A specialized version of `baseIsEqualDeep` for objects with support for
  44027. * partial deep comparisons.
  44028. *
  44029. * @private
  44030. * @param {Object} object The object to compare.
  44031. * @param {Object} other The other object to compare.
  44032. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  44033. * @param {Function} customizer The function to customize comparisons.
  44034. * @param {Function} equalFunc The function to determine equivalents of values.
  44035. * @param {Object} stack Tracks traversed `object` and `other` objects.
  44036. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  44037. */
  44038. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  44039. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  44040. objProps = getAllKeys(object),
  44041. objLength = objProps.length,
  44042. othProps = getAllKeys(other),
  44043. othLength = othProps.length;
  44044. if (objLength != othLength && !isPartial) {
  44045. return false;
  44046. }
  44047. var index = objLength;
  44048. while (index--) {
  44049. var key = objProps[index];
  44050. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  44051. return false;
  44052. }
  44053. }
  44054. // Assume cyclic values are equal.
  44055. var stacked = stack.get(object);
  44056. if (stacked && stack.get(other)) {
  44057. return stacked == other;
  44058. }
  44059. var result = true;
  44060. stack.set(object, other);
  44061. stack.set(other, object);
  44062. var skipCtor = isPartial;
  44063. while (++index < objLength) {
  44064. key = objProps[index];
  44065. var objValue = object[key],
  44066. othValue = other[key];
  44067. if (customizer) {
  44068. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  44069. }
  44070. // Recursively compare objects (susceptible to call stack limits).
  44071. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
  44072. result = false;
  44073. break;
  44074. }
  44075. skipCtor || (skipCtor = key == 'constructor');
  44076. }
  44077. if (result && !skipCtor) {
  44078. var objCtor = object.constructor,
  44079. othCtor = other.constructor;
  44080. // Non `Object` object instances with different constructors are not equal.
  44081. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  44082. result = false;
  44083. }
  44084. }
  44085. stack['delete'](object);
  44086. stack['delete'](other);
  44087. return result;
  44088. }
  44089. /**
  44090. * Creates an array of own enumerable property names and symbols of `object`.
  44091. *
  44092. * @private
  44093. * @param {Object} object The object to query.
  44094. * @returns {Array} Returns the array of property names and symbols.
  44095. */
  44096. function getAllKeys(object) {
  44097. return baseGetAllKeys(object, keys, getSymbols);
  44098. }
  44099. /**
  44100. * Gets the data for `map`.
  44101. *
  44102. * @private
  44103. * @param {Object} map The map to query.
  44104. * @param {string} key The reference key.
  44105. * @returns {*} Returns the map data.
  44106. */
  44107. function getMapData(map, key) {
  44108. var data = map.__data__;
  44109. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  44110. }
  44111. /**
  44112. * Gets the native function at `key` of `object`.
  44113. *
  44114. * @private
  44115. * @param {Object} object The object to query.
  44116. * @param {string} key The key of the method to get.
  44117. * @returns {*} Returns the function if it's native, else `undefined`.
  44118. */
  44119. function getNative(object, key) {
  44120. var value = getValue(object, key);
  44121. return baseIsNative(value) ? value : undefined;
  44122. }
  44123. /**
  44124. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  44125. *
  44126. * @private
  44127. * @param {*} value The value to query.
  44128. * @returns {string} Returns the raw `toStringTag`.
  44129. */
  44130. function getRawTag(value) {
  44131. var isOwn = hasOwnProperty.call(value, symToStringTag),
  44132. tag = value[symToStringTag];
  44133. try {
  44134. value[symToStringTag] = undefined;
  44135. var unmasked = true;
  44136. } catch (e) {}
  44137. var result = nativeObjectToString.call(value);
  44138. if (unmasked) {
  44139. if (isOwn) {
  44140. value[symToStringTag] = tag;
  44141. } else {
  44142. delete value[symToStringTag];
  44143. }
  44144. }
  44145. return result;
  44146. }
  44147. /**
  44148. * Creates an array of the own enumerable symbols of `object`.
  44149. *
  44150. * @private
  44151. * @param {Object} object The object to query.
  44152. * @returns {Array} Returns the array of symbols.
  44153. */
  44154. var getSymbols = !nativeGetSymbols ? stubArray : function (object) {
  44155. if (object == null) {
  44156. return [];
  44157. }
  44158. object = Object(object);
  44159. return arrayFilter(nativeGetSymbols(object), function (symbol) {
  44160. return propertyIsEnumerable.call(object, symbol);
  44161. });
  44162. };
  44163. /**
  44164. * Gets the `toStringTag` of `value`.
  44165. *
  44166. * @private
  44167. * @param {*} value The value to query.
  44168. * @returns {string} Returns the `toStringTag`.
  44169. */
  44170. var getTag = baseGetTag;
  44171. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  44172. if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise && getTag(Promise.resolve()) != promiseTag || Set && getTag(new Set()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
  44173. getTag = function (value) {
  44174. var result = baseGetTag(value),
  44175. Ctor = result == objectTag ? value.constructor : undefined,
  44176. ctorString = Ctor ? toSource(Ctor) : '';
  44177. if (ctorString) {
  44178. switch (ctorString) {
  44179. case dataViewCtorString:
  44180. return dataViewTag;
  44181. case mapCtorString:
  44182. return mapTag;
  44183. case promiseCtorString:
  44184. return promiseTag;
  44185. case setCtorString:
  44186. return setTag;
  44187. case weakMapCtorString:
  44188. return weakMapTag;
  44189. }
  44190. }
  44191. return result;
  44192. };
  44193. }
  44194. /**
  44195. * Checks if `value` is a valid array-like index.
  44196. *
  44197. * @private
  44198. * @param {*} value The value to check.
  44199. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  44200. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  44201. */
  44202. function isIndex(value, length) {
  44203. length = length == null ? MAX_SAFE_INTEGER : length;
  44204. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  44205. }
  44206. /**
  44207. * Checks if `value` is suitable for use as unique object key.
  44208. *
  44209. * @private
  44210. * @param {*} value The value to check.
  44211. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  44212. */
  44213. function isKeyable(value) {
  44214. var type = typeof value;
  44215. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  44216. }
  44217. /**
  44218. * Checks if `func` has its source masked.
  44219. *
  44220. * @private
  44221. * @param {Function} func The function to check.
  44222. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  44223. */
  44224. function isMasked(func) {
  44225. return !!maskSrcKey && maskSrcKey in func;
  44226. }
  44227. /**
  44228. * Checks if `value` is likely a prototype object.
  44229. *
  44230. * @private
  44231. * @param {*} value The value to check.
  44232. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  44233. */
  44234. function isPrototype(value) {
  44235. var Ctor = value && value.constructor,
  44236. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  44237. return value === proto;
  44238. }
  44239. /**
  44240. * Converts `value` to a string using `Object.prototype.toString`.
  44241. *
  44242. * @private
  44243. * @param {*} value The value to convert.
  44244. * @returns {string} Returns the converted string.
  44245. */
  44246. function objectToString(value) {
  44247. return nativeObjectToString.call(value);
  44248. }
  44249. /**
  44250. * Converts `func` to its source code.
  44251. *
  44252. * @private
  44253. * @param {Function} func The function to convert.
  44254. * @returns {string} Returns the source code.
  44255. */
  44256. function toSource(func) {
  44257. if (func != null) {
  44258. try {
  44259. return funcToString.call(func);
  44260. } catch (e) {}
  44261. try {
  44262. return func + '';
  44263. } catch (e) {}
  44264. }
  44265. return '';
  44266. }
  44267. /**
  44268. * Performs a
  44269. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  44270. * comparison between two values to determine if they are equivalent.
  44271. *
  44272. * @static
  44273. * @memberOf _
  44274. * @since 4.0.0
  44275. * @category Lang
  44276. * @param {*} value The value to compare.
  44277. * @param {*} other The other value to compare.
  44278. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  44279. * @example
  44280. *
  44281. * var object = { 'a': 1 };
  44282. * var other = { 'a': 1 };
  44283. *
  44284. * _.eq(object, object);
  44285. * // => true
  44286. *
  44287. * _.eq(object, other);
  44288. * // => false
  44289. *
  44290. * _.eq('a', 'a');
  44291. * // => true
  44292. *
  44293. * _.eq('a', Object('a'));
  44294. * // => false
  44295. *
  44296. * _.eq(NaN, NaN);
  44297. * // => true
  44298. */
  44299. function eq(value, other) {
  44300. return value === other || value !== value && other !== other;
  44301. }
  44302. /**
  44303. * Checks if `value` is likely an `arguments` object.
  44304. *
  44305. * @static
  44306. * @memberOf _
  44307. * @since 0.1.0
  44308. * @category Lang
  44309. * @param {*} value The value to check.
  44310. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  44311. * else `false`.
  44312. * @example
  44313. *
  44314. * _.isArguments(function() { return arguments; }());
  44315. * // => true
  44316. *
  44317. * _.isArguments([1, 2, 3]);
  44318. * // => false
  44319. */
  44320. var isArguments = baseIsArguments(function () {
  44321. return arguments;
  44322. }()) ? baseIsArguments : function (value) {
  44323. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  44324. };
  44325. /**
  44326. * Checks if `value` is classified as an `Array` object.
  44327. *
  44328. * @static
  44329. * @memberOf _
  44330. * @since 0.1.0
  44331. * @category Lang
  44332. * @param {*} value The value to check.
  44333. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  44334. * @example
  44335. *
  44336. * _.isArray([1, 2, 3]);
  44337. * // => true
  44338. *
  44339. * _.isArray(document.body.children);
  44340. * // => false
  44341. *
  44342. * _.isArray('abc');
  44343. * // => false
  44344. *
  44345. * _.isArray(_.noop);
  44346. * // => false
  44347. */
  44348. var isArray = Array.isArray;
  44349. /**
  44350. * Checks if `value` is array-like. A value is considered array-like if it's
  44351. * not a function and has a `value.length` that's an integer greater than or
  44352. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  44353. *
  44354. * @static
  44355. * @memberOf _
  44356. * @since 4.0.0
  44357. * @category Lang
  44358. * @param {*} value The value to check.
  44359. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  44360. * @example
  44361. *
  44362. * _.isArrayLike([1, 2, 3]);
  44363. * // => true
  44364. *
  44365. * _.isArrayLike(document.body.children);
  44366. * // => true
  44367. *
  44368. * _.isArrayLike('abc');
  44369. * // => true
  44370. *
  44371. * _.isArrayLike(_.noop);
  44372. * // => false
  44373. */
  44374. function isArrayLike(value) {
  44375. return value != null && isLength(value.length) && !isFunction(value);
  44376. }
  44377. /**
  44378. * Checks if `value` is a buffer.
  44379. *
  44380. * @static
  44381. * @memberOf _
  44382. * @since 4.3.0
  44383. * @category Lang
  44384. * @param {*} value The value to check.
  44385. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  44386. * @example
  44387. *
  44388. * _.isBuffer(new Buffer(2));
  44389. * // => true
  44390. *
  44391. * _.isBuffer(new Uint8Array(2));
  44392. * // => false
  44393. */
  44394. var isBuffer = nativeIsBuffer || stubFalse;
  44395. /**
  44396. * Performs a deep comparison between two values to determine if they are
  44397. * equivalent.
  44398. *
  44399. * **Note:** This method supports comparing arrays, array buffers, booleans,
  44400. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  44401. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  44402. * by their own, not inherited, enumerable properties. Functions and DOM
  44403. * nodes are compared by strict equality, i.e. `===`.
  44404. *
  44405. * @static
  44406. * @memberOf _
  44407. * @since 0.1.0
  44408. * @category Lang
  44409. * @param {*} value The value to compare.
  44410. * @param {*} other The other value to compare.
  44411. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  44412. * @example
  44413. *
  44414. * var object = { 'a': 1 };
  44415. * var other = { 'a': 1 };
  44416. *
  44417. * _.isEqual(object, other);
  44418. * // => true
  44419. *
  44420. * object === other;
  44421. * // => false
  44422. */
  44423. function isEqual(value, other) {
  44424. return baseIsEqual(value, other);
  44425. }
  44426. /**
  44427. * Checks if `value` is classified as a `Function` object.
  44428. *
  44429. * @static
  44430. * @memberOf _
  44431. * @since 0.1.0
  44432. * @category Lang
  44433. * @param {*} value The value to check.
  44434. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  44435. * @example
  44436. *
  44437. * _.isFunction(_);
  44438. * // => true
  44439. *
  44440. * _.isFunction(/abc/);
  44441. * // => false
  44442. */
  44443. function isFunction(value) {
  44444. if (!isObject(value)) {
  44445. return false;
  44446. }
  44447. // The use of `Object#toString` avoids issues with the `typeof` operator
  44448. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  44449. var tag = baseGetTag(value);
  44450. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  44451. }
  44452. /**
  44453. * Checks if `value` is a valid array-like length.
  44454. *
  44455. * **Note:** This method is loosely based on
  44456. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  44457. *
  44458. * @static
  44459. * @memberOf _
  44460. * @since 4.0.0
  44461. * @category Lang
  44462. * @param {*} value The value to check.
  44463. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  44464. * @example
  44465. *
  44466. * _.isLength(3);
  44467. * // => true
  44468. *
  44469. * _.isLength(Number.MIN_VALUE);
  44470. * // => false
  44471. *
  44472. * _.isLength(Infinity);
  44473. * // => false
  44474. *
  44475. * _.isLength('3');
  44476. * // => false
  44477. */
  44478. function isLength(value) {
  44479. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  44480. }
  44481. /**
  44482. * Checks if `value` is the
  44483. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  44484. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  44485. *
  44486. * @static
  44487. * @memberOf _
  44488. * @since 0.1.0
  44489. * @category Lang
  44490. * @param {*} value The value to check.
  44491. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  44492. * @example
  44493. *
  44494. * _.isObject({});
  44495. * // => true
  44496. *
  44497. * _.isObject([1, 2, 3]);
  44498. * // => true
  44499. *
  44500. * _.isObject(_.noop);
  44501. * // => true
  44502. *
  44503. * _.isObject(null);
  44504. * // => false
  44505. */
  44506. function isObject(value) {
  44507. var type = typeof value;
  44508. return value != null && (type == 'object' || type == 'function');
  44509. }
  44510. /**
  44511. * Checks if `value` is object-like. A value is object-like if it's not `null`
  44512. * and has a `typeof` result of "object".
  44513. *
  44514. * @static
  44515. * @memberOf _
  44516. * @since 4.0.0
  44517. * @category Lang
  44518. * @param {*} value The value to check.
  44519. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  44520. * @example
  44521. *
  44522. * _.isObjectLike({});
  44523. * // => true
  44524. *
  44525. * _.isObjectLike([1, 2, 3]);
  44526. * // => true
  44527. *
  44528. * _.isObjectLike(_.noop);
  44529. * // => false
  44530. *
  44531. * _.isObjectLike(null);
  44532. * // => false
  44533. */
  44534. function isObjectLike(value) {
  44535. return value != null && typeof value == 'object';
  44536. }
  44537. /**
  44538. * Checks if `value` is classified as a typed array.
  44539. *
  44540. * @static
  44541. * @memberOf _
  44542. * @since 3.0.0
  44543. * @category Lang
  44544. * @param {*} value The value to check.
  44545. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  44546. * @example
  44547. *
  44548. * _.isTypedArray(new Uint8Array);
  44549. * // => true
  44550. *
  44551. * _.isTypedArray([]);
  44552. * // => false
  44553. */
  44554. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  44555. /**
  44556. * Creates an array of the own enumerable property names of `object`.
  44557. *
  44558. * **Note:** Non-object values are coerced to objects. See the
  44559. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  44560. * for more details.
  44561. *
  44562. * @static
  44563. * @since 0.1.0
  44564. * @memberOf _
  44565. * @category Object
  44566. * @param {Object} object The object to query.
  44567. * @returns {Array} Returns the array of property names.
  44568. * @example
  44569. *
  44570. * function Foo() {
  44571. * this.a = 1;
  44572. * this.b = 2;
  44573. * }
  44574. *
  44575. * Foo.prototype.c = 3;
  44576. *
  44577. * _.keys(new Foo);
  44578. * // => ['a', 'b'] (iteration order is not guaranteed)
  44579. *
  44580. * _.keys('hi');
  44581. * // => ['0', '1']
  44582. */
  44583. function keys(object) {
  44584. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  44585. }
  44586. /**
  44587. * This method returns a new empty array.
  44588. *
  44589. * @static
  44590. * @memberOf _
  44591. * @since 4.13.0
  44592. * @category Util
  44593. * @returns {Array} Returns the new empty array.
  44594. * @example
  44595. *
  44596. * var arrays = _.times(2, _.stubArray);
  44597. *
  44598. * console.log(arrays);
  44599. * // => [[], []]
  44600. *
  44601. * console.log(arrays[0] === arrays[1]);
  44602. * // => false
  44603. */
  44604. function stubArray() {
  44605. return [];
  44606. }
  44607. /**
  44608. * This method returns `false`.
  44609. *
  44610. * @static
  44611. * @memberOf _
  44612. * @since 4.13.0
  44613. * @category Util
  44614. * @returns {boolean} Returns `false`.
  44615. * @example
  44616. *
  44617. * _.times(2, _.stubFalse);
  44618. * // => [false, false]
  44619. */
  44620. function stubFalse() {
  44621. return false;
  44622. }
  44623. module.exports = isEqual;
  44624. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  44625. },{}],446:[function(require,module,exports){
  44626. (function (global){(function (){
  44627. "use strict";
  44628. /**
  44629. * Lodash (Custom Build) <https://lodash.com/>
  44630. * Build: `lodash modularize exports="npm" -o ./`
  44631. * Copyright JS Foundation and other contributors <https://js.foundation/>
  44632. * Released under MIT license <https://lodash.com/license>
  44633. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44634. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44635. */
  44636. /** `Object#toString` result references. */
  44637. var asyncTag = '[object AsyncFunction]',
  44638. funcTag = '[object Function]',
  44639. genTag = '[object GeneratorFunction]',
  44640. nullTag = '[object Null]',
  44641. proxyTag = '[object Proxy]',
  44642. undefinedTag = '[object Undefined]';
  44643. /** Detect free variable `global` from Node.js. */
  44644. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  44645. /** Detect free variable `self`. */
  44646. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  44647. /** Used as a reference to the global object. */
  44648. var root = freeGlobal || freeSelf || Function('return this')();
  44649. /** Used for built-in method references. */
  44650. var objectProto = Object.prototype;
  44651. /** Used to check objects for own properties. */
  44652. var hasOwnProperty = objectProto.hasOwnProperty;
  44653. /**
  44654. * Used to resolve the
  44655. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  44656. * of values.
  44657. */
  44658. var nativeObjectToString = objectProto.toString;
  44659. /** Built-in value references. */
  44660. var Symbol = root.Symbol,
  44661. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  44662. /**
  44663. * The base implementation of `getTag` without fallbacks for buggy environments.
  44664. *
  44665. * @private
  44666. * @param {*} value The value to query.
  44667. * @returns {string} Returns the `toStringTag`.
  44668. */
  44669. function baseGetTag(value) {
  44670. if (value == null) {
  44671. return value === undefined ? undefinedTag : nullTag;
  44672. }
  44673. return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
  44674. }
  44675. /**
  44676. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  44677. *
  44678. * @private
  44679. * @param {*} value The value to query.
  44680. * @returns {string} Returns the raw `toStringTag`.
  44681. */
  44682. function getRawTag(value) {
  44683. var isOwn = hasOwnProperty.call(value, symToStringTag),
  44684. tag = value[symToStringTag];
  44685. try {
  44686. value[symToStringTag] = undefined;
  44687. var unmasked = true;
  44688. } catch (e) {}
  44689. var result = nativeObjectToString.call(value);
  44690. if (unmasked) {
  44691. if (isOwn) {
  44692. value[symToStringTag] = tag;
  44693. } else {
  44694. delete value[symToStringTag];
  44695. }
  44696. }
  44697. return result;
  44698. }
  44699. /**
  44700. * Converts `value` to a string using `Object.prototype.toString`.
  44701. *
  44702. * @private
  44703. * @param {*} value The value to convert.
  44704. * @returns {string} Returns the converted string.
  44705. */
  44706. function objectToString(value) {
  44707. return nativeObjectToString.call(value);
  44708. }
  44709. /**
  44710. * Checks if `value` is classified as a `Function` object.
  44711. *
  44712. * @static
  44713. * @memberOf _
  44714. * @since 0.1.0
  44715. * @category Lang
  44716. * @param {*} value The value to check.
  44717. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  44718. * @example
  44719. *
  44720. * _.isFunction(_);
  44721. * // => true
  44722. *
  44723. * _.isFunction(/abc/);
  44724. * // => false
  44725. */
  44726. function isFunction(value) {
  44727. if (!isObject(value)) {
  44728. return false;
  44729. }
  44730. // The use of `Object#toString` avoids issues with the `typeof` operator
  44731. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  44732. var tag = baseGetTag(value);
  44733. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  44734. }
  44735. /**
  44736. * Checks if `value` is the
  44737. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  44738. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  44739. *
  44740. * @static
  44741. * @memberOf _
  44742. * @since 0.1.0
  44743. * @category Lang
  44744. * @param {*} value The value to check.
  44745. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  44746. * @example
  44747. *
  44748. * _.isObject({});
  44749. * // => true
  44750. *
  44751. * _.isObject([1, 2, 3]);
  44752. * // => true
  44753. *
  44754. * _.isObject(_.noop);
  44755. * // => true
  44756. *
  44757. * _.isObject(null);
  44758. * // => false
  44759. */
  44760. function isObject(value) {
  44761. var type = typeof value;
  44762. return value != null && (type == 'object' || type == 'function');
  44763. }
  44764. module.exports = isFunction;
  44765. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  44766. },{}],447:[function(require,module,exports){
  44767. "use strict";
  44768. /**
  44769. * lodash 4.0.0 (Custom Build) <https://lodash.com/>
  44770. * Build: `lodash modularize exports="npm" -o ./`
  44771. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  44772. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44773. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44774. * Available under MIT license <https://lodash.com/license>
  44775. */
  44776. /**
  44777. * Checks if `value` is `null` or `undefined`.
  44778. *
  44779. * @static
  44780. * @memberOf _
  44781. * @category Lang
  44782. * @param {*} value The value to check.
  44783. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  44784. * @example
  44785. *
  44786. * _.isNil(null);
  44787. * // => true
  44788. *
  44789. * _.isNil(void 0);
  44790. * // => true
  44791. *
  44792. * _.isNil(NaN);
  44793. * // => false
  44794. */
  44795. function isNil(value) {
  44796. return value == null;
  44797. }
  44798. module.exports = isNil;
  44799. },{}],448:[function(require,module,exports){
  44800. "use strict";
  44801. /**
  44802. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  44803. * Build: `lodash modern modularize exports="npm" -o ./`
  44804. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  44805. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44806. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44807. * Available under MIT license <https://lodash.com/license>
  44808. */
  44809. /**
  44810. * Checks if `value` is `undefined`.
  44811. *
  44812. * @static
  44813. * @memberOf _
  44814. * @category Lang
  44815. * @param {*} value The value to check.
  44816. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  44817. * @example
  44818. *
  44819. * _.isUndefined(void 0);
  44820. * // => true
  44821. *
  44822. * _.isUndefined(null);
  44823. * // => false
  44824. */
  44825. function isUndefined(value) {
  44826. return value === undefined;
  44827. }
  44828. module.exports = isUndefined;
  44829. },{}],449:[function(require,module,exports){
  44830. (function (global){(function (){
  44831. "use strict";
  44832. /**
  44833. * lodash (Custom Build) <https://lodash.com/>
  44834. * Build: `lodash modularize exports="npm" -o ./`
  44835. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  44836. * Released under MIT license <https://lodash.com/license>
  44837. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  44838. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  44839. */
  44840. /** Used as the size to enable large array optimizations. */
  44841. var LARGE_ARRAY_SIZE = 200;
  44842. /** Used to stand-in for `undefined` hash values. */
  44843. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  44844. /** Used as references for various `Number` constants. */
  44845. var INFINITY = 1 / 0;
  44846. /** `Object#toString` result references. */
  44847. var funcTag = '[object Function]',
  44848. genTag = '[object GeneratorFunction]';
  44849. /**
  44850. * Used to match `RegExp`
  44851. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  44852. */
  44853. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  44854. /** Used to detect host constructors (Safari). */
  44855. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  44856. /** Detect free variable `global` from Node.js. */
  44857. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  44858. /** Detect free variable `self`. */
  44859. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  44860. /** Used as a reference to the global object. */
  44861. var root = freeGlobal || freeSelf || Function('return this')();
  44862. /**
  44863. * A specialized version of `_.includes` for arrays without support for
  44864. * specifying an index to search from.
  44865. *
  44866. * @private
  44867. * @param {Array} [array] The array to inspect.
  44868. * @param {*} target The value to search for.
  44869. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  44870. */
  44871. function arrayIncludes(array, value) {
  44872. var length = array ? array.length : 0;
  44873. return !!length && baseIndexOf(array, value, 0) > -1;
  44874. }
  44875. /**
  44876. * This function is like `arrayIncludes` except that it accepts a comparator.
  44877. *
  44878. * @private
  44879. * @param {Array} [array] The array to inspect.
  44880. * @param {*} target The value to search for.
  44881. * @param {Function} comparator The comparator invoked per element.
  44882. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  44883. */
  44884. function arrayIncludesWith(array, value, comparator) {
  44885. var index = -1,
  44886. length = array ? array.length : 0;
  44887. while (++index < length) {
  44888. if (comparator(value, array[index])) {
  44889. return true;
  44890. }
  44891. }
  44892. return false;
  44893. }
  44894. /**
  44895. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  44896. * support for iteratee shorthands.
  44897. *
  44898. * @private
  44899. * @param {Array} array The array to inspect.
  44900. * @param {Function} predicate The function invoked per iteration.
  44901. * @param {number} fromIndex The index to search from.
  44902. * @param {boolean} [fromRight] Specify iterating from right to left.
  44903. * @returns {number} Returns the index of the matched value, else `-1`.
  44904. */
  44905. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  44906. var length = array.length,
  44907. index = fromIndex + (fromRight ? 1 : -1);
  44908. while (fromRight ? index-- : ++index < length) {
  44909. if (predicate(array[index], index, array)) {
  44910. return index;
  44911. }
  44912. }
  44913. return -1;
  44914. }
  44915. /**
  44916. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  44917. *
  44918. * @private
  44919. * @param {Array} array The array to inspect.
  44920. * @param {*} value The value to search for.
  44921. * @param {number} fromIndex The index to search from.
  44922. * @returns {number} Returns the index of the matched value, else `-1`.
  44923. */
  44924. function baseIndexOf(array, value, fromIndex) {
  44925. if (value !== value) {
  44926. return baseFindIndex(array, baseIsNaN, fromIndex);
  44927. }
  44928. var index = fromIndex - 1,
  44929. length = array.length;
  44930. while (++index < length) {
  44931. if (array[index] === value) {
  44932. return index;
  44933. }
  44934. }
  44935. return -1;
  44936. }
  44937. /**
  44938. * The base implementation of `_.isNaN` without support for number objects.
  44939. *
  44940. * @private
  44941. * @param {*} value The value to check.
  44942. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  44943. */
  44944. function baseIsNaN(value) {
  44945. return value !== value;
  44946. }
  44947. /**
  44948. * Checks if a cache value for `key` exists.
  44949. *
  44950. * @private
  44951. * @param {Object} cache The cache to query.
  44952. * @param {string} key The key of the entry to check.
  44953. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  44954. */
  44955. function cacheHas(cache, key) {
  44956. return cache.has(key);
  44957. }
  44958. /**
  44959. * Gets the value at `key` of `object`.
  44960. *
  44961. * @private
  44962. * @param {Object} [object] The object to query.
  44963. * @param {string} key The key of the property to get.
  44964. * @returns {*} Returns the property value.
  44965. */
  44966. function getValue(object, key) {
  44967. return object == null ? undefined : object[key];
  44968. }
  44969. /**
  44970. * Checks if `value` is a host object in IE < 9.
  44971. *
  44972. * @private
  44973. * @param {*} value The value to check.
  44974. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  44975. */
  44976. function isHostObject(value) {
  44977. // Many host objects are `Object` objects that can coerce to strings
  44978. // despite having improperly defined `toString` methods.
  44979. var result = false;
  44980. if (value != null && typeof value.toString != 'function') {
  44981. try {
  44982. result = !!(value + '');
  44983. } catch (e) {}
  44984. }
  44985. return result;
  44986. }
  44987. /**
  44988. * Converts `set` to an array of its values.
  44989. *
  44990. * @private
  44991. * @param {Object} set The set to convert.
  44992. * @returns {Array} Returns the values.
  44993. */
  44994. function setToArray(set) {
  44995. var index = -1,
  44996. result = Array(set.size);
  44997. set.forEach(function (value) {
  44998. result[++index] = value;
  44999. });
  45000. return result;
  45001. }
  45002. /** Used for built-in method references. */
  45003. var arrayProto = Array.prototype,
  45004. funcProto = Function.prototype,
  45005. objectProto = Object.prototype;
  45006. /** Used to detect overreaching core-js shims. */
  45007. var coreJsData = root['__core-js_shared__'];
  45008. /** Used to detect methods masquerading as native. */
  45009. var maskSrcKey = function () {
  45010. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  45011. return uid ? 'Symbol(src)_1.' + uid : '';
  45012. }();
  45013. /** Used to resolve the decompiled source of functions. */
  45014. var funcToString = funcProto.toString;
  45015. /** Used to check objects for own properties. */
  45016. var hasOwnProperty = objectProto.hasOwnProperty;
  45017. /**
  45018. * Used to resolve the
  45019. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  45020. * of values.
  45021. */
  45022. var objectToString = objectProto.toString;
  45023. /** Used to detect if a method is native. */
  45024. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  45025. /** Built-in value references. */
  45026. var splice = arrayProto.splice;
  45027. /* Built-in method references that are verified to be native. */
  45028. var Map = getNative(root, 'Map'),
  45029. Set = getNative(root, 'Set'),
  45030. nativeCreate = getNative(Object, 'create');
  45031. /**
  45032. * Creates a hash object.
  45033. *
  45034. * @private
  45035. * @constructor
  45036. * @param {Array} [entries] The key-value pairs to cache.
  45037. */
  45038. function Hash(entries) {
  45039. var index = -1,
  45040. length = entries ? entries.length : 0;
  45041. this.clear();
  45042. while (++index < length) {
  45043. var entry = entries[index];
  45044. this.set(entry[0], entry[1]);
  45045. }
  45046. }
  45047. /**
  45048. * Removes all key-value entries from the hash.
  45049. *
  45050. * @private
  45051. * @name clear
  45052. * @memberOf Hash
  45053. */
  45054. function hashClear() {
  45055. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  45056. }
  45057. /**
  45058. * Removes `key` and its value from the hash.
  45059. *
  45060. * @private
  45061. * @name delete
  45062. * @memberOf Hash
  45063. * @param {Object} hash The hash to modify.
  45064. * @param {string} key The key of the value to remove.
  45065. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45066. */
  45067. function hashDelete(key) {
  45068. return this.has(key) && delete this.__data__[key];
  45069. }
  45070. /**
  45071. * Gets the hash value for `key`.
  45072. *
  45073. * @private
  45074. * @name get
  45075. * @memberOf Hash
  45076. * @param {string} key The key of the value to get.
  45077. * @returns {*} Returns the entry value.
  45078. */
  45079. function hashGet(key) {
  45080. var data = this.__data__;
  45081. if (nativeCreate) {
  45082. var result = data[key];
  45083. return result === HASH_UNDEFINED ? undefined : result;
  45084. }
  45085. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  45086. }
  45087. /**
  45088. * Checks if a hash value for `key` exists.
  45089. *
  45090. * @private
  45091. * @name has
  45092. * @memberOf Hash
  45093. * @param {string} key The key of the entry to check.
  45094. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45095. */
  45096. function hashHas(key) {
  45097. var data = this.__data__;
  45098. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  45099. }
  45100. /**
  45101. * Sets the hash `key` to `value`.
  45102. *
  45103. * @private
  45104. * @name set
  45105. * @memberOf Hash
  45106. * @param {string} key The key of the value to set.
  45107. * @param {*} value The value to set.
  45108. * @returns {Object} Returns the hash instance.
  45109. */
  45110. function hashSet(key, value) {
  45111. var data = this.__data__;
  45112. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  45113. return this;
  45114. }
  45115. // Add methods to `Hash`.
  45116. Hash.prototype.clear = hashClear;
  45117. Hash.prototype['delete'] = hashDelete;
  45118. Hash.prototype.get = hashGet;
  45119. Hash.prototype.has = hashHas;
  45120. Hash.prototype.set = hashSet;
  45121. /**
  45122. * Creates an list cache object.
  45123. *
  45124. * @private
  45125. * @constructor
  45126. * @param {Array} [entries] The key-value pairs to cache.
  45127. */
  45128. function ListCache(entries) {
  45129. var index = -1,
  45130. length = entries ? entries.length : 0;
  45131. this.clear();
  45132. while (++index < length) {
  45133. var entry = entries[index];
  45134. this.set(entry[0], entry[1]);
  45135. }
  45136. }
  45137. /**
  45138. * Removes all key-value entries from the list cache.
  45139. *
  45140. * @private
  45141. * @name clear
  45142. * @memberOf ListCache
  45143. */
  45144. function listCacheClear() {
  45145. this.__data__ = [];
  45146. }
  45147. /**
  45148. * Removes `key` and its value from the list cache.
  45149. *
  45150. * @private
  45151. * @name delete
  45152. * @memberOf ListCache
  45153. * @param {string} key The key of the value to remove.
  45154. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45155. */
  45156. function listCacheDelete(key) {
  45157. var data = this.__data__,
  45158. index = assocIndexOf(data, key);
  45159. if (index < 0) {
  45160. return false;
  45161. }
  45162. var lastIndex = data.length - 1;
  45163. if (index == lastIndex) {
  45164. data.pop();
  45165. } else {
  45166. splice.call(data, index, 1);
  45167. }
  45168. return true;
  45169. }
  45170. /**
  45171. * Gets the list cache value for `key`.
  45172. *
  45173. * @private
  45174. * @name get
  45175. * @memberOf ListCache
  45176. * @param {string} key The key of the value to get.
  45177. * @returns {*} Returns the entry value.
  45178. */
  45179. function listCacheGet(key) {
  45180. var data = this.__data__,
  45181. index = assocIndexOf(data, key);
  45182. return index < 0 ? undefined : data[index][1];
  45183. }
  45184. /**
  45185. * Checks if a list cache value for `key` exists.
  45186. *
  45187. * @private
  45188. * @name has
  45189. * @memberOf ListCache
  45190. * @param {string} key The key of the entry to check.
  45191. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45192. */
  45193. function listCacheHas(key) {
  45194. return assocIndexOf(this.__data__, key) > -1;
  45195. }
  45196. /**
  45197. * Sets the list cache `key` to `value`.
  45198. *
  45199. * @private
  45200. * @name set
  45201. * @memberOf ListCache
  45202. * @param {string} key The key of the value to set.
  45203. * @param {*} value The value to set.
  45204. * @returns {Object} Returns the list cache instance.
  45205. */
  45206. function listCacheSet(key, value) {
  45207. var data = this.__data__,
  45208. index = assocIndexOf(data, key);
  45209. if (index < 0) {
  45210. data.push([key, value]);
  45211. } else {
  45212. data[index][1] = value;
  45213. }
  45214. return this;
  45215. }
  45216. // Add methods to `ListCache`.
  45217. ListCache.prototype.clear = listCacheClear;
  45218. ListCache.prototype['delete'] = listCacheDelete;
  45219. ListCache.prototype.get = listCacheGet;
  45220. ListCache.prototype.has = listCacheHas;
  45221. ListCache.prototype.set = listCacheSet;
  45222. /**
  45223. * Creates a map cache object to store key-value pairs.
  45224. *
  45225. * @private
  45226. * @constructor
  45227. * @param {Array} [entries] The key-value pairs to cache.
  45228. */
  45229. function MapCache(entries) {
  45230. var index = -1,
  45231. length = entries ? entries.length : 0;
  45232. this.clear();
  45233. while (++index < length) {
  45234. var entry = entries[index];
  45235. this.set(entry[0], entry[1]);
  45236. }
  45237. }
  45238. /**
  45239. * Removes all key-value entries from the map.
  45240. *
  45241. * @private
  45242. * @name clear
  45243. * @memberOf MapCache
  45244. */
  45245. function mapCacheClear() {
  45246. this.__data__ = {
  45247. 'hash': new Hash(),
  45248. 'map': new (Map || ListCache)(),
  45249. 'string': new Hash()
  45250. };
  45251. }
  45252. /**
  45253. * Removes `key` and its value from the map.
  45254. *
  45255. * @private
  45256. * @name delete
  45257. * @memberOf MapCache
  45258. * @param {string} key The key of the value to remove.
  45259. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  45260. */
  45261. function mapCacheDelete(key) {
  45262. return getMapData(this, key)['delete'](key);
  45263. }
  45264. /**
  45265. * Gets the map value for `key`.
  45266. *
  45267. * @private
  45268. * @name get
  45269. * @memberOf MapCache
  45270. * @param {string} key The key of the value to get.
  45271. * @returns {*} Returns the entry value.
  45272. */
  45273. function mapCacheGet(key) {
  45274. return getMapData(this, key).get(key);
  45275. }
  45276. /**
  45277. * Checks if a map value for `key` exists.
  45278. *
  45279. * @private
  45280. * @name has
  45281. * @memberOf MapCache
  45282. * @param {string} key The key of the entry to check.
  45283. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  45284. */
  45285. function mapCacheHas(key) {
  45286. return getMapData(this, key).has(key);
  45287. }
  45288. /**
  45289. * Sets the map `key` to `value`.
  45290. *
  45291. * @private
  45292. * @name set
  45293. * @memberOf MapCache
  45294. * @param {string} key The key of the value to set.
  45295. * @param {*} value The value to set.
  45296. * @returns {Object} Returns the map cache instance.
  45297. */
  45298. function mapCacheSet(key, value) {
  45299. getMapData(this, key).set(key, value);
  45300. return this;
  45301. }
  45302. // Add methods to `MapCache`.
  45303. MapCache.prototype.clear = mapCacheClear;
  45304. MapCache.prototype['delete'] = mapCacheDelete;
  45305. MapCache.prototype.get = mapCacheGet;
  45306. MapCache.prototype.has = mapCacheHas;
  45307. MapCache.prototype.set = mapCacheSet;
  45308. /**
  45309. *
  45310. * Creates an array cache object to store unique values.
  45311. *
  45312. * @private
  45313. * @constructor
  45314. * @param {Array} [values] The values to cache.
  45315. */
  45316. function SetCache(values) {
  45317. var index = -1,
  45318. length = values ? values.length : 0;
  45319. this.__data__ = new MapCache();
  45320. while (++index < length) {
  45321. this.add(values[index]);
  45322. }
  45323. }
  45324. /**
  45325. * Adds `value` to the array cache.
  45326. *
  45327. * @private
  45328. * @name add
  45329. * @memberOf SetCache
  45330. * @alias push
  45331. * @param {*} value The value to cache.
  45332. * @returns {Object} Returns the cache instance.
  45333. */
  45334. function setCacheAdd(value) {
  45335. this.__data__.set(value, HASH_UNDEFINED);
  45336. return this;
  45337. }
  45338. /**
  45339. * Checks if `value` is in the array cache.
  45340. *
  45341. * @private
  45342. * @name has
  45343. * @memberOf SetCache
  45344. * @param {*} value The value to search for.
  45345. * @returns {number} Returns `true` if `value` is found, else `false`.
  45346. */
  45347. function setCacheHas(value) {
  45348. return this.__data__.has(value);
  45349. }
  45350. // Add methods to `SetCache`.
  45351. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  45352. SetCache.prototype.has = setCacheHas;
  45353. /**
  45354. * Gets the index at which the `key` is found in `array` of key-value pairs.
  45355. *
  45356. * @private
  45357. * @param {Array} array The array to inspect.
  45358. * @param {*} key The key to search for.
  45359. * @returns {number} Returns the index of the matched value, else `-1`.
  45360. */
  45361. function assocIndexOf(array, key) {
  45362. var length = array.length;
  45363. while (length--) {
  45364. if (eq(array[length][0], key)) {
  45365. return length;
  45366. }
  45367. }
  45368. return -1;
  45369. }
  45370. /**
  45371. * The base implementation of `_.isNative` without bad shim checks.
  45372. *
  45373. * @private
  45374. * @param {*} value The value to check.
  45375. * @returns {boolean} Returns `true` if `value` is a native function,
  45376. * else `false`.
  45377. */
  45378. function baseIsNative(value) {
  45379. if (!isObject(value) || isMasked(value)) {
  45380. return false;
  45381. }
  45382. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  45383. return pattern.test(toSource(value));
  45384. }
  45385. /**
  45386. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  45387. *
  45388. * @private
  45389. * @param {Array} array The array to inspect.
  45390. * @param {Function} [iteratee] The iteratee invoked per element.
  45391. * @param {Function} [comparator] The comparator invoked per element.
  45392. * @returns {Array} Returns the new duplicate free array.
  45393. */
  45394. function baseUniq(array, iteratee, comparator) {
  45395. var index = -1,
  45396. includes = arrayIncludes,
  45397. length = array.length,
  45398. isCommon = true,
  45399. result = [],
  45400. seen = result;
  45401. if (comparator) {
  45402. isCommon = false;
  45403. includes = arrayIncludesWith;
  45404. } else if (length >= LARGE_ARRAY_SIZE) {
  45405. var set = iteratee ? null : createSet(array);
  45406. if (set) {
  45407. return setToArray(set);
  45408. }
  45409. isCommon = false;
  45410. includes = cacheHas;
  45411. seen = new SetCache();
  45412. } else {
  45413. seen = iteratee ? [] : result;
  45414. }
  45415. outer: while (++index < length) {
  45416. var value = array[index],
  45417. computed = iteratee ? iteratee(value) : value;
  45418. value = comparator || value !== 0 ? value : 0;
  45419. if (isCommon && computed === computed) {
  45420. var seenIndex = seen.length;
  45421. while (seenIndex--) {
  45422. if (seen[seenIndex] === computed) {
  45423. continue outer;
  45424. }
  45425. }
  45426. if (iteratee) {
  45427. seen.push(computed);
  45428. }
  45429. result.push(value);
  45430. } else if (!includes(seen, computed, comparator)) {
  45431. if (seen !== result) {
  45432. seen.push(computed);
  45433. }
  45434. result.push(value);
  45435. }
  45436. }
  45437. return result;
  45438. }
  45439. /**
  45440. * Creates a set object of `values`.
  45441. *
  45442. * @private
  45443. * @param {Array} values The values to add to the set.
  45444. * @returns {Object} Returns the new set.
  45445. */
  45446. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  45447. return new Set(values);
  45448. };
  45449. /**
  45450. * Gets the data for `map`.
  45451. *
  45452. * @private
  45453. * @param {Object} map The map to query.
  45454. * @param {string} key The reference key.
  45455. * @returns {*} Returns the map data.
  45456. */
  45457. function getMapData(map, key) {
  45458. var data = map.__data__;
  45459. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  45460. }
  45461. /**
  45462. * Gets the native function at `key` of `object`.
  45463. *
  45464. * @private
  45465. * @param {Object} object The object to query.
  45466. * @param {string} key The key of the method to get.
  45467. * @returns {*} Returns the function if it's native, else `undefined`.
  45468. */
  45469. function getNative(object, key) {
  45470. var value = getValue(object, key);
  45471. return baseIsNative(value) ? value : undefined;
  45472. }
  45473. /**
  45474. * Checks if `value` is suitable for use as unique object key.
  45475. *
  45476. * @private
  45477. * @param {*} value The value to check.
  45478. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  45479. */
  45480. function isKeyable(value) {
  45481. var type = typeof value;
  45482. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  45483. }
  45484. /**
  45485. * Checks if `func` has its source masked.
  45486. *
  45487. * @private
  45488. * @param {Function} func The function to check.
  45489. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  45490. */
  45491. function isMasked(func) {
  45492. return !!maskSrcKey && maskSrcKey in func;
  45493. }
  45494. /**
  45495. * Converts `func` to its source code.
  45496. *
  45497. * @private
  45498. * @param {Function} func The function to process.
  45499. * @returns {string} Returns the source code.
  45500. */
  45501. function toSource(func) {
  45502. if (func != null) {
  45503. try {
  45504. return funcToString.call(func);
  45505. } catch (e) {}
  45506. try {
  45507. return func + '';
  45508. } catch (e) {}
  45509. }
  45510. return '';
  45511. }
  45512. /**
  45513. * Creates a duplicate-free version of an array, using
  45514. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  45515. * for equality comparisons, in which only the first occurrence of each
  45516. * element is kept.
  45517. *
  45518. * @static
  45519. * @memberOf _
  45520. * @since 0.1.0
  45521. * @category Array
  45522. * @param {Array} array The array to inspect.
  45523. * @returns {Array} Returns the new duplicate free array.
  45524. * @example
  45525. *
  45526. * _.uniq([2, 1, 2]);
  45527. * // => [2, 1]
  45528. */
  45529. function uniq(array) {
  45530. return array && array.length ? baseUniq(array) : [];
  45531. }
  45532. /**
  45533. * Performs a
  45534. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  45535. * comparison between two values to determine if they are equivalent.
  45536. *
  45537. * @static
  45538. * @memberOf _
  45539. * @since 4.0.0
  45540. * @category Lang
  45541. * @param {*} value The value to compare.
  45542. * @param {*} other The other value to compare.
  45543. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  45544. * @example
  45545. *
  45546. * var object = { 'a': 1 };
  45547. * var other = { 'a': 1 };
  45548. *
  45549. * _.eq(object, object);
  45550. * // => true
  45551. *
  45552. * _.eq(object, other);
  45553. * // => false
  45554. *
  45555. * _.eq('a', 'a');
  45556. * // => true
  45557. *
  45558. * _.eq('a', Object('a'));
  45559. * // => false
  45560. *
  45561. * _.eq(NaN, NaN);
  45562. * // => true
  45563. */
  45564. function eq(value, other) {
  45565. return value === other || value !== value && other !== other;
  45566. }
  45567. /**
  45568. * Checks if `value` is classified as a `Function` object.
  45569. *
  45570. * @static
  45571. * @memberOf _
  45572. * @since 0.1.0
  45573. * @category Lang
  45574. * @param {*} value The value to check.
  45575. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  45576. * @example
  45577. *
  45578. * _.isFunction(_);
  45579. * // => true
  45580. *
  45581. * _.isFunction(/abc/);
  45582. * // => false
  45583. */
  45584. function isFunction(value) {
  45585. // The use of `Object#toString` avoids issues with the `typeof` operator
  45586. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  45587. var tag = isObject(value) ? objectToString.call(value) : '';
  45588. return tag == funcTag || tag == genTag;
  45589. }
  45590. /**
  45591. * Checks if `value` is the
  45592. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  45593. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  45594. *
  45595. * @static
  45596. * @memberOf _
  45597. * @since 0.1.0
  45598. * @category Lang
  45599. * @param {*} value The value to check.
  45600. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  45601. * @example
  45602. *
  45603. * _.isObject({});
  45604. * // => true
  45605. *
  45606. * _.isObject([1, 2, 3]);
  45607. * // => true
  45608. *
  45609. * _.isObject(_.noop);
  45610. * // => true
  45611. *
  45612. * _.isObject(null);
  45613. * // => false
  45614. */
  45615. function isObject(value) {
  45616. var type = typeof value;
  45617. return !!value && (type == 'object' || type == 'function');
  45618. }
  45619. /**
  45620. * This method returns `undefined`.
  45621. *
  45622. * @static
  45623. * @memberOf _
  45624. * @since 2.3.0
  45625. * @category Util
  45626. * @example
  45627. *
  45628. * _.times(2, _.noop);
  45629. * // => [undefined, undefined]
  45630. */
  45631. function noop() {
  45632. // No operation performed.
  45633. }
  45634. module.exports = uniq;
  45635. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  45636. },{}],450:[function(require,module,exports){
  45637. 'use strict';
  45638. var inherits = require('inherits');
  45639. var HashBase = require('hash-base');
  45640. var Buffer = require('safe-buffer').Buffer;
  45641. var ARRAY16 = new Array(16);
  45642. function MD5() {
  45643. HashBase.call(this, 64);
  45644. // state
  45645. this._a = 0x67452301;
  45646. this._b = 0xefcdab89;
  45647. this._c = 0x98badcfe;
  45648. this._d = 0x10325476;
  45649. }
  45650. inherits(MD5, HashBase);
  45651. MD5.prototype._update = function () {
  45652. var M = ARRAY16;
  45653. for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4);
  45654. var a = this._a;
  45655. var b = this._b;
  45656. var c = this._c;
  45657. var d = this._d;
  45658. a = fnF(a, b, c, d, M[0], 0xd76aa478, 7);
  45659. d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12);
  45660. c = fnF(c, d, a, b, M[2], 0x242070db, 17);
  45661. b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22);
  45662. a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7);
  45663. d = fnF(d, a, b, c, M[5], 0x4787c62a, 12);
  45664. c = fnF(c, d, a, b, M[6], 0xa8304613, 17);
  45665. b = fnF(b, c, d, a, M[7], 0xfd469501, 22);
  45666. a = fnF(a, b, c, d, M[8], 0x698098d8, 7);
  45667. d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12);
  45668. c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17);
  45669. b = fnF(b, c, d, a, M[11], 0x895cd7be, 22);
  45670. a = fnF(a, b, c, d, M[12], 0x6b901122, 7);
  45671. d = fnF(d, a, b, c, M[13], 0xfd987193, 12);
  45672. c = fnF(c, d, a, b, M[14], 0xa679438e, 17);
  45673. b = fnF(b, c, d, a, M[15], 0x49b40821, 22);
  45674. a = fnG(a, b, c, d, M[1], 0xf61e2562, 5);
  45675. d = fnG(d, a, b, c, M[6], 0xc040b340, 9);
  45676. c = fnG(c, d, a, b, M[11], 0x265e5a51, 14);
  45677. b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20);
  45678. a = fnG(a, b, c, d, M[5], 0xd62f105d, 5);
  45679. d = fnG(d, a, b, c, M[10], 0x02441453, 9);
  45680. c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14);
  45681. b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20);
  45682. a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5);
  45683. d = fnG(d, a, b, c, M[14], 0xc33707d6, 9);
  45684. c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14);
  45685. b = fnG(b, c, d, a, M[8], 0x455a14ed, 20);
  45686. a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5);
  45687. d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9);
  45688. c = fnG(c, d, a, b, M[7], 0x676f02d9, 14);
  45689. b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20);
  45690. a = fnH(a, b, c, d, M[5], 0xfffa3942, 4);
  45691. d = fnH(d, a, b, c, M[8], 0x8771f681, 11);
  45692. c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16);
  45693. b = fnH(b, c, d, a, M[14], 0xfde5380c, 23);
  45694. a = fnH(a, b, c, d, M[1], 0xa4beea44, 4);
  45695. d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11);
  45696. c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16);
  45697. b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23);
  45698. a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4);
  45699. d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11);
  45700. c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16);
  45701. b = fnH(b, c, d, a, M[6], 0x04881d05, 23);
  45702. a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4);
  45703. d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11);
  45704. c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16);
  45705. b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23);
  45706. a = fnI(a, b, c, d, M[0], 0xf4292244, 6);
  45707. d = fnI(d, a, b, c, M[7], 0x432aff97, 10);
  45708. c = fnI(c, d, a, b, M[14], 0xab9423a7, 15);
  45709. b = fnI(b, c, d, a, M[5], 0xfc93a039, 21);
  45710. a = fnI(a, b, c, d, M[12], 0x655b59c3, 6);
  45711. d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10);
  45712. c = fnI(c, d, a, b, M[10], 0xffeff47d, 15);
  45713. b = fnI(b, c, d, a, M[1], 0x85845dd1, 21);
  45714. a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6);
  45715. d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10);
  45716. c = fnI(c, d, a, b, M[6], 0xa3014314, 15);
  45717. b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21);
  45718. a = fnI(a, b, c, d, M[4], 0xf7537e82, 6);
  45719. d = fnI(d, a, b, c, M[11], 0xbd3af235, 10);
  45720. c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15);
  45721. b = fnI(b, c, d, a, M[9], 0xeb86d391, 21);
  45722. this._a = this._a + a | 0;
  45723. this._b = this._b + b | 0;
  45724. this._c = this._c + c | 0;
  45725. this._d = this._d + d | 0;
  45726. };
  45727. MD5.prototype._digest = function () {
  45728. // create padding and handle blocks
  45729. this._block[this._blockOffset++] = 0x80;
  45730. if (this._blockOffset > 56) {
  45731. this._block.fill(0, this._blockOffset, 64);
  45732. this._update();
  45733. this._blockOffset = 0;
  45734. }
  45735. this._block.fill(0, this._blockOffset, 56);
  45736. this._block.writeUInt32LE(this._length[0], 56);
  45737. this._block.writeUInt32LE(this._length[1], 60);
  45738. this._update();
  45739. // produce result
  45740. var buffer = Buffer.allocUnsafe(16);
  45741. buffer.writeInt32LE(this._a, 0);
  45742. buffer.writeInt32LE(this._b, 4);
  45743. buffer.writeInt32LE(this._c, 8);
  45744. buffer.writeInt32LE(this._d, 12);
  45745. return buffer;
  45746. };
  45747. function rotl(x, n) {
  45748. return x << n | x >>> 32 - n;
  45749. }
  45750. function fnF(a, b, c, d, m, k, s) {
  45751. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0;
  45752. }
  45753. function fnG(a, b, c, d, m, k, s) {
  45754. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0;
  45755. }
  45756. function fnH(a, b, c, d, m, k, s) {
  45757. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0;
  45758. }
  45759. function fnI(a, b, c, d, m, k, s) {
  45760. return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0;
  45761. }
  45762. module.exports = MD5;
  45763. },{"hash-base":425,"inherits":440,"safe-buffer":494}],451:[function(require,module,exports){
  45764. "use strict";
  45765. var bn = require('bn.js');
  45766. var brorand = require('brorand');
  45767. function MillerRabin(rand) {
  45768. this.rand = rand || new brorand.Rand();
  45769. }
  45770. module.exports = MillerRabin;
  45771. MillerRabin.create = function create(rand) {
  45772. return new MillerRabin(rand);
  45773. };
  45774. MillerRabin.prototype._randbelow = function _randbelow(n) {
  45775. var len = n.bitLength();
  45776. var min_bytes = Math.ceil(len / 8);
  45777. // Generage random bytes until a number less than n is found.
  45778. // This ensures that 0..n-1 have an equal probability of being selected.
  45779. do var a = new bn(this.rand.generate(min_bytes)); while (a.cmp(n) >= 0);
  45780. return a;
  45781. };
  45782. MillerRabin.prototype._randrange = function _randrange(start, stop) {
  45783. // Generate a random number greater than or equal to start and less than stop.
  45784. var size = stop.sub(start);
  45785. return start.add(this._randbelow(size));
  45786. };
  45787. MillerRabin.prototype.test = function test(n, k, cb) {
  45788. var len = n.bitLength();
  45789. var red = bn.mont(n);
  45790. var rone = new bn(1).toRed(red);
  45791. if (!k) k = Math.max(1, len / 48 | 0);
  45792. // Find d and s, (n - 1) = (2 ^ s) * d;
  45793. var n1 = n.subn(1);
  45794. for (var s = 0; !n1.testn(s); s++) {}
  45795. var d = n.shrn(s);
  45796. var rn1 = n1.toRed(red);
  45797. var prime = true;
  45798. for (; k > 0; k--) {
  45799. var a = this._randrange(new bn(2), n1);
  45800. if (cb) cb(a);
  45801. var x = a.toRed(red).redPow(d);
  45802. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  45803. for (var i = 1; i < s; i++) {
  45804. x = x.redSqr();
  45805. if (x.cmp(rone) === 0) return false;
  45806. if (x.cmp(rn1) === 0) break;
  45807. }
  45808. if (i === s) return false;
  45809. }
  45810. return prime;
  45811. };
  45812. MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
  45813. var len = n.bitLength();
  45814. var red = bn.mont(n);
  45815. var rone = new bn(1).toRed(red);
  45816. if (!k) k = Math.max(1, len / 48 | 0);
  45817. // Find d and s, (n - 1) = (2 ^ s) * d;
  45818. var n1 = n.subn(1);
  45819. for (var s = 0; !n1.testn(s); s++) {}
  45820. var d = n.shrn(s);
  45821. var rn1 = n1.toRed(red);
  45822. for (; k > 0; k--) {
  45823. var a = this._randrange(new bn(2), n1);
  45824. var g = n.gcd(a);
  45825. if (g.cmpn(1) !== 0) return g;
  45826. var x = a.toRed(red).redPow(d);
  45827. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  45828. for (var i = 1; i < s; i++) {
  45829. x = x.redSqr();
  45830. if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n);
  45831. if (x.cmp(rn1) === 0) break;
  45832. }
  45833. if (i === s) {
  45834. x = x.redSqr();
  45835. return x.fromRed().subn(1).gcd(n);
  45836. }
  45837. }
  45838. return false;
  45839. };
  45840. },{"bn.js":452,"brorand":187}],452:[function(require,module,exports){
  45841. arguments[4][184][0].apply(exports,arguments)
  45842. },{"buffer":188,"dup":184}],453:[function(require,module,exports){
  45843. "use strict";
  45844. module.exports = assert;
  45845. function assert(val, msg) {
  45846. if (!val) throw new Error(msg || 'Assertion failed');
  45847. }
  45848. assert.equal = function assertEqual(l, r, msg) {
  45849. if (l != r) throw new Error(msg || 'Assertion failed: ' + l + ' != ' + r);
  45850. };
  45851. },{}],454:[function(require,module,exports){
  45852. 'use strict';
  45853. var utils = exports;
  45854. function toArray(msg, enc) {
  45855. if (Array.isArray(msg)) return msg.slice();
  45856. if (!msg) return [];
  45857. var res = [];
  45858. if (typeof msg !== 'string') {
  45859. for (var i = 0; i < msg.length; i++) res[i] = msg[i] | 0;
  45860. return res;
  45861. }
  45862. if (enc === 'hex') {
  45863. msg = msg.replace(/[^a-z0-9]+/ig, '');
  45864. if (msg.length % 2 !== 0) msg = '0' + msg;
  45865. for (var i = 0; i < msg.length; i += 2) res.push(parseInt(msg[i] + msg[i + 1], 16));
  45866. } else {
  45867. for (var i = 0; i < msg.length; i++) {
  45868. var c = msg.charCodeAt(i);
  45869. var hi = c >> 8;
  45870. var lo = c & 0xff;
  45871. if (hi) res.push(hi, lo);else res.push(lo);
  45872. }
  45873. }
  45874. return res;
  45875. }
  45876. utils.toArray = toArray;
  45877. function zero2(word) {
  45878. if (word.length === 1) return '0' + word;else return word;
  45879. }
  45880. utils.zero2 = zero2;
  45881. function toHex(msg) {
  45882. var res = '';
  45883. for (var i = 0; i < msg.length; i++) res += zero2(msg[i].toString(16));
  45884. return res;
  45885. }
  45886. utils.toHex = toHex;
  45887. utils.encode = function encode(arr, enc) {
  45888. if (enc === 'hex') return toHex(arr);else return arr;
  45889. };
  45890. },{}],455:[function(require,module,exports){
  45891. module.exports={"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
  45892. "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
  45893. "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
  45894. "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
  45895. "2.16.840.1.101.3.4.1.21": "aes-192-ecb",
  45896. "2.16.840.1.101.3.4.1.22": "aes-192-cbc",
  45897. "2.16.840.1.101.3.4.1.23": "aes-192-ofb",
  45898. "2.16.840.1.101.3.4.1.24": "aes-192-cfb",
  45899. "2.16.840.1.101.3.4.1.41": "aes-256-ecb",
  45900. "2.16.840.1.101.3.4.1.42": "aes-256-cbc",
  45901. "2.16.840.1.101.3.4.1.43": "aes-256-ofb",
  45902. "2.16.840.1.101.3.4.1.44": "aes-256-cfb"
  45903. }
  45904. },{}],456:[function(require,module,exports){
  45905. // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  45906. // Fedor, you are amazing.
  45907. 'use strict';
  45908. var asn1 = require('asn1.js');
  45909. exports.certificate = require('./certificate');
  45910. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  45911. this.seq().obj(this.key('version').int(), this.key('modulus').int(), this.key('publicExponent').int(), this.key('privateExponent').int(), this.key('prime1').int(), this.key('prime2').int(), this.key('exponent1').int(), this.key('exponent2').int(), this.key('coefficient').int());
  45912. });
  45913. exports.RSAPrivateKey = RSAPrivateKey;
  45914. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  45915. this.seq().obj(this.key('modulus').int(), this.key('publicExponent').int());
  45916. });
  45917. exports.RSAPublicKey = RSAPublicKey;
  45918. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  45919. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  45920. });
  45921. exports.PublicKey = PublicKey;
  45922. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  45923. this.seq().obj(this.key('algorithm').objid(), this.key('none').null_().optional(), this.key('curve').objid().optional(), this.key('params').seq().obj(this.key('p').int(), this.key('q').int(), this.key('g').int()).optional());
  45924. });
  45925. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  45926. this.seq().obj(this.key('version').int(), this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPrivateKey').octstr());
  45927. });
  45928. exports.PrivateKey = PrivateKeyInfo;
  45929. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  45930. this.seq().obj(this.key('algorithm').seq().obj(this.key('id').objid(), this.key('decrypt').seq().obj(this.key('kde').seq().obj(this.key('id').objid(), this.key('kdeparams').seq().obj(this.key('salt').octstr(), this.key('iters').int())), this.key('cipher').seq().obj(this.key('algo').objid(), this.key('iv').octstr()))), this.key('subjectPrivateKey').octstr());
  45931. });
  45932. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo;
  45933. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  45934. this.seq().obj(this.key('version').int(), this.key('p').int(), this.key('q').int(), this.key('g').int(), this.key('pub_key').int(), this.key('priv_key').int());
  45935. });
  45936. exports.DSAPrivateKey = DSAPrivateKey;
  45937. exports.DSAparam = asn1.define('DSAparam', function () {
  45938. this.int();
  45939. });
  45940. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  45941. this.seq().obj(this.key('version').int(), this.key('privateKey').octstr(), this.key('parameters').optional().explicit(0).use(ECParameters), this.key('publicKey').optional().explicit(1).bitstr());
  45942. });
  45943. exports.ECPrivateKey = ECPrivateKey;
  45944. var ECParameters = asn1.define('ECParameters', function () {
  45945. this.choice({
  45946. namedCurve: this.objid()
  45947. });
  45948. });
  45949. exports.signature = asn1.define('signature', function () {
  45950. this.seq().obj(this.key('r').int(), this.key('s').int());
  45951. });
  45952. },{"./certificate":457,"asn1.js":170}],457:[function(require,module,exports){
  45953. // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
  45954. // thanks to @Rantanen
  45955. 'use strict';
  45956. var asn = require('asn1.js');
  45957. var Time = asn.define('Time', function () {
  45958. this.choice({
  45959. utcTime: this.utctime(),
  45960. generalTime: this.gentime()
  45961. });
  45962. });
  45963. var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
  45964. this.seq().obj(this.key('type').objid(), this.key('value').any());
  45965. });
  45966. var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  45967. this.seq().obj(this.key('algorithm').objid(), this.key('parameters').optional(), this.key('curve').objid().optional());
  45968. });
  45969. var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
  45970. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  45971. });
  45972. var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
  45973. this.setof(AttributeTypeValue);
  45974. });
  45975. var RDNSequence = asn.define('RDNSequence', function () {
  45976. this.seqof(RelativeDistinguishedName);
  45977. });
  45978. var Name = asn.define('Name', function () {
  45979. this.choice({
  45980. rdnSequence: this.use(RDNSequence)
  45981. });
  45982. });
  45983. var Validity = asn.define('Validity', function () {
  45984. this.seq().obj(this.key('notBefore').use(Time), this.key('notAfter').use(Time));
  45985. });
  45986. var Extension = asn.define('Extension', function () {
  45987. this.seq().obj(this.key('extnID').objid(), this.key('critical').bool().def(false), this.key('extnValue').octstr());
  45988. });
  45989. var TBSCertificate = asn.define('TBSCertificate', function () {
  45990. this.seq().obj(this.key('version').explicit(0).int().optional(), this.key('serialNumber').int(), this.key('signature').use(AlgorithmIdentifier), this.key('issuer').use(Name), this.key('validity').use(Validity), this.key('subject').use(Name), this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo), this.key('issuerUniqueID').implicit(1).bitstr().optional(), this.key('subjectUniqueID').implicit(2).bitstr().optional(), this.key('extensions').explicit(3).seqof(Extension).optional());
  45991. });
  45992. var X509Certificate = asn.define('X509Certificate', function () {
  45993. this.seq().obj(this.key('tbsCertificate').use(TBSCertificate), this.key('signatureAlgorithm').use(AlgorithmIdentifier), this.key('signatureValue').bitstr());
  45994. });
  45995. module.exports = X509Certificate;
  45996. },{"asn1.js":170}],458:[function(require,module,exports){
  45997. "use strict";
  45998. // adapted from https://github.com/apatil/pemstrip
  45999. var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m;
  46000. var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m;
  46001. var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m;
  46002. var evp = require('evp_bytestokey');
  46003. var ciphers = require('browserify-aes');
  46004. var Buffer = require('safe-buffer').Buffer;
  46005. module.exports = function (okey, password) {
  46006. var key = okey.toString();
  46007. var match = key.match(findProc);
  46008. var decrypted;
  46009. if (!match) {
  46010. var match2 = key.match(fullRegex);
  46011. decrypted = Buffer.from(match2[2].replace(/[\r\n]/g, ''), 'base64');
  46012. } else {
  46013. var suite = 'aes' + match[1];
  46014. var iv = Buffer.from(match[2], 'hex');
  46015. var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ''), 'base64');
  46016. var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key;
  46017. var out = [];
  46018. var cipher = ciphers.createDecipheriv(suite, cipherKey, iv);
  46019. out.push(cipher.update(cipherText));
  46020. out.push(cipher.final());
  46021. decrypted = Buffer.concat(out);
  46022. }
  46023. var tag = key.match(startRegex)[1];
  46024. return {
  46025. tag: tag,
  46026. data: decrypted
  46027. };
  46028. };
  46029. },{"browserify-aes":191,"evp_bytestokey":423,"safe-buffer":494}],459:[function(require,module,exports){
  46030. "use strict";
  46031. var asn1 = require('./asn1');
  46032. var aesid = require('./aesid.json');
  46033. var fixProc = require('./fixProc');
  46034. var ciphers = require('browserify-aes');
  46035. var compat = require('pbkdf2');
  46036. var Buffer = require('safe-buffer').Buffer;
  46037. module.exports = parseKeys;
  46038. function parseKeys(buffer) {
  46039. var password;
  46040. if (typeof buffer === 'object' && !Buffer.isBuffer(buffer)) {
  46041. password = buffer.passphrase;
  46042. buffer = buffer.key;
  46043. }
  46044. if (typeof buffer === 'string') {
  46045. buffer = Buffer.from(buffer);
  46046. }
  46047. var stripped = fixProc(buffer, password);
  46048. var type = stripped.tag;
  46049. var data = stripped.data;
  46050. var subtype, ndata;
  46051. switch (type) {
  46052. case 'CERTIFICATE':
  46053. ndata = asn1.certificate.decode(data, 'der').tbsCertificate.subjectPublicKeyInfo;
  46054. // falls through
  46055. case 'PUBLIC KEY':
  46056. if (!ndata) {
  46057. ndata = asn1.PublicKey.decode(data, 'der');
  46058. }
  46059. subtype = ndata.algorithm.algorithm.join('.');
  46060. switch (subtype) {
  46061. case '1.2.840.113549.1.1.1':
  46062. return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der');
  46063. case '1.2.840.10045.2.1':
  46064. ndata.subjectPrivateKey = ndata.subjectPublicKey;
  46065. return {
  46066. type: 'ec',
  46067. data: ndata
  46068. };
  46069. case '1.2.840.10040.4.1':
  46070. ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der');
  46071. return {
  46072. type: 'dsa',
  46073. data: ndata.algorithm.params
  46074. };
  46075. default:
  46076. throw new Error('unknown key id ' + subtype);
  46077. }
  46078. // throw new Error('unknown key type ' + type)
  46079. case 'ENCRYPTED PRIVATE KEY':
  46080. data = asn1.EncryptedPrivateKey.decode(data, 'der');
  46081. data = decrypt(data, password);
  46082. // falls through
  46083. case 'PRIVATE KEY':
  46084. ndata = asn1.PrivateKey.decode(data, 'der');
  46085. subtype = ndata.algorithm.algorithm.join('.');
  46086. switch (subtype) {
  46087. case '1.2.840.113549.1.1.1':
  46088. return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der');
  46089. case '1.2.840.10045.2.1':
  46090. return {
  46091. curve: ndata.algorithm.curve,
  46092. privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
  46093. };
  46094. case '1.2.840.10040.4.1':
  46095. ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der');
  46096. return {
  46097. type: 'dsa',
  46098. params: ndata.algorithm.params
  46099. };
  46100. default:
  46101. throw new Error('unknown key id ' + subtype);
  46102. }
  46103. // throw new Error('unknown key type ' + type)
  46104. case 'RSA PUBLIC KEY':
  46105. return asn1.RSAPublicKey.decode(data, 'der');
  46106. case 'RSA PRIVATE KEY':
  46107. return asn1.RSAPrivateKey.decode(data, 'der');
  46108. case 'DSA PRIVATE KEY':
  46109. return {
  46110. type: 'dsa',
  46111. params: asn1.DSAPrivateKey.decode(data, 'der')
  46112. };
  46113. case 'EC PRIVATE KEY':
  46114. data = asn1.ECPrivateKey.decode(data, 'der');
  46115. return {
  46116. curve: data.parameters.value,
  46117. privateKey: data.privateKey
  46118. };
  46119. default:
  46120. throw new Error('unknown key type ' + type);
  46121. }
  46122. }
  46123. parseKeys.signature = asn1.signature;
  46124. function decrypt(data, password) {
  46125. var salt = data.algorithm.decrypt.kde.kdeparams.salt;
  46126. var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10);
  46127. var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')];
  46128. var iv = data.algorithm.decrypt.cipher.iv;
  46129. var cipherText = data.subjectPrivateKey;
  46130. var keylen = parseInt(algo.split('-')[1], 10) / 8;
  46131. var key = compat.pbkdf2Sync(password, salt, iters, keylen, 'sha1');
  46132. var cipher = ciphers.createDecipheriv(algo, key, iv);
  46133. var out = [];
  46134. out.push(cipher.update(cipherText));
  46135. out.push(cipher.final());
  46136. return Buffer.concat(out);
  46137. }
  46138. },{"./aesid.json":455,"./asn1":456,"./fixProc":458,"browserify-aes":191,"pbkdf2":460,"safe-buffer":494}],460:[function(require,module,exports){
  46139. "use strict";
  46140. exports.pbkdf2 = require('./lib/async');
  46141. exports.pbkdf2Sync = require('./lib/sync');
  46142. },{"./lib/async":461,"./lib/sync":464}],461:[function(require,module,exports){
  46143. (function (global){(function (){
  46144. "use strict";
  46145. var Buffer = require('safe-buffer').Buffer;
  46146. var checkParameters = require('./precondition');
  46147. var defaultEncoding = require('./default-encoding');
  46148. var sync = require('./sync');
  46149. var toBuffer = require('./to-buffer');
  46150. var ZERO_BUF;
  46151. var subtle = global.crypto && global.crypto.subtle;
  46152. var toBrowser = {
  46153. sha: 'SHA-1',
  46154. 'sha-1': 'SHA-1',
  46155. sha1: 'SHA-1',
  46156. sha256: 'SHA-256',
  46157. 'sha-256': 'SHA-256',
  46158. sha384: 'SHA-384',
  46159. 'sha-384': 'SHA-384',
  46160. 'sha-512': 'SHA-512',
  46161. sha512: 'SHA-512'
  46162. };
  46163. var checks = [];
  46164. function checkNative(algo) {
  46165. if (global.process && !global.process.browser) {
  46166. return Promise.resolve(false);
  46167. }
  46168. if (!subtle || !subtle.importKey || !subtle.deriveBits) {
  46169. return Promise.resolve(false);
  46170. }
  46171. if (checks[algo] !== undefined) {
  46172. return checks[algo];
  46173. }
  46174. ZERO_BUF = ZERO_BUF || Buffer.alloc(8);
  46175. var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () {
  46176. return true;
  46177. }).catch(function () {
  46178. return false;
  46179. });
  46180. checks[algo] = prom;
  46181. return prom;
  46182. }
  46183. var nextTick;
  46184. function getNextTick() {
  46185. if (nextTick) {
  46186. return nextTick;
  46187. }
  46188. if (global.process && global.process.nextTick) {
  46189. nextTick = global.process.nextTick;
  46190. } else if (global.queueMicrotask) {
  46191. nextTick = global.queueMicrotask;
  46192. } else if (global.setImmediate) {
  46193. nextTick = global.setImmediate;
  46194. } else {
  46195. nextTick = global.setTimeout;
  46196. }
  46197. return nextTick;
  46198. }
  46199. function browserPbkdf2(password, salt, iterations, length, algo) {
  46200. return subtle.importKey('raw', password, {
  46201. name: 'PBKDF2'
  46202. }, false, ['deriveBits']).then(function (key) {
  46203. return subtle.deriveBits({
  46204. name: 'PBKDF2',
  46205. salt: salt,
  46206. iterations: iterations,
  46207. hash: {
  46208. name: algo
  46209. }
  46210. }, key, length << 3);
  46211. }).then(function (res) {
  46212. return Buffer.from(res);
  46213. });
  46214. }
  46215. function resolvePromise(promise, callback) {
  46216. promise.then(function (out) {
  46217. getNextTick()(function () {
  46218. callback(null, out);
  46219. });
  46220. }, function (e) {
  46221. getNextTick()(function () {
  46222. callback(e);
  46223. });
  46224. });
  46225. }
  46226. module.exports = function (password, salt, iterations, keylen, digest, callback) {
  46227. if (typeof digest === 'function') {
  46228. callback = digest;
  46229. digest = undefined;
  46230. }
  46231. digest = digest || 'sha1';
  46232. var algo = toBrowser[digest.toLowerCase()];
  46233. if (!algo || typeof global.Promise !== 'function') {
  46234. getNextTick()(function () {
  46235. var out;
  46236. try {
  46237. out = sync(password, salt, iterations, keylen, digest);
  46238. } catch (e) {
  46239. return callback(e);
  46240. }
  46241. callback(null, out);
  46242. });
  46243. return;
  46244. }
  46245. checkParameters(iterations, keylen);
  46246. password = toBuffer(password, defaultEncoding, 'Password');
  46247. salt = toBuffer(salt, defaultEncoding, 'Salt');
  46248. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2');
  46249. resolvePromise(checkNative(algo).then(function (resp) {
  46250. if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo);
  46251. return sync(password, salt, iterations, keylen, digest);
  46252. }), callback);
  46253. };
  46254. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46255. },{"./default-encoding":462,"./precondition":463,"./sync":464,"./to-buffer":465,"safe-buffer":494}],462:[function(require,module,exports){
  46256. (function (process,global){(function (){
  46257. "use strict";
  46258. var defaultEncoding;
  46259. /* istanbul ignore next */
  46260. if (global.process && global.process.browser) {
  46261. defaultEncoding = 'utf-8';
  46262. } else if (global.process && global.process.version) {
  46263. var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10);
  46264. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary';
  46265. } else {
  46266. defaultEncoding = 'utf-8';
  46267. }
  46268. module.exports = defaultEncoding;
  46269. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46270. },{"_process":467}],463:[function(require,module,exports){
  46271. "use strict";
  46272. var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs
  46273. module.exports = function (iterations, keylen) {
  46274. if (typeof iterations !== 'number') {
  46275. throw new TypeError('Iterations not a number');
  46276. }
  46277. if (iterations < 0) {
  46278. throw new TypeError('Bad iterations');
  46279. }
  46280. if (typeof keylen !== 'number') {
  46281. throw new TypeError('Key length not a number');
  46282. }
  46283. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) {
  46284. /* eslint no-self-compare: 0 */
  46285. throw new TypeError('Bad key length');
  46286. }
  46287. };
  46288. },{}],464:[function(require,module,exports){
  46289. "use strict";
  46290. var md5 = require('create-hash/md5');
  46291. var RIPEMD160 = require('ripemd160');
  46292. var sha = require('sha.js');
  46293. var Buffer = require('safe-buffer').Buffer;
  46294. var checkParameters = require('./precondition');
  46295. var defaultEncoding = require('./default-encoding');
  46296. var toBuffer = require('./to-buffer');
  46297. var ZEROS = Buffer.alloc(128);
  46298. var sizes = {
  46299. md5: 16,
  46300. sha1: 20,
  46301. sha224: 28,
  46302. sha256: 32,
  46303. sha384: 48,
  46304. sha512: 64,
  46305. rmd160: 20,
  46306. ripemd160: 20
  46307. };
  46308. function Hmac(alg, key, saltLen) {
  46309. var hash = getDigest(alg);
  46310. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  46311. if (key.length > blocksize) {
  46312. key = hash(key);
  46313. } else if (key.length < blocksize) {
  46314. key = Buffer.concat([key, ZEROS], blocksize);
  46315. }
  46316. var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  46317. var opad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  46318. for (var i = 0; i < blocksize; i++) {
  46319. ipad[i] = key[i] ^ 0x36;
  46320. opad[i] = key[i] ^ 0x5C;
  46321. }
  46322. var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4);
  46323. ipad.copy(ipad1, 0, 0, blocksize);
  46324. this.ipad1 = ipad1;
  46325. this.ipad2 = ipad;
  46326. this.opad = opad;
  46327. this.alg = alg;
  46328. this.blocksize = blocksize;
  46329. this.hash = hash;
  46330. this.size = sizes[alg];
  46331. }
  46332. Hmac.prototype.run = function (data, ipad) {
  46333. data.copy(ipad, this.blocksize);
  46334. var h = this.hash(ipad);
  46335. h.copy(this.opad, this.blocksize);
  46336. return this.hash(this.opad);
  46337. };
  46338. function getDigest(alg) {
  46339. function shaFunc(data) {
  46340. return sha(alg).update(data).digest();
  46341. }
  46342. function rmd160Func(data) {
  46343. return new RIPEMD160().update(data).digest();
  46344. }
  46345. if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func;
  46346. if (alg === 'md5') return md5;
  46347. return shaFunc;
  46348. }
  46349. function pbkdf2(password, salt, iterations, keylen, digest) {
  46350. checkParameters(iterations, keylen);
  46351. password = toBuffer(password, defaultEncoding, 'Password');
  46352. salt = toBuffer(salt, defaultEncoding, 'Salt');
  46353. digest = digest || 'sha1';
  46354. var hmac = new Hmac(digest, password, salt.length);
  46355. var DK = Buffer.allocUnsafe(keylen);
  46356. var block1 = Buffer.allocUnsafe(salt.length + 4);
  46357. salt.copy(block1, 0, 0, salt.length);
  46358. var destPos = 0;
  46359. var hLen = sizes[digest];
  46360. var l = Math.ceil(keylen / hLen);
  46361. for (var i = 1; i <= l; i++) {
  46362. block1.writeUInt32BE(i, salt.length);
  46363. var T = hmac.run(block1, hmac.ipad1);
  46364. var U = T;
  46365. for (var j = 1; j < iterations; j++) {
  46366. U = hmac.run(U, hmac.ipad2);
  46367. for (var k = 0; k < hLen; k++) T[k] ^= U[k];
  46368. }
  46369. T.copy(DK, destPos);
  46370. destPos += hLen;
  46371. }
  46372. return DK;
  46373. }
  46374. module.exports = pbkdf2;
  46375. },{"./default-encoding":462,"./precondition":463,"./to-buffer":465,"create-hash/md5":387,"ripemd160":493,"safe-buffer":494,"sha.js":498}],465:[function(require,module,exports){
  46376. "use strict";
  46377. var Buffer = require('safe-buffer').Buffer;
  46378. module.exports = function (thing, encoding, name) {
  46379. if (Buffer.isBuffer(thing)) {
  46380. return thing;
  46381. } else if (typeof thing === 'string') {
  46382. return Buffer.from(thing, encoding);
  46383. } else if (ArrayBuffer.isView(thing)) {
  46384. return Buffer.from(thing.buffer);
  46385. } else {
  46386. throw new TypeError(name + ' must be a string, a Buffer, a typed array or a DataView');
  46387. }
  46388. };
  46389. },{"safe-buffer":494}],466:[function(require,module,exports){
  46390. (function (process){(function (){
  46391. 'use strict';
  46392. if (typeof process === 'undefined' || !process.version || process.version.indexOf('v0.') === 0 || process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
  46393. module.exports = {
  46394. nextTick: nextTick
  46395. };
  46396. } else {
  46397. module.exports = process;
  46398. }
  46399. function nextTick(fn, arg1, arg2, arg3) {
  46400. if (typeof fn !== 'function') {
  46401. throw new TypeError('"callback" argument must be a function');
  46402. }
  46403. var len = arguments.length;
  46404. var args, i;
  46405. switch (len) {
  46406. case 0:
  46407. case 1:
  46408. return process.nextTick(fn);
  46409. case 2:
  46410. return process.nextTick(function afterTickOne() {
  46411. fn.call(null, arg1);
  46412. });
  46413. case 3:
  46414. return process.nextTick(function afterTickTwo() {
  46415. fn.call(null, arg1, arg2);
  46416. });
  46417. case 4:
  46418. return process.nextTick(function afterTickThree() {
  46419. fn.call(null, arg1, arg2, arg3);
  46420. });
  46421. default:
  46422. args = new Array(len - 1);
  46423. i = 0;
  46424. while (i < args.length) {
  46425. args[i++] = arguments[i];
  46426. }
  46427. return process.nextTick(function afterTick() {
  46428. fn.apply(null, args);
  46429. });
  46430. }
  46431. }
  46432. }).call(this)}).call(this,require('_process'))
  46433. },{"_process":467}],467:[function(require,module,exports){
  46434. "use strict";
  46435. // shim for using process in browser
  46436. var process = module.exports = {};
  46437. // cached from whatever global is present so that test runners that stub it
  46438. // don't break things. But we need to wrap it in a try catch in case it is
  46439. // wrapped in strict mode code which doesn't define any globals. It's inside a
  46440. // function because try/catches deoptimize in certain engines.
  46441. var cachedSetTimeout;
  46442. var cachedClearTimeout;
  46443. function defaultSetTimout() {
  46444. throw new Error('setTimeout has not been defined');
  46445. }
  46446. function defaultClearTimeout() {
  46447. throw new Error('clearTimeout has not been defined');
  46448. }
  46449. (function () {
  46450. try {
  46451. if (typeof setTimeout === 'function') {
  46452. cachedSetTimeout = setTimeout;
  46453. } else {
  46454. cachedSetTimeout = defaultSetTimout;
  46455. }
  46456. } catch (e) {
  46457. cachedSetTimeout = defaultSetTimout;
  46458. }
  46459. try {
  46460. if (typeof clearTimeout === 'function') {
  46461. cachedClearTimeout = clearTimeout;
  46462. } else {
  46463. cachedClearTimeout = defaultClearTimeout;
  46464. }
  46465. } catch (e) {
  46466. cachedClearTimeout = defaultClearTimeout;
  46467. }
  46468. })();
  46469. function runTimeout(fun) {
  46470. if (cachedSetTimeout === setTimeout) {
  46471. //normal enviroments in sane situations
  46472. return setTimeout(fun, 0);
  46473. }
  46474. // if setTimeout wasn't available but was latter defined
  46475. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  46476. cachedSetTimeout = setTimeout;
  46477. return setTimeout(fun, 0);
  46478. }
  46479. try {
  46480. // when when somebody has screwed with setTimeout but no I.E. maddness
  46481. return cachedSetTimeout(fun, 0);
  46482. } catch (e) {
  46483. try {
  46484. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  46485. return cachedSetTimeout.call(null, fun, 0);
  46486. } catch (e) {
  46487. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  46488. return cachedSetTimeout.call(this, fun, 0);
  46489. }
  46490. }
  46491. }
  46492. function runClearTimeout(marker) {
  46493. if (cachedClearTimeout === clearTimeout) {
  46494. //normal enviroments in sane situations
  46495. return clearTimeout(marker);
  46496. }
  46497. // if clearTimeout wasn't available but was latter defined
  46498. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  46499. cachedClearTimeout = clearTimeout;
  46500. return clearTimeout(marker);
  46501. }
  46502. try {
  46503. // when when somebody has screwed with setTimeout but no I.E. maddness
  46504. return cachedClearTimeout(marker);
  46505. } catch (e) {
  46506. try {
  46507. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  46508. return cachedClearTimeout.call(null, marker);
  46509. } catch (e) {
  46510. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  46511. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  46512. return cachedClearTimeout.call(this, marker);
  46513. }
  46514. }
  46515. }
  46516. var queue = [];
  46517. var draining = false;
  46518. var currentQueue;
  46519. var queueIndex = -1;
  46520. function cleanUpNextTick() {
  46521. if (!draining || !currentQueue) {
  46522. return;
  46523. }
  46524. draining = false;
  46525. if (currentQueue.length) {
  46526. queue = currentQueue.concat(queue);
  46527. } else {
  46528. queueIndex = -1;
  46529. }
  46530. if (queue.length) {
  46531. drainQueue();
  46532. }
  46533. }
  46534. function drainQueue() {
  46535. if (draining) {
  46536. return;
  46537. }
  46538. var timeout = runTimeout(cleanUpNextTick);
  46539. draining = true;
  46540. var len = queue.length;
  46541. while (len) {
  46542. currentQueue = queue;
  46543. queue = [];
  46544. while (++queueIndex < len) {
  46545. if (currentQueue) {
  46546. currentQueue[queueIndex].run();
  46547. }
  46548. }
  46549. queueIndex = -1;
  46550. len = queue.length;
  46551. }
  46552. currentQueue = null;
  46553. draining = false;
  46554. runClearTimeout(timeout);
  46555. }
  46556. process.nextTick = function (fun) {
  46557. var args = new Array(arguments.length - 1);
  46558. if (arguments.length > 1) {
  46559. for (var i = 1; i < arguments.length; i++) {
  46560. args[i - 1] = arguments[i];
  46561. }
  46562. }
  46563. queue.push(new Item(fun, args));
  46564. if (queue.length === 1 && !draining) {
  46565. runTimeout(drainQueue);
  46566. }
  46567. };
  46568. // v8 likes predictible objects
  46569. function Item(fun, array) {
  46570. this.fun = fun;
  46571. this.array = array;
  46572. }
  46573. Item.prototype.run = function () {
  46574. this.fun.apply(null, this.array);
  46575. };
  46576. process.title = 'browser';
  46577. process.browser = true;
  46578. process.env = {};
  46579. process.argv = [];
  46580. process.version = ''; // empty string to avoid regexp issues
  46581. process.versions = {};
  46582. function noop() {}
  46583. process.on = noop;
  46584. process.addListener = noop;
  46585. process.once = noop;
  46586. process.off = noop;
  46587. process.removeListener = noop;
  46588. process.removeAllListeners = noop;
  46589. process.emit = noop;
  46590. process.prependListener = noop;
  46591. process.prependOnceListener = noop;
  46592. process.listeners = function (name) {
  46593. return [];
  46594. };
  46595. process.binding = function (name) {
  46596. throw new Error('process.binding is not supported');
  46597. };
  46598. process.cwd = function () {
  46599. return '/';
  46600. };
  46601. process.chdir = function (dir) {
  46602. throw new Error('process.chdir is not supported');
  46603. };
  46604. process.umask = function () {
  46605. return 0;
  46606. };
  46607. },{}],468:[function(require,module,exports){
  46608. "use strict";
  46609. exports.publicEncrypt = require('./publicEncrypt');
  46610. exports.privateDecrypt = require('./privateDecrypt');
  46611. exports.privateEncrypt = function privateEncrypt(key, buf) {
  46612. return exports.publicEncrypt(key, buf, true);
  46613. };
  46614. exports.publicDecrypt = function publicDecrypt(key, buf) {
  46615. return exports.privateDecrypt(key, buf, true);
  46616. };
  46617. },{"./privateDecrypt":471,"./publicEncrypt":472}],469:[function(require,module,exports){
  46618. "use strict";
  46619. var createHash = require('create-hash');
  46620. var Buffer = require('safe-buffer').Buffer;
  46621. module.exports = function (seed, len) {
  46622. var t = Buffer.alloc(0);
  46623. var i = 0;
  46624. var c;
  46625. while (t.length < len) {
  46626. c = i2ops(i++);
  46627. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  46628. }
  46629. return t.slice(0, len);
  46630. };
  46631. function i2ops(c) {
  46632. var out = Buffer.allocUnsafe(4);
  46633. out.writeUInt32BE(c, 0);
  46634. return out;
  46635. }
  46636. },{"create-hash":386,"safe-buffer":494}],470:[function(require,module,exports){
  46637. arguments[4][184][0].apply(exports,arguments)
  46638. },{"buffer":188,"dup":184}],471:[function(require,module,exports){
  46639. "use strict";
  46640. var parseKeys = require('parse-asn1');
  46641. var mgf = require('./mgf');
  46642. var xor = require('./xor');
  46643. var BN = require('bn.js');
  46644. var crt = require('browserify-rsa');
  46645. var createHash = require('create-hash');
  46646. var withPublic = require('./withPublic');
  46647. var Buffer = require('safe-buffer').Buffer;
  46648. module.exports = function privateDecrypt(privateKey, enc, reverse) {
  46649. var padding;
  46650. if (privateKey.padding) {
  46651. padding = privateKey.padding;
  46652. } else if (reverse) {
  46653. padding = 1;
  46654. } else {
  46655. padding = 4;
  46656. }
  46657. var key = parseKeys(privateKey);
  46658. var k = key.modulus.byteLength();
  46659. if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) {
  46660. throw new Error('decryption error');
  46661. }
  46662. var msg;
  46663. if (reverse) {
  46664. msg = withPublic(new BN(enc), key);
  46665. } else {
  46666. msg = crt(enc, key);
  46667. }
  46668. var zBuffer = Buffer.alloc(k - msg.length);
  46669. msg = Buffer.concat([zBuffer, msg], k);
  46670. if (padding === 4) {
  46671. return oaep(key, msg);
  46672. } else if (padding === 1) {
  46673. return pkcs1(key, msg, reverse);
  46674. } else if (padding === 3) {
  46675. return msg;
  46676. } else {
  46677. throw new Error('unknown padding');
  46678. }
  46679. };
  46680. function oaep(key, msg) {
  46681. var k = key.modulus.byteLength();
  46682. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  46683. var hLen = iHash.length;
  46684. if (msg[0] !== 0) {
  46685. throw new Error('decryption error');
  46686. }
  46687. var maskedSeed = msg.slice(1, hLen + 1);
  46688. var maskedDb = msg.slice(hLen + 1);
  46689. var seed = xor(maskedSeed, mgf(maskedDb, hLen));
  46690. var db = xor(maskedDb, mgf(seed, k - hLen - 1));
  46691. if (compare(iHash, db.slice(0, hLen))) {
  46692. throw new Error('decryption error');
  46693. }
  46694. var i = hLen;
  46695. while (db[i] === 0) {
  46696. i++;
  46697. }
  46698. if (db[i++] !== 1) {
  46699. throw new Error('decryption error');
  46700. }
  46701. return db.slice(i);
  46702. }
  46703. function pkcs1(key, msg, reverse) {
  46704. var p1 = msg.slice(0, 2);
  46705. var i = 2;
  46706. var status = 0;
  46707. while (msg[i++] !== 0) {
  46708. if (i >= msg.length) {
  46709. status++;
  46710. break;
  46711. }
  46712. }
  46713. var ps = msg.slice(2, i - 1);
  46714. if (p1.toString('hex') !== '0002' && !reverse || p1.toString('hex') !== '0001' && reverse) {
  46715. status++;
  46716. }
  46717. if (ps.length < 8) {
  46718. status++;
  46719. }
  46720. if (status) {
  46721. throw new Error('decryption error');
  46722. }
  46723. return msg.slice(i);
  46724. }
  46725. function compare(a, b) {
  46726. a = Buffer.from(a);
  46727. b = Buffer.from(b);
  46728. var dif = 0;
  46729. var len = a.length;
  46730. if (a.length !== b.length) {
  46731. dif++;
  46732. len = Math.min(a.length, b.length);
  46733. }
  46734. var i = -1;
  46735. while (++i < len) {
  46736. dif += a[i] ^ b[i];
  46737. }
  46738. return dif;
  46739. }
  46740. },{"./mgf":469,"./withPublic":473,"./xor":474,"bn.js":470,"browserify-rsa":209,"create-hash":386,"parse-asn1":459,"safe-buffer":494}],472:[function(require,module,exports){
  46741. "use strict";
  46742. var parseKeys = require('parse-asn1');
  46743. var randomBytes = require('randombytes');
  46744. var createHash = require('create-hash');
  46745. var mgf = require('./mgf');
  46746. var xor = require('./xor');
  46747. var BN = require('bn.js');
  46748. var withPublic = require('./withPublic');
  46749. var crt = require('browserify-rsa');
  46750. var Buffer = require('safe-buffer').Buffer;
  46751. module.exports = function publicEncrypt(publicKey, msg, reverse) {
  46752. var padding;
  46753. if (publicKey.padding) {
  46754. padding = publicKey.padding;
  46755. } else if (reverse) {
  46756. padding = 1;
  46757. } else {
  46758. padding = 4;
  46759. }
  46760. var key = parseKeys(publicKey);
  46761. var paddedMsg;
  46762. if (padding === 4) {
  46763. paddedMsg = oaep(key, msg);
  46764. } else if (padding === 1) {
  46765. paddedMsg = pkcs1(key, msg, reverse);
  46766. } else if (padding === 3) {
  46767. paddedMsg = new BN(msg);
  46768. if (paddedMsg.cmp(key.modulus) >= 0) {
  46769. throw new Error('data too long for modulus');
  46770. }
  46771. } else {
  46772. throw new Error('unknown padding');
  46773. }
  46774. if (reverse) {
  46775. return crt(paddedMsg, key);
  46776. } else {
  46777. return withPublic(paddedMsg, key);
  46778. }
  46779. };
  46780. function oaep(key, msg) {
  46781. var k = key.modulus.byteLength();
  46782. var mLen = msg.length;
  46783. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  46784. var hLen = iHash.length;
  46785. var hLen2 = 2 * hLen;
  46786. if (mLen > k - hLen2 - 2) {
  46787. throw new Error('message too long');
  46788. }
  46789. var ps = Buffer.alloc(k - mLen - hLen2 - 2);
  46790. var dblen = k - hLen - 1;
  46791. var seed = randomBytes(hLen);
  46792. var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen));
  46793. var maskedSeed = xor(seed, mgf(maskedDb, hLen));
  46794. return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k));
  46795. }
  46796. function pkcs1(key, msg, reverse) {
  46797. var mLen = msg.length;
  46798. var k = key.modulus.byteLength();
  46799. if (mLen > k - 11) {
  46800. throw new Error('message too long');
  46801. }
  46802. var ps;
  46803. if (reverse) {
  46804. ps = Buffer.alloc(k - mLen - 3, 0xff);
  46805. } else {
  46806. ps = nonZero(k - mLen - 3);
  46807. }
  46808. return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k));
  46809. }
  46810. function nonZero(len) {
  46811. var out = Buffer.allocUnsafe(len);
  46812. var i = 0;
  46813. var cache = randomBytes(len * 2);
  46814. var cur = 0;
  46815. var num;
  46816. while (i < len) {
  46817. if (cur === cache.length) {
  46818. cache = randomBytes(len * 2);
  46819. cur = 0;
  46820. }
  46821. num = cache[cur++];
  46822. if (num) {
  46823. out[i++] = num;
  46824. }
  46825. }
  46826. return out;
  46827. }
  46828. },{"./mgf":469,"./withPublic":473,"./xor":474,"bn.js":470,"browserify-rsa":209,"create-hash":386,"parse-asn1":459,"randombytes":475,"safe-buffer":494}],473:[function(require,module,exports){
  46829. "use strict";
  46830. var BN = require('bn.js');
  46831. var Buffer = require('safe-buffer').Buffer;
  46832. function withPublic(paddedMsg, key) {
  46833. return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray());
  46834. }
  46835. module.exports = withPublic;
  46836. },{"bn.js":470,"safe-buffer":494}],474:[function(require,module,exports){
  46837. "use strict";
  46838. module.exports = function xor(a, b) {
  46839. var len = a.length;
  46840. var i = -1;
  46841. while (++i < len) {
  46842. a[i] ^= b[i];
  46843. }
  46844. return a;
  46845. };
  46846. },{}],475:[function(require,module,exports){
  46847. (function (process,global){(function (){
  46848. 'use strict';
  46849. // limit of Crypto.getRandomValues()
  46850. // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
  46851. var MAX_BYTES = 65536;
  46852. // Node supports requesting up to this number of bytes
  46853. // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
  46854. var MAX_UINT32 = 4294967295;
  46855. function oldBrowser() {
  46856. throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11');
  46857. }
  46858. var Buffer = require('safe-buffer').Buffer;
  46859. var crypto = global.crypto || global.msCrypto;
  46860. if (crypto && crypto.getRandomValues) {
  46861. module.exports = randomBytes;
  46862. } else {
  46863. module.exports = oldBrowser;
  46864. }
  46865. function randomBytes(size, cb) {
  46866. // phantomjs needs to throw
  46867. if (size > MAX_UINT32) throw new RangeError('requested too many random bytes');
  46868. var bytes = Buffer.allocUnsafe(size);
  46869. if (size > 0) {
  46870. // getRandomValues fails on IE if size == 0
  46871. if (size > MAX_BYTES) {
  46872. // this is the max bytes crypto.getRandomValues
  46873. // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  46874. for (var generated = 0; generated < size; generated += MAX_BYTES) {
  46875. // buffer.slice automatically checks if the end is past the end of
  46876. // the buffer so we don't have to here
  46877. crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
  46878. }
  46879. } else {
  46880. crypto.getRandomValues(bytes);
  46881. }
  46882. }
  46883. if (typeof cb === 'function') {
  46884. return process.nextTick(function () {
  46885. cb(null, bytes);
  46886. });
  46887. }
  46888. return bytes;
  46889. }
  46890. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46891. },{"_process":467,"safe-buffer":494}],476:[function(require,module,exports){
  46892. (function (process,global){(function (){
  46893. 'use strict';
  46894. function oldBrowser() {
  46895. throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11');
  46896. }
  46897. var safeBuffer = require('safe-buffer');
  46898. var randombytes = require('randombytes');
  46899. var Buffer = safeBuffer.Buffer;
  46900. var kBufferMaxLength = safeBuffer.kMaxLength;
  46901. var crypto = global.crypto || global.msCrypto;
  46902. var kMaxUint32 = Math.pow(2, 32) - 1;
  46903. function assertOffset(offset, length) {
  46904. if (typeof offset !== 'number' || offset !== offset) {
  46905. // eslint-disable-line no-self-compare
  46906. throw new TypeError('offset must be a number');
  46907. }
  46908. if (offset > kMaxUint32 || offset < 0) {
  46909. throw new TypeError('offset must be a uint32');
  46910. }
  46911. if (offset > kBufferMaxLength || offset > length) {
  46912. throw new RangeError('offset out of range');
  46913. }
  46914. }
  46915. function assertSize(size, offset, length) {
  46916. if (typeof size !== 'number' || size !== size) {
  46917. // eslint-disable-line no-self-compare
  46918. throw new TypeError('size must be a number');
  46919. }
  46920. if (size > kMaxUint32 || size < 0) {
  46921. throw new TypeError('size must be a uint32');
  46922. }
  46923. if (size + offset > length || size > kBufferMaxLength) {
  46924. throw new RangeError('buffer too small');
  46925. }
  46926. }
  46927. if (crypto && crypto.getRandomValues || !process.browser) {
  46928. exports.randomFill = randomFill;
  46929. exports.randomFillSync = randomFillSync;
  46930. } else {
  46931. exports.randomFill = oldBrowser;
  46932. exports.randomFillSync = oldBrowser;
  46933. }
  46934. function randomFill(buf, offset, size, cb) {
  46935. if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
  46936. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  46937. }
  46938. if (typeof offset === 'function') {
  46939. cb = offset;
  46940. offset = 0;
  46941. size = buf.length;
  46942. } else if (typeof size === 'function') {
  46943. cb = size;
  46944. size = buf.length - offset;
  46945. } else if (typeof cb !== 'function') {
  46946. throw new TypeError('"cb" argument must be a function');
  46947. }
  46948. assertOffset(offset, buf.length);
  46949. assertSize(size, offset, buf.length);
  46950. return actualFill(buf, offset, size, cb);
  46951. }
  46952. function actualFill(buf, offset, size, cb) {
  46953. if (process.browser) {
  46954. var ourBuf = buf.buffer;
  46955. var uint = new Uint8Array(ourBuf, offset, size);
  46956. crypto.getRandomValues(uint);
  46957. if (cb) {
  46958. process.nextTick(function () {
  46959. cb(null, buf);
  46960. });
  46961. return;
  46962. }
  46963. return buf;
  46964. }
  46965. if (cb) {
  46966. randombytes(size, function (err, bytes) {
  46967. if (err) {
  46968. return cb(err);
  46969. }
  46970. bytes.copy(buf, offset);
  46971. cb(null, buf);
  46972. });
  46973. return;
  46974. }
  46975. var bytes = randombytes(size);
  46976. bytes.copy(buf, offset);
  46977. return buf;
  46978. }
  46979. function randomFillSync(buf, offset, size) {
  46980. if (typeof offset === 'undefined') {
  46981. offset = 0;
  46982. }
  46983. if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) {
  46984. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  46985. }
  46986. assertOffset(offset, buf.length);
  46987. if (size === undefined) size = buf.length - offset;
  46988. assertSize(size, offset, buf.length);
  46989. return actualFill(buf, offset, size);
  46990. }
  46991. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  46992. },{"_process":467,"randombytes":475,"safe-buffer":494}],477:[function(require,module,exports){
  46993. 'use strict';
  46994. function _inheritsLoose(subClass, superClass) {
  46995. subClass.prototype = Object.create(superClass.prototype);
  46996. subClass.prototype.constructor = subClass;
  46997. subClass.__proto__ = superClass;
  46998. }
  46999. var codes = {};
  47000. function createErrorType(code, message, Base) {
  47001. if (!Base) {
  47002. Base = Error;
  47003. }
  47004. function getMessage(arg1, arg2, arg3) {
  47005. if (typeof message === 'string') {
  47006. return message;
  47007. } else {
  47008. return message(arg1, arg2, arg3);
  47009. }
  47010. }
  47011. var NodeError = /*#__PURE__*/
  47012. function (_Base) {
  47013. _inheritsLoose(NodeError, _Base);
  47014. function NodeError(arg1, arg2, arg3) {
  47015. return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
  47016. }
  47017. return NodeError;
  47018. }(Base);
  47019. NodeError.prototype.name = Base.name;
  47020. NodeError.prototype.code = code;
  47021. codes[code] = NodeError;
  47022. } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
  47023. function oneOf(expected, thing) {
  47024. if (Array.isArray(expected)) {
  47025. var len = expected.length;
  47026. expected = expected.map(function (i) {
  47027. return String(i);
  47028. });
  47029. if (len > 2) {
  47030. return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
  47031. } else if (len === 2) {
  47032. return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
  47033. } else {
  47034. return "of ".concat(thing, " ").concat(expected[0]);
  47035. }
  47036. } else {
  47037. return "of ".concat(thing, " ").concat(String(expected));
  47038. }
  47039. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
  47040. function startsWith(str, search, pos) {
  47041. return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
  47042. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  47043. function endsWith(str, search, this_len) {
  47044. if (this_len === undefined || this_len > str.length) {
  47045. this_len = str.length;
  47046. }
  47047. return str.substring(this_len - search.length, this_len) === search;
  47048. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
  47049. function includes(str, search, start) {
  47050. if (typeof start !== 'number') {
  47051. start = 0;
  47052. }
  47053. if (start + search.length > str.length) {
  47054. return false;
  47055. } else {
  47056. return str.indexOf(search, start) !== -1;
  47057. }
  47058. }
  47059. createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
  47060. return 'The value "' + value + '" is invalid for option "' + name + '"';
  47061. }, TypeError);
  47062. createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  47063. // determiner: 'must be' or 'must not be'
  47064. var determiner;
  47065. if (typeof expected === 'string' && startsWith(expected, 'not ')) {
  47066. determiner = 'must not be';
  47067. expected = expected.replace(/^not /, '');
  47068. } else {
  47069. determiner = 'must be';
  47070. }
  47071. var msg;
  47072. if (endsWith(name, ' argument')) {
  47073. // For cases like 'first argument'
  47074. msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  47075. } else {
  47076. var type = includes(name, '.') ? 'property' : 'argument';
  47077. msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  47078. }
  47079. msg += ". Received type ".concat(typeof actual);
  47080. return msg;
  47081. }, TypeError);
  47082. createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
  47083. createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
  47084. return 'The ' + name + ' method is not implemented';
  47085. });
  47086. createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
  47087. createErrorType('ERR_STREAM_DESTROYED', function (name) {
  47088. return 'Cannot call ' + name + ' after a stream was destroyed';
  47089. });
  47090. createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
  47091. createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
  47092. createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
  47093. createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
  47094. createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
  47095. return 'Unknown encoding: ' + arg;
  47096. }, TypeError);
  47097. createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
  47098. module.exports.codes = codes;
  47099. },{}],478:[function(require,module,exports){
  47100. (function (process){(function (){
  47101. // Copyright Joyent, Inc. and other Node contributors.
  47102. //
  47103. // Permission is hereby granted, free of charge, to any person obtaining a
  47104. // copy of this software and associated documentation files (the
  47105. // "Software"), to deal in the Software without restriction, including
  47106. // without limitation the rights to use, copy, modify, merge, publish,
  47107. // distribute, sublicense, and/or sell copies of the Software, and to permit
  47108. // persons to whom the Software is furnished to do so, subject to the
  47109. // following conditions:
  47110. //
  47111. // The above copyright notice and this permission notice shall be included
  47112. // in all copies or substantial portions of the Software.
  47113. //
  47114. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  47115. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  47116. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  47117. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  47118. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  47119. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  47120. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  47121. // a duplex stream is just a stream that is both readable and writable.
  47122. // Since JS doesn't have multiple prototypal inheritance, this class
  47123. // prototypally inherits from Readable, and then parasitically from
  47124. // Writable.
  47125. 'use strict';
  47126. /*<replacement>*/
  47127. var objectKeys = Object.keys || function (obj) {
  47128. var keys = [];
  47129. for (var key in obj) keys.push(key);
  47130. return keys;
  47131. };
  47132. /*</replacement>*/
  47133. module.exports = Duplex;
  47134. var Readable = require('./_stream_readable');
  47135. var Writable = require('./_stream_writable');
  47136. require('inherits')(Duplex, Readable);
  47137. {
  47138. // Allow the keys array to be GC'ed.
  47139. var keys = objectKeys(Writable.prototype);
  47140. for (var v = 0; v < keys.length; v++) {
  47141. var method = keys[v];
  47142. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  47143. }
  47144. }
  47145. function Duplex(options) {
  47146. if (!(this instanceof Duplex)) return new Duplex(options);
  47147. Readable.call(this, options);
  47148. Writable.call(this, options);
  47149. this.allowHalfOpen = true;
  47150. if (options) {
  47151. if (options.readable === false) this.readable = false;
  47152. if (options.writable === false) this.writable = false;
  47153. if (options.allowHalfOpen === false) {
  47154. this.allowHalfOpen = false;
  47155. this.once('end', onend);
  47156. }
  47157. }
  47158. }
  47159. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  47160. // making it explicit this property is not enumerable
  47161. // because otherwise some prototype manipulation in
  47162. // userland will fail
  47163. enumerable: false,
  47164. get: function get() {
  47165. return this._writableState.highWaterMark;
  47166. }
  47167. });
  47168. Object.defineProperty(Duplex.prototype, 'writableBuffer', {
  47169. // making it explicit this property is not enumerable
  47170. // because otherwise some prototype manipulation in
  47171. // userland will fail
  47172. enumerable: false,
  47173. get: function get() {
  47174. return this._writableState && this._writableState.getBuffer();
  47175. }
  47176. });
  47177. Object.defineProperty(Duplex.prototype, 'writableLength', {
  47178. // making it explicit this property is not enumerable
  47179. // because otherwise some prototype manipulation in
  47180. // userland will fail
  47181. enumerable: false,
  47182. get: function get() {
  47183. return this._writableState.length;
  47184. }
  47185. });
  47186. // the no-half-open enforcer
  47187. function onend() {
  47188. // If the writable side ended, then we're ok.
  47189. if (this._writableState.ended) return;
  47190. // no more data can be written.
  47191. // But allow more writes to happen in this tick.
  47192. process.nextTick(onEndNT, this);
  47193. }
  47194. function onEndNT(self) {
  47195. self.end();
  47196. }
  47197. Object.defineProperty(Duplex.prototype, 'destroyed', {
  47198. // making it explicit this property is not enumerable
  47199. // because otherwise some prototype manipulation in
  47200. // userland will fail
  47201. enumerable: false,
  47202. get: function get() {
  47203. if (this._readableState === undefined || this._writableState === undefined) {
  47204. return false;
  47205. }
  47206. return this._readableState.destroyed && this._writableState.destroyed;
  47207. },
  47208. set: function set(value) {
  47209. // we ignore the value if the stream
  47210. // has not been initialized yet
  47211. if (this._readableState === undefined || this._writableState === undefined) {
  47212. return;
  47213. }
  47214. // backward compatibility, the user is explicitly
  47215. // managing destroyed
  47216. this._readableState.destroyed = value;
  47217. this._writableState.destroyed = value;
  47218. }
  47219. });
  47220. }).call(this)}).call(this,require('_process'))
  47221. },{"./_stream_readable":480,"./_stream_writable":482,"_process":467,"inherits":440}],479:[function(require,module,exports){
  47222. // Copyright Joyent, Inc. and other Node contributors.
  47223. //
  47224. // Permission is hereby granted, free of charge, to any person obtaining a
  47225. // copy of this software and associated documentation files (the
  47226. // "Software"), to deal in the Software without restriction, including
  47227. // without limitation the rights to use, copy, modify, merge, publish,
  47228. // distribute, sublicense, and/or sell copies of the Software, and to permit
  47229. // persons to whom the Software is furnished to do so, subject to the
  47230. // following conditions:
  47231. //
  47232. // The above copyright notice and this permission notice shall be included
  47233. // in all copies or substantial portions of the Software.
  47234. //
  47235. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  47236. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  47237. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  47238. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  47239. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  47240. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  47241. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  47242. // a passthrough stream.
  47243. // basically just the most minimal sort of Transform stream.
  47244. // Every written chunk gets output as-is.
  47245. 'use strict';
  47246. module.exports = PassThrough;
  47247. var Transform = require('./_stream_transform');
  47248. require('inherits')(PassThrough, Transform);
  47249. function PassThrough(options) {
  47250. if (!(this instanceof PassThrough)) return new PassThrough(options);
  47251. Transform.call(this, options);
  47252. }
  47253. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  47254. cb(null, chunk);
  47255. };
  47256. },{"./_stream_transform":481,"inherits":440}],480:[function(require,module,exports){
  47257. (function (process,global){(function (){
  47258. // Copyright Joyent, Inc. and other Node contributors.
  47259. //
  47260. // Permission is hereby granted, free of charge, to any person obtaining a
  47261. // copy of this software and associated documentation files (the
  47262. // "Software"), to deal in the Software without restriction, including
  47263. // without limitation the rights to use, copy, modify, merge, publish,
  47264. // distribute, sublicense, and/or sell copies of the Software, and to permit
  47265. // persons to whom the Software is furnished to do so, subject to the
  47266. // following conditions:
  47267. //
  47268. // The above copyright notice and this permission notice shall be included
  47269. // in all copies or substantial portions of the Software.
  47270. //
  47271. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  47272. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  47273. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  47274. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  47275. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  47276. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  47277. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  47278. 'use strict';
  47279. module.exports = Readable;
  47280. /*<replacement>*/
  47281. var Duplex;
  47282. /*</replacement>*/
  47283. Readable.ReadableState = ReadableState;
  47284. /*<replacement>*/
  47285. var EE = require('events').EventEmitter;
  47286. var EElistenerCount = function EElistenerCount(emitter, type) {
  47287. return emitter.listeners(type).length;
  47288. };
  47289. /*</replacement>*/
  47290. /*<replacement>*/
  47291. var Stream = require('./internal/streams/stream');
  47292. /*</replacement>*/
  47293. var Buffer = require('buffer').Buffer;
  47294. var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
  47295. function _uint8ArrayToBuffer(chunk) {
  47296. return Buffer.from(chunk);
  47297. }
  47298. function _isUint8Array(obj) {
  47299. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  47300. }
  47301. /*<replacement>*/
  47302. var debugUtil = require('util');
  47303. var debug;
  47304. if (debugUtil && debugUtil.debuglog) {
  47305. debug = debugUtil.debuglog('stream');
  47306. } else {
  47307. debug = function debug() {};
  47308. }
  47309. /*</replacement>*/
  47310. var BufferList = require('./internal/streams/buffer_list');
  47311. var destroyImpl = require('./internal/streams/destroy');
  47312. var _require = require('./internal/streams/state'),
  47313. getHighWaterMark = _require.getHighWaterMark;
  47314. var _require$codes = require('../errors').codes,
  47315. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  47316. ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
  47317. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  47318. ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
  47319. // Lazy loaded to improve the startup performance.
  47320. var StringDecoder;
  47321. var createReadableStreamAsyncIterator;
  47322. var from;
  47323. require('inherits')(Readable, Stream);
  47324. var errorOrDestroy = destroyImpl.errorOrDestroy;
  47325. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  47326. function prependListener(emitter, event, fn) {
  47327. // Sadly this is not cacheable as some libraries bundle their own
  47328. // event emitter implementation with them.
  47329. if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
  47330. // This is a hack to make sure that our error handler is attached before any
  47331. // userland ones. NEVER DO THIS. This is here only because this code needs
  47332. // to continue to work with older versions of Node.js that do not include
  47333. // the prependListener() method. The goal is to eventually remove this hack.
  47334. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  47335. }
  47336. function ReadableState(options, stream, isDuplex) {
  47337. Duplex = Duplex || require('./_stream_duplex');
  47338. options = options || {};
  47339. // Duplex streams are both readable and writable, but share
  47340. // the same options object.
  47341. // However, some cases require setting options to different
  47342. // values for the readable and the writable sides of the duplex stream.
  47343. // These options can be provided separately as readableXXX and writableXXX.
  47344. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
  47345. // object stream flag. Used to make read(n) ignore n and to
  47346. // make all the buffer merging and length checks go away
  47347. this.objectMode = !!options.objectMode;
  47348. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  47349. // the point at which it stops calling _read() to fill the buffer
  47350. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  47351. this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex);
  47352. // A linked list is used to store data chunks instead of an array because the
  47353. // linked list can remove elements from the beginning faster than
  47354. // array.shift()
  47355. this.buffer = new BufferList();
  47356. this.length = 0;
  47357. this.pipes = null;
  47358. this.pipesCount = 0;
  47359. this.flowing = null;
  47360. this.ended = false;
  47361. this.endEmitted = false;
  47362. this.reading = false;
  47363. // a flag to be able to tell if the event 'readable'/'data' is emitted
  47364. // immediately, or on a later tick. We set this to true at first, because
  47365. // any actions that shouldn't happen until "later" should generally also
  47366. // not happen before the first read call.
  47367. this.sync = true;
  47368. // whenever we return null, then we set a flag to say
  47369. // that we're awaiting a 'readable' event emission.
  47370. this.needReadable = false;
  47371. this.emittedReadable = false;
  47372. this.readableListening = false;
  47373. this.resumeScheduled = false;
  47374. this.paused = true;
  47375. // Should close be emitted on destroy. Defaults to true.
  47376. this.emitClose = options.emitClose !== false;
  47377. // Should .destroy() be called after 'end' (and potentially 'finish')
  47378. this.autoDestroy = !!options.autoDestroy;
  47379. // has it been destroyed
  47380. this.destroyed = false;
  47381. // Crypto is kind of old and crusty. Historically, its default string
  47382. // encoding is 'binary' so we have to make this configurable.
  47383. // Everything else in the universe uses 'utf8', though.
  47384. this.defaultEncoding = options.defaultEncoding || 'utf8';
  47385. // the number of writers that are awaiting a drain event in .pipe()s
  47386. this.awaitDrain = 0;
  47387. // if true, a maybeReadMore has been scheduled
  47388. this.readingMore = false;
  47389. this.decoder = null;
  47390. this.encoding = null;
  47391. if (options.encoding) {
  47392. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  47393. this.decoder = new StringDecoder(options.encoding);
  47394. this.encoding = options.encoding;
  47395. }
  47396. }
  47397. function Readable(options) {
  47398. Duplex = Duplex || require('./_stream_duplex');
  47399. if (!(this instanceof Readable)) return new Readable(options);
  47400. // Checking for a Stream.Duplex instance is faster here instead of inside
  47401. // the ReadableState constructor, at least with V8 6.5
  47402. var isDuplex = this instanceof Duplex;
  47403. this._readableState = new ReadableState(options, this, isDuplex);
  47404. // legacy
  47405. this.readable = true;
  47406. if (options) {
  47407. if (typeof options.read === 'function') this._read = options.read;
  47408. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  47409. }
  47410. Stream.call(this);
  47411. }
  47412. Object.defineProperty(Readable.prototype, 'destroyed', {
  47413. // making it explicit this property is not enumerable
  47414. // because otherwise some prototype manipulation in
  47415. // userland will fail
  47416. enumerable: false,
  47417. get: function get() {
  47418. if (this._readableState === undefined) {
  47419. return false;
  47420. }
  47421. return this._readableState.destroyed;
  47422. },
  47423. set: function set(value) {
  47424. // we ignore the value if the stream
  47425. // has not been initialized yet
  47426. if (!this._readableState) {
  47427. return;
  47428. }
  47429. // backward compatibility, the user is explicitly
  47430. // managing destroyed
  47431. this._readableState.destroyed = value;
  47432. }
  47433. });
  47434. Readable.prototype.destroy = destroyImpl.destroy;
  47435. Readable.prototype._undestroy = destroyImpl.undestroy;
  47436. Readable.prototype._destroy = function (err, cb) {
  47437. cb(err);
  47438. };
  47439. // Manually shove something into the read() buffer.
  47440. // This returns true if the highWaterMark has not been hit yet,
  47441. // similar to how Writable.write() returns true if you should
  47442. // write() some more.
  47443. Readable.prototype.push = function (chunk, encoding) {
  47444. var state = this._readableState;
  47445. var skipChunkCheck;
  47446. if (!state.objectMode) {
  47447. if (typeof chunk === 'string') {
  47448. encoding = encoding || state.defaultEncoding;
  47449. if (encoding !== state.encoding) {
  47450. chunk = Buffer.from(chunk, encoding);
  47451. encoding = '';
  47452. }
  47453. skipChunkCheck = true;
  47454. }
  47455. } else {
  47456. skipChunkCheck = true;
  47457. }
  47458. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  47459. };
  47460. // Unshift should *always* be something directly out of read()
  47461. Readable.prototype.unshift = function (chunk) {
  47462. return readableAddChunk(this, chunk, null, true, false);
  47463. };
  47464. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  47465. debug('readableAddChunk', chunk);
  47466. var state = stream._readableState;
  47467. if (chunk === null) {
  47468. state.reading = false;
  47469. onEofChunk(stream, state);
  47470. } else {
  47471. var er;
  47472. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  47473. if (er) {
  47474. errorOrDestroy(stream, er);
  47475. } else if (state.objectMode || chunk && chunk.length > 0) {
  47476. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  47477. chunk = _uint8ArrayToBuffer(chunk);
  47478. }
  47479. if (addToFront) {
  47480. if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
  47481. } else if (state.ended) {
  47482. errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
  47483. } else if (state.destroyed) {
  47484. return false;
  47485. } else {
  47486. state.reading = false;
  47487. if (state.decoder && !encoding) {
  47488. chunk = state.decoder.write(chunk);
  47489. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  47490. } else {
  47491. addChunk(stream, state, chunk, false);
  47492. }
  47493. }
  47494. } else if (!addToFront) {
  47495. state.reading = false;
  47496. maybeReadMore(stream, state);
  47497. }
  47498. }
  47499. // We can push more data if we are below the highWaterMark.
  47500. // Also, if we have no data yet, we can stand some more bytes.
  47501. // This is to work around cases where hwm=0, such as the repl.
  47502. return !state.ended && (state.length < state.highWaterMark || state.length === 0);
  47503. }
  47504. function addChunk(stream, state, chunk, addToFront) {
  47505. if (state.flowing && state.length === 0 && !state.sync) {
  47506. state.awaitDrain = 0;
  47507. stream.emit('data', chunk);
  47508. } else {
  47509. // update the buffer info.
  47510. state.length += state.objectMode ? 1 : chunk.length;
  47511. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  47512. if (state.needReadable) emitReadable(stream);
  47513. }
  47514. maybeReadMore(stream, state);
  47515. }
  47516. function chunkInvalid(state, chunk) {
  47517. var er;
  47518. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  47519. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
  47520. }
  47521. return er;
  47522. }
  47523. Readable.prototype.isPaused = function () {
  47524. return this._readableState.flowing === false;
  47525. };
  47526. // backwards compatibility.
  47527. Readable.prototype.setEncoding = function (enc) {
  47528. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  47529. var decoder = new StringDecoder(enc);
  47530. this._readableState.decoder = decoder;
  47531. // If setEncoding(null), decoder.encoding equals utf8
  47532. this._readableState.encoding = this._readableState.decoder.encoding;
  47533. // Iterate over current buffer to convert already stored Buffers:
  47534. var p = this._readableState.buffer.head;
  47535. var content = '';
  47536. while (p !== null) {
  47537. content += decoder.write(p.data);
  47538. p = p.next;
  47539. }
  47540. this._readableState.buffer.clear();
  47541. if (content !== '') this._readableState.buffer.push(content);
  47542. this._readableState.length = content.length;
  47543. return this;
  47544. };
  47545. // Don't raise the hwm > 1GB
  47546. var MAX_HWM = 0x40000000;
  47547. function computeNewHighWaterMark(n) {
  47548. if (n >= MAX_HWM) {
  47549. // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
  47550. n = MAX_HWM;
  47551. } else {
  47552. // Get the next highest power of 2 to prevent increasing hwm excessively in
  47553. // tiny amounts
  47554. n--;
  47555. n |= n >>> 1;
  47556. n |= n >>> 2;
  47557. n |= n >>> 4;
  47558. n |= n >>> 8;
  47559. n |= n >>> 16;
  47560. n++;
  47561. }
  47562. return n;
  47563. }
  47564. // This function is designed to be inlinable, so please take care when making
  47565. // changes to the function body.
  47566. function howMuchToRead(n, state) {
  47567. if (n <= 0 || state.length === 0 && state.ended) return 0;
  47568. if (state.objectMode) return 1;
  47569. if (n !== n) {
  47570. // Only flow one buffer at a time
  47571. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  47572. }
  47573. // If we're asking for more than the current hwm, then raise the hwm.
  47574. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  47575. if (n <= state.length) return n;
  47576. // Don't have enough
  47577. if (!state.ended) {
  47578. state.needReadable = true;
  47579. return 0;
  47580. }
  47581. return state.length;
  47582. }
  47583. // you can override either this method, or the async _read(n) below.
  47584. Readable.prototype.read = function (n) {
  47585. debug('read', n);
  47586. n = parseInt(n, 10);
  47587. var state = this._readableState;
  47588. var nOrig = n;
  47589. if (n !== 0) state.emittedReadable = false;
  47590. // if we're doing read(0) to trigger a readable event, but we
  47591. // already have a bunch of data in the buffer, then just trigger
  47592. // the 'readable' event and move on.
  47593. if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
  47594. debug('read: emitReadable', state.length, state.ended);
  47595. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  47596. return null;
  47597. }
  47598. n = howMuchToRead(n, state);
  47599. // if we've ended, and we're now clear, then finish it up.
  47600. if (n === 0 && state.ended) {
  47601. if (state.length === 0) endReadable(this);
  47602. return null;
  47603. }
  47604. // All the actual chunk generation logic needs to be
  47605. // *below* the call to _read. The reason is that in certain
  47606. // synthetic stream cases, such as passthrough streams, _read
  47607. // may be a completely synchronous operation which may change
  47608. // the state of the read buffer, providing enough data when
  47609. // before there was *not* enough.
  47610. //
  47611. // So, the steps are:
  47612. // 1. Figure out what the state of things will be after we do
  47613. // a read from the buffer.
  47614. //
  47615. // 2. If that resulting state will trigger a _read, then call _read.
  47616. // Note that this may be asynchronous, or synchronous. Yes, it is
  47617. // deeply ugly to write APIs this way, but that still doesn't mean
  47618. // that the Readable class should behave improperly, as streams are
  47619. // designed to be sync/async agnostic.
  47620. // Take note if the _read call is sync or async (ie, if the read call
  47621. // has returned yet), so that we know whether or not it's safe to emit
  47622. // 'readable' etc.
  47623. //
  47624. // 3. Actually pull the requested chunks out of the buffer and return.
  47625. // if we need a readable event, then we need to do some reading.
  47626. var doRead = state.needReadable;
  47627. debug('need readable', doRead);
  47628. // if we currently have less than the highWaterMark, then also read some
  47629. if (state.length === 0 || state.length - n < state.highWaterMark) {
  47630. doRead = true;
  47631. debug('length less than watermark', doRead);
  47632. }
  47633. // however, if we've ended, then there's no point, and if we're already
  47634. // reading, then it's unnecessary.
  47635. if (state.ended || state.reading) {
  47636. doRead = false;
  47637. debug('reading or ended', doRead);
  47638. } else if (doRead) {
  47639. debug('do read');
  47640. state.reading = true;
  47641. state.sync = true;
  47642. // if the length is currently zero, then we *need* a readable event.
  47643. if (state.length === 0) state.needReadable = true;
  47644. // call internal read method
  47645. this._read(state.highWaterMark);
  47646. state.sync = false;
  47647. // If _read pushed data synchronously, then `reading` will be false,
  47648. // and we need to re-evaluate how much data we can return to the user.
  47649. if (!state.reading) n = howMuchToRead(nOrig, state);
  47650. }
  47651. var ret;
  47652. if (n > 0) ret = fromList(n, state);else ret = null;
  47653. if (ret === null) {
  47654. state.needReadable = state.length <= state.highWaterMark;
  47655. n = 0;
  47656. } else {
  47657. state.length -= n;
  47658. state.awaitDrain = 0;
  47659. }
  47660. if (state.length === 0) {
  47661. // If we have nothing in the buffer, then we want to know
  47662. // as soon as we *do* get something into the buffer.
  47663. if (!state.ended) state.needReadable = true;
  47664. // If we tried to read() past the EOF, then emit end on the next tick.
  47665. if (nOrig !== n && state.ended) endReadable(this);
  47666. }
  47667. if (ret !== null) this.emit('data', ret);
  47668. return ret;
  47669. };
  47670. function onEofChunk(stream, state) {
  47671. debug('onEofChunk');
  47672. if (state.ended) return;
  47673. if (state.decoder) {
  47674. var chunk = state.decoder.end();
  47675. if (chunk && chunk.length) {
  47676. state.buffer.push(chunk);
  47677. state.length += state.objectMode ? 1 : chunk.length;
  47678. }
  47679. }
  47680. state.ended = true;
  47681. if (state.sync) {
  47682. // if we are sync, wait until next tick to emit the data.
  47683. // Otherwise we risk emitting data in the flow()
  47684. // the readable code triggers during a read() call
  47685. emitReadable(stream);
  47686. } else {
  47687. // emit 'readable' now to make sure it gets picked up.
  47688. state.needReadable = false;
  47689. if (!state.emittedReadable) {
  47690. state.emittedReadable = true;
  47691. emitReadable_(stream);
  47692. }
  47693. }
  47694. }
  47695. // Don't emit readable right away in sync mode, because this can trigger
  47696. // another read() call => stack overflow. This way, it might trigger
  47697. // a nextTick recursion warning, but that's not so bad.
  47698. function emitReadable(stream) {
  47699. var state = stream._readableState;
  47700. debug('emitReadable', state.needReadable, state.emittedReadable);
  47701. state.needReadable = false;
  47702. if (!state.emittedReadable) {
  47703. debug('emitReadable', state.flowing);
  47704. state.emittedReadable = true;
  47705. process.nextTick(emitReadable_, stream);
  47706. }
  47707. }
  47708. function emitReadable_(stream) {
  47709. var state = stream._readableState;
  47710. debug('emitReadable_', state.destroyed, state.length, state.ended);
  47711. if (!state.destroyed && (state.length || state.ended)) {
  47712. stream.emit('readable');
  47713. state.emittedReadable = false;
  47714. }
  47715. // The stream needs another readable event if
  47716. // 1. It is not flowing, as the flow mechanism will take
  47717. // care of it.
  47718. // 2. It is not ended.
  47719. // 3. It is below the highWaterMark, so we can schedule
  47720. // another readable later.
  47721. state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
  47722. flow(stream);
  47723. }
  47724. // at this point, the user has presumably seen the 'readable' event,
  47725. // and called read() to consume some data. that may have triggered
  47726. // in turn another _read(n) call, in which case reading = true if
  47727. // it's in progress.
  47728. // However, if we're not ended, or reading, and the length < hwm,
  47729. // then go ahead and try to read some more preemptively.
  47730. function maybeReadMore(stream, state) {
  47731. if (!state.readingMore) {
  47732. state.readingMore = true;
  47733. process.nextTick(maybeReadMore_, stream, state);
  47734. }
  47735. }
  47736. function maybeReadMore_(stream, state) {
  47737. // Attempt to read more data if we should.
  47738. //
  47739. // The conditions for reading more data are (one of):
  47740. // - Not enough data buffered (state.length < state.highWaterMark). The loop
  47741. // is responsible for filling the buffer with enough data if such data
  47742. // is available. If highWaterMark is 0 and we are not in the flowing mode
  47743. // we should _not_ attempt to buffer any extra data. We'll get more data
  47744. // when the stream consumer calls read() instead.
  47745. // - No data in the buffer, and the stream is in flowing mode. In this mode
  47746. // the loop below is responsible for ensuring read() is called. Failing to
  47747. // call read here would abort the flow and there's no other mechanism for
  47748. // continuing the flow if the stream consumer has just subscribed to the
  47749. // 'data' event.
  47750. //
  47751. // In addition to the above conditions to keep reading data, the following
  47752. // conditions prevent the data from being read:
  47753. // - The stream has ended (state.ended).
  47754. // - There is already a pending 'read' operation (state.reading). This is a
  47755. // case where the the stream has called the implementation defined _read()
  47756. // method, but they are processing the call asynchronously and have _not_
  47757. // called push() with new data. In this case we skip performing more
  47758. // read()s. The execution ends in this method again after the _read() ends
  47759. // up calling push() with more data.
  47760. while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
  47761. var len = state.length;
  47762. debug('maybeReadMore read 0');
  47763. stream.read(0);
  47764. if (len === state.length)
  47765. // didn't get any data, stop spinning.
  47766. break;
  47767. }
  47768. state.readingMore = false;
  47769. }
  47770. // abstract method. to be overridden in specific implementation classes.
  47771. // call cb(er, data) where data is <= n in length.
  47772. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  47773. // arbitrary, and perhaps not very meaningful.
  47774. Readable.prototype._read = function (n) {
  47775. errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
  47776. };
  47777. Readable.prototype.pipe = function (dest, pipeOpts) {
  47778. var src = this;
  47779. var state = this._readableState;
  47780. switch (state.pipesCount) {
  47781. case 0:
  47782. state.pipes = dest;
  47783. break;
  47784. case 1:
  47785. state.pipes = [state.pipes, dest];
  47786. break;
  47787. default:
  47788. state.pipes.push(dest);
  47789. break;
  47790. }
  47791. state.pipesCount += 1;
  47792. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  47793. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  47794. var endFn = doEnd ? onend : unpipe;
  47795. if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
  47796. dest.on('unpipe', onunpipe);
  47797. function onunpipe(readable, unpipeInfo) {
  47798. debug('onunpipe');
  47799. if (readable === src) {
  47800. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  47801. unpipeInfo.hasUnpiped = true;
  47802. cleanup();
  47803. }
  47804. }
  47805. }
  47806. function onend() {
  47807. debug('onend');
  47808. dest.end();
  47809. }
  47810. // when the dest drains, it reduces the awaitDrain counter
  47811. // on the source. This would be more elegant with a .once()
  47812. // handler in flow(), but adding and removing repeatedly is
  47813. // too slow.
  47814. var ondrain = pipeOnDrain(src);
  47815. dest.on('drain', ondrain);
  47816. var cleanedUp = false;
  47817. function cleanup() {
  47818. debug('cleanup');
  47819. // cleanup event handlers once the pipe is broken
  47820. dest.removeListener('close', onclose);
  47821. dest.removeListener('finish', onfinish);
  47822. dest.removeListener('drain', ondrain);
  47823. dest.removeListener('error', onerror);
  47824. dest.removeListener('unpipe', onunpipe);
  47825. src.removeListener('end', onend);
  47826. src.removeListener('end', unpipe);
  47827. src.removeListener('data', ondata);
  47828. cleanedUp = true;
  47829. // if the reader is waiting for a drain event from this
  47830. // specific writer, then it would cause it to never start
  47831. // flowing again.
  47832. // So, if this is awaiting a drain, then we just call it now.
  47833. // If we don't know, then assume that we are waiting for one.
  47834. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  47835. }
  47836. src.on('data', ondata);
  47837. function ondata(chunk) {
  47838. debug('ondata');
  47839. var ret = dest.write(chunk);
  47840. debug('dest.write', ret);
  47841. if (ret === false) {
  47842. // If the user unpiped during `dest.write()`, it is possible
  47843. // to get stuck in a permanently paused state if that write
  47844. // also returned false.
  47845. // => Check whether `dest` is still a piping destination.
  47846. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  47847. debug('false write response, pause', state.awaitDrain);
  47848. state.awaitDrain++;
  47849. }
  47850. src.pause();
  47851. }
  47852. }
  47853. // if the dest has an error, then stop piping into it.
  47854. // however, don't suppress the throwing behavior for this.
  47855. function onerror(er) {
  47856. debug('onerror', er);
  47857. unpipe();
  47858. dest.removeListener('error', onerror);
  47859. if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
  47860. }
  47861. // Make sure our error handler is attached before userland ones.
  47862. prependListener(dest, 'error', onerror);
  47863. // Both close and finish should trigger unpipe, but only once.
  47864. function onclose() {
  47865. dest.removeListener('finish', onfinish);
  47866. unpipe();
  47867. }
  47868. dest.once('close', onclose);
  47869. function onfinish() {
  47870. debug('onfinish');
  47871. dest.removeListener('close', onclose);
  47872. unpipe();
  47873. }
  47874. dest.once('finish', onfinish);
  47875. function unpipe() {
  47876. debug('unpipe');
  47877. src.unpipe(dest);
  47878. }
  47879. // tell the dest that it's being piped to
  47880. dest.emit('pipe', src);
  47881. // start the flow if it hasn't been started already.
  47882. if (!state.flowing) {
  47883. debug('pipe resume');
  47884. src.resume();
  47885. }
  47886. return dest;
  47887. };
  47888. function pipeOnDrain(src) {
  47889. return function pipeOnDrainFunctionResult() {
  47890. var state = src._readableState;
  47891. debug('pipeOnDrain', state.awaitDrain);
  47892. if (state.awaitDrain) state.awaitDrain--;
  47893. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  47894. state.flowing = true;
  47895. flow(src);
  47896. }
  47897. };
  47898. }
  47899. Readable.prototype.unpipe = function (dest) {
  47900. var state = this._readableState;
  47901. var unpipeInfo = {
  47902. hasUnpiped: false
  47903. };
  47904. // if we're not piping anywhere, then do nothing.
  47905. if (state.pipesCount === 0) return this;
  47906. // just one destination. most common case.
  47907. if (state.pipesCount === 1) {
  47908. // passed in one, but it's not the right one.
  47909. if (dest && dest !== state.pipes) return this;
  47910. if (!dest) dest = state.pipes;
  47911. // got a match.
  47912. state.pipes = null;
  47913. state.pipesCount = 0;
  47914. state.flowing = false;
  47915. if (dest) dest.emit('unpipe', this, unpipeInfo);
  47916. return this;
  47917. }
  47918. // slow case. multiple pipe destinations.
  47919. if (!dest) {
  47920. // remove all.
  47921. var dests = state.pipes;
  47922. var len = state.pipesCount;
  47923. state.pipes = null;
  47924. state.pipesCount = 0;
  47925. state.flowing = false;
  47926. for (var i = 0; i < len; i++) dests[i].emit('unpipe', this, {
  47927. hasUnpiped: false
  47928. });
  47929. return this;
  47930. }
  47931. // try to find the right one.
  47932. var index = indexOf(state.pipes, dest);
  47933. if (index === -1) return this;
  47934. state.pipes.splice(index, 1);
  47935. state.pipesCount -= 1;
  47936. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  47937. dest.emit('unpipe', this, unpipeInfo);
  47938. return this;
  47939. };
  47940. // set up data events if they are asked for
  47941. // Ensure readable listeners eventually get something
  47942. Readable.prototype.on = function (ev, fn) {
  47943. var res = Stream.prototype.on.call(this, ev, fn);
  47944. var state = this._readableState;
  47945. if (ev === 'data') {
  47946. // update readableListening so that resume() may be a no-op
  47947. // a few lines down. This is needed to support once('readable').
  47948. state.readableListening = this.listenerCount('readable') > 0;
  47949. // Try start flowing on next tick if stream isn't explicitly paused
  47950. if (state.flowing !== false) this.resume();
  47951. } else if (ev === 'readable') {
  47952. if (!state.endEmitted && !state.readableListening) {
  47953. state.readableListening = state.needReadable = true;
  47954. state.flowing = false;
  47955. state.emittedReadable = false;
  47956. debug('on readable', state.length, state.reading);
  47957. if (state.length) {
  47958. emitReadable(this);
  47959. } else if (!state.reading) {
  47960. process.nextTick(nReadingNextTick, this);
  47961. }
  47962. }
  47963. }
  47964. return res;
  47965. };
  47966. Readable.prototype.addListener = Readable.prototype.on;
  47967. Readable.prototype.removeListener = function (ev, fn) {
  47968. var res = Stream.prototype.removeListener.call(this, ev, fn);
  47969. if (ev === 'readable') {
  47970. // We need to check if there is someone still listening to
  47971. // readable and reset the state. However this needs to happen
  47972. // after readable has been emitted but before I/O (nextTick) to
  47973. // support once('readable', fn) cycles. This means that calling
  47974. // resume within the same tick will have no
  47975. // effect.
  47976. process.nextTick(updateReadableListening, this);
  47977. }
  47978. return res;
  47979. };
  47980. Readable.prototype.removeAllListeners = function (ev) {
  47981. var res = Stream.prototype.removeAllListeners.apply(this, arguments);
  47982. if (ev === 'readable' || ev === undefined) {
  47983. // We need to check if there is someone still listening to
  47984. // readable and reset the state. However this needs to happen
  47985. // after readable has been emitted but before I/O (nextTick) to
  47986. // support once('readable', fn) cycles. This means that calling
  47987. // resume within the same tick will have no
  47988. // effect.
  47989. process.nextTick(updateReadableListening, this);
  47990. }
  47991. return res;
  47992. };
  47993. function updateReadableListening(self) {
  47994. var state = self._readableState;
  47995. state.readableListening = self.listenerCount('readable') > 0;
  47996. if (state.resumeScheduled && !state.paused) {
  47997. // flowing needs to be set to true now, otherwise
  47998. // the upcoming resume will not flow.
  47999. state.flowing = true;
  48000. // crude way to check if we should resume
  48001. } else if (self.listenerCount('data') > 0) {
  48002. self.resume();
  48003. }
  48004. }
  48005. function nReadingNextTick(self) {
  48006. debug('readable nexttick read 0');
  48007. self.read(0);
  48008. }
  48009. // pause() and resume() are remnants of the legacy readable stream API
  48010. // If the user uses them, then switch into old mode.
  48011. Readable.prototype.resume = function () {
  48012. var state = this._readableState;
  48013. if (!state.flowing) {
  48014. debug('resume');
  48015. // we flow only if there is no one listening
  48016. // for readable, but we still have to call
  48017. // resume()
  48018. state.flowing = !state.readableListening;
  48019. resume(this, state);
  48020. }
  48021. state.paused = false;
  48022. return this;
  48023. };
  48024. function resume(stream, state) {
  48025. if (!state.resumeScheduled) {
  48026. state.resumeScheduled = true;
  48027. process.nextTick(resume_, stream, state);
  48028. }
  48029. }
  48030. function resume_(stream, state) {
  48031. debug('resume', state.reading);
  48032. if (!state.reading) {
  48033. stream.read(0);
  48034. }
  48035. state.resumeScheduled = false;
  48036. stream.emit('resume');
  48037. flow(stream);
  48038. if (state.flowing && !state.reading) stream.read(0);
  48039. }
  48040. Readable.prototype.pause = function () {
  48041. debug('call pause flowing=%j', this._readableState.flowing);
  48042. if (this._readableState.flowing !== false) {
  48043. debug('pause');
  48044. this._readableState.flowing = false;
  48045. this.emit('pause');
  48046. }
  48047. this._readableState.paused = true;
  48048. return this;
  48049. };
  48050. function flow(stream) {
  48051. var state = stream._readableState;
  48052. debug('flow', state.flowing);
  48053. while (state.flowing && stream.read() !== null);
  48054. }
  48055. // wrap an old-style stream as the async data source.
  48056. // This is *not* part of the readable stream interface.
  48057. // It is an ugly unfortunate mess of history.
  48058. Readable.prototype.wrap = function (stream) {
  48059. var _this = this;
  48060. var state = this._readableState;
  48061. var paused = false;
  48062. stream.on('end', function () {
  48063. debug('wrapped end');
  48064. if (state.decoder && !state.ended) {
  48065. var chunk = state.decoder.end();
  48066. if (chunk && chunk.length) _this.push(chunk);
  48067. }
  48068. _this.push(null);
  48069. });
  48070. stream.on('data', function (chunk) {
  48071. debug('wrapped data');
  48072. if (state.decoder) chunk = state.decoder.write(chunk);
  48073. // don't skip over falsy values in objectMode
  48074. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  48075. var ret = _this.push(chunk);
  48076. if (!ret) {
  48077. paused = true;
  48078. stream.pause();
  48079. }
  48080. });
  48081. // proxy all the other methods.
  48082. // important when wrapping filters and duplexes.
  48083. for (var i in stream) {
  48084. if (this[i] === undefined && typeof stream[i] === 'function') {
  48085. this[i] = function methodWrap(method) {
  48086. return function methodWrapReturnFunction() {
  48087. return stream[method].apply(stream, arguments);
  48088. };
  48089. }(i);
  48090. }
  48091. }
  48092. // proxy certain important events.
  48093. for (var n = 0; n < kProxyEvents.length; n++) {
  48094. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  48095. }
  48096. // when we try to consume some more bytes, simply unpause the
  48097. // underlying stream.
  48098. this._read = function (n) {
  48099. debug('wrapped _read', n);
  48100. if (paused) {
  48101. paused = false;
  48102. stream.resume();
  48103. }
  48104. };
  48105. return this;
  48106. };
  48107. if (typeof Symbol === 'function') {
  48108. Readable.prototype[Symbol.asyncIterator] = function () {
  48109. if (createReadableStreamAsyncIterator === undefined) {
  48110. createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
  48111. }
  48112. return createReadableStreamAsyncIterator(this);
  48113. };
  48114. }
  48115. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  48116. // making it explicit this property is not enumerable
  48117. // because otherwise some prototype manipulation in
  48118. // userland will fail
  48119. enumerable: false,
  48120. get: function get() {
  48121. return this._readableState.highWaterMark;
  48122. }
  48123. });
  48124. Object.defineProperty(Readable.prototype, 'readableBuffer', {
  48125. // making it explicit this property is not enumerable
  48126. // because otherwise some prototype manipulation in
  48127. // userland will fail
  48128. enumerable: false,
  48129. get: function get() {
  48130. return this._readableState && this._readableState.buffer;
  48131. }
  48132. });
  48133. Object.defineProperty(Readable.prototype, 'readableFlowing', {
  48134. // making it explicit this property is not enumerable
  48135. // because otherwise some prototype manipulation in
  48136. // userland will fail
  48137. enumerable: false,
  48138. get: function get() {
  48139. return this._readableState.flowing;
  48140. },
  48141. set: function set(state) {
  48142. if (this._readableState) {
  48143. this._readableState.flowing = state;
  48144. }
  48145. }
  48146. });
  48147. // exposed for testing purposes only.
  48148. Readable._fromList = fromList;
  48149. Object.defineProperty(Readable.prototype, 'readableLength', {
  48150. // making it explicit this property is not enumerable
  48151. // because otherwise some prototype manipulation in
  48152. // userland will fail
  48153. enumerable: false,
  48154. get: function get() {
  48155. return this._readableState.length;
  48156. }
  48157. });
  48158. // Pluck off n bytes from an array of buffers.
  48159. // Length is the combined lengths of all the buffers in the list.
  48160. // This function is designed to be inlinable, so please take care when making
  48161. // changes to the function body.
  48162. function fromList(n, state) {
  48163. // nothing buffered
  48164. if (state.length === 0) return null;
  48165. var ret;
  48166. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  48167. // read it all, truncate the list
  48168. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
  48169. state.buffer.clear();
  48170. } else {
  48171. // read part of list
  48172. ret = state.buffer.consume(n, state.decoder);
  48173. }
  48174. return ret;
  48175. }
  48176. function endReadable(stream) {
  48177. var state = stream._readableState;
  48178. debug('endReadable', state.endEmitted);
  48179. if (!state.endEmitted) {
  48180. state.ended = true;
  48181. process.nextTick(endReadableNT, state, stream);
  48182. }
  48183. }
  48184. function endReadableNT(state, stream) {
  48185. debug('endReadableNT', state.endEmitted, state.length);
  48186. // Check that we didn't get one last unshift.
  48187. if (!state.endEmitted && state.length === 0) {
  48188. state.endEmitted = true;
  48189. stream.readable = false;
  48190. stream.emit('end');
  48191. if (state.autoDestroy) {
  48192. // In case of duplex streams we need a way to detect
  48193. // if the writable side is ready for autoDestroy as well
  48194. var wState = stream._writableState;
  48195. if (!wState || wState.autoDestroy && wState.finished) {
  48196. stream.destroy();
  48197. }
  48198. }
  48199. }
  48200. }
  48201. if (typeof Symbol === 'function') {
  48202. Readable.from = function (iterable, opts) {
  48203. if (from === undefined) {
  48204. from = require('./internal/streams/from');
  48205. }
  48206. return from(Readable, iterable, opts);
  48207. };
  48208. }
  48209. function indexOf(xs, x) {
  48210. for (var i = 0, l = xs.length; i < l; i++) {
  48211. if (xs[i] === x) return i;
  48212. }
  48213. return -1;
  48214. }
  48215. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  48216. },{"../errors":477,"./_stream_duplex":478,"./internal/streams/async_iterator":483,"./internal/streams/buffer_list":484,"./internal/streams/destroy":485,"./internal/streams/from":487,"./internal/streams/state":489,"./internal/streams/stream":490,"_process":467,"buffer":220,"events":422,"inherits":440,"string_decoder/":522,"util":188}],481:[function(require,module,exports){
  48217. // Copyright Joyent, Inc. and other Node contributors.
  48218. //
  48219. // Permission is hereby granted, free of charge, to any person obtaining a
  48220. // copy of this software and associated documentation files (the
  48221. // "Software"), to deal in the Software without restriction, including
  48222. // without limitation the rights to use, copy, modify, merge, publish,
  48223. // distribute, sublicense, and/or sell copies of the Software, and to permit
  48224. // persons to whom the Software is furnished to do so, subject to the
  48225. // following conditions:
  48226. //
  48227. // The above copyright notice and this permission notice shall be included
  48228. // in all copies or substantial portions of the Software.
  48229. //
  48230. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  48231. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  48232. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  48233. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  48234. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  48235. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  48236. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  48237. // a transform stream is a readable/writable stream where you do
  48238. // something with the data. Sometimes it's called a "filter",
  48239. // but that's not a great name for it, since that implies a thing where
  48240. // some bits pass through, and others are simply ignored. (That would
  48241. // be a valid example of a transform, of course.)
  48242. //
  48243. // While the output is causally related to the input, it's not a
  48244. // necessarily symmetric or synchronous transformation. For example,
  48245. // a zlib stream might take multiple plain-text writes(), and then
  48246. // emit a single compressed chunk some time in the future.
  48247. //
  48248. // Here's how this works:
  48249. //
  48250. // The Transform stream has all the aspects of the readable and writable
  48251. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  48252. // internally, and returns false if there's a lot of pending writes
  48253. // buffered up. When you call read(), that calls _read(n) until
  48254. // there's enough pending readable data buffered up.
  48255. //
  48256. // In a transform stream, the written data is placed in a buffer. When
  48257. // _read(n) is called, it transforms the queued up data, calling the
  48258. // buffered _write cb's as it consumes chunks. If consuming a single
  48259. // written chunk would result in multiple output chunks, then the first
  48260. // outputted bit calls the readcb, and subsequent chunks just go into
  48261. // the read buffer, and will cause it to emit 'readable' if necessary.
  48262. //
  48263. // This way, back-pressure is actually determined by the reading side,
  48264. // since _read has to be called to start processing a new chunk. However,
  48265. // a pathological inflate type of transform can cause excessive buffering
  48266. // here. For example, imagine a stream where every byte of input is
  48267. // interpreted as an integer from 0-255, and then results in that many
  48268. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  48269. // 1kb of data being output. In this case, you could write a very small
  48270. // amount of input, and end up with a very large amount of output. In
  48271. // such a pathological inflating mechanism, there'd be no way to tell
  48272. // the system to stop doing the transform. A single 4MB write could
  48273. // cause the system to run out of memory.
  48274. //
  48275. // However, even in such a pathological case, only a single written chunk
  48276. // would be consumed, and then the rest would wait (un-transformed) until
  48277. // the results of the previous transformed chunk were consumed.
  48278. 'use strict';
  48279. module.exports = Transform;
  48280. var _require$codes = require('../errors').codes,
  48281. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  48282. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  48283. ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
  48284. ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
  48285. var Duplex = require('./_stream_duplex');
  48286. require('inherits')(Transform, Duplex);
  48287. function afterTransform(er, data) {
  48288. var ts = this._transformState;
  48289. ts.transforming = false;
  48290. var cb = ts.writecb;
  48291. if (cb === null) {
  48292. return this.emit('error', new ERR_MULTIPLE_CALLBACK());
  48293. }
  48294. ts.writechunk = null;
  48295. ts.writecb = null;
  48296. if (data != null)
  48297. // single equals check for both `null` and `undefined`
  48298. this.push(data);
  48299. cb(er);
  48300. var rs = this._readableState;
  48301. rs.reading = false;
  48302. if (rs.needReadable || rs.length < rs.highWaterMark) {
  48303. this._read(rs.highWaterMark);
  48304. }
  48305. }
  48306. function Transform(options) {
  48307. if (!(this instanceof Transform)) return new Transform(options);
  48308. Duplex.call(this, options);
  48309. this._transformState = {
  48310. afterTransform: afterTransform.bind(this),
  48311. needTransform: false,
  48312. transforming: false,
  48313. writecb: null,
  48314. writechunk: null,
  48315. writeencoding: null
  48316. };
  48317. // start out asking for a readable event once data is transformed.
  48318. this._readableState.needReadable = true;
  48319. // we have implemented the _read method, and done the other things
  48320. // that Readable wants before the first _read call, so unset the
  48321. // sync guard flag.
  48322. this._readableState.sync = false;
  48323. if (options) {
  48324. if (typeof options.transform === 'function') this._transform = options.transform;
  48325. if (typeof options.flush === 'function') this._flush = options.flush;
  48326. }
  48327. // When the writable side finishes, then flush out anything remaining.
  48328. this.on('prefinish', prefinish);
  48329. }
  48330. function prefinish() {
  48331. var _this = this;
  48332. if (typeof this._flush === 'function' && !this._readableState.destroyed) {
  48333. this._flush(function (er, data) {
  48334. done(_this, er, data);
  48335. });
  48336. } else {
  48337. done(this, null, null);
  48338. }
  48339. }
  48340. Transform.prototype.push = function (chunk, encoding) {
  48341. this._transformState.needTransform = false;
  48342. return Duplex.prototype.push.call(this, chunk, encoding);
  48343. };
  48344. // This is the part where you do stuff!
  48345. // override this function in implementation classes.
  48346. // 'chunk' is an input chunk.
  48347. //
  48348. // Call `push(newChunk)` to pass along transformed output
  48349. // to the readable side. You may call 'push' zero or more times.
  48350. //
  48351. // Call `cb(err)` when you are done with this chunk. If you pass
  48352. // an error, then that'll put the hurt on the whole operation. If you
  48353. // never call cb(), then you'll never get another chunk.
  48354. Transform.prototype._transform = function (chunk, encoding, cb) {
  48355. cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
  48356. };
  48357. Transform.prototype._write = function (chunk, encoding, cb) {
  48358. var ts = this._transformState;
  48359. ts.writecb = cb;
  48360. ts.writechunk = chunk;
  48361. ts.writeencoding = encoding;
  48362. if (!ts.transforming) {
  48363. var rs = this._readableState;
  48364. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  48365. }
  48366. };
  48367. // Doesn't matter what the args are here.
  48368. // _transform does all the work.
  48369. // That we got here means that the readable side wants more data.
  48370. Transform.prototype._read = function (n) {
  48371. var ts = this._transformState;
  48372. if (ts.writechunk !== null && !ts.transforming) {
  48373. ts.transforming = true;
  48374. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  48375. } else {
  48376. // mark that we need a transform, so that any data that comes in
  48377. // will get processed, now that we've asked for it.
  48378. ts.needTransform = true;
  48379. }
  48380. };
  48381. Transform.prototype._destroy = function (err, cb) {
  48382. Duplex.prototype._destroy.call(this, err, function (err2) {
  48383. cb(err2);
  48384. });
  48385. };
  48386. function done(stream, er, data) {
  48387. if (er) return stream.emit('error', er);
  48388. if (data != null)
  48389. // single equals check for both `null` and `undefined`
  48390. stream.push(data);
  48391. // TODO(BridgeAR): Write a test for these two error cases
  48392. // if there's nothing in the write buffer, then that means
  48393. // that nothing more will ever be provided
  48394. if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
  48395. if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
  48396. return stream.push(null);
  48397. }
  48398. },{"../errors":477,"./_stream_duplex":478,"inherits":440}],482:[function(require,module,exports){
  48399. (function (process,global){(function (){
  48400. // Copyright Joyent, Inc. and other Node contributors.
  48401. //
  48402. // Permission is hereby granted, free of charge, to any person obtaining a
  48403. // copy of this software and associated documentation files (the
  48404. // "Software"), to deal in the Software without restriction, including
  48405. // without limitation the rights to use, copy, modify, merge, publish,
  48406. // distribute, sublicense, and/or sell copies of the Software, and to permit
  48407. // persons to whom the Software is furnished to do so, subject to the
  48408. // following conditions:
  48409. //
  48410. // The above copyright notice and this permission notice shall be included
  48411. // in all copies or substantial portions of the Software.
  48412. //
  48413. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  48414. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  48415. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  48416. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  48417. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  48418. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  48419. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  48420. // A bit simpler than readable streams.
  48421. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  48422. // the drain event emission and buffering.
  48423. 'use strict';
  48424. module.exports = Writable;
  48425. /* <replacement> */
  48426. function WriteReq(chunk, encoding, cb) {
  48427. this.chunk = chunk;
  48428. this.encoding = encoding;
  48429. this.callback = cb;
  48430. this.next = null;
  48431. }
  48432. // It seems a linked list but it is not
  48433. // there will be only 2 of these for each stream
  48434. function CorkedRequest(state) {
  48435. var _this = this;
  48436. this.next = null;
  48437. this.entry = null;
  48438. this.finish = function () {
  48439. onCorkedFinish(_this, state);
  48440. };
  48441. }
  48442. /* </replacement> */
  48443. /*<replacement>*/
  48444. var Duplex;
  48445. /*</replacement>*/
  48446. Writable.WritableState = WritableState;
  48447. /*<replacement>*/
  48448. var internalUtil = {
  48449. deprecate: require('util-deprecate')
  48450. };
  48451. /*</replacement>*/
  48452. /*<replacement>*/
  48453. var Stream = require('./internal/streams/stream');
  48454. /*</replacement>*/
  48455. var Buffer = require('buffer').Buffer;
  48456. var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
  48457. function _uint8ArrayToBuffer(chunk) {
  48458. return Buffer.from(chunk);
  48459. }
  48460. function _isUint8Array(obj) {
  48461. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  48462. }
  48463. var destroyImpl = require('./internal/streams/destroy');
  48464. var _require = require('./internal/streams/state'),
  48465. getHighWaterMark = _require.getHighWaterMark;
  48466. var _require$codes = require('../errors').codes,
  48467. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  48468. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  48469. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  48470. ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
  48471. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
  48472. ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
  48473. ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
  48474. ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
  48475. var errorOrDestroy = destroyImpl.errorOrDestroy;
  48476. require('inherits')(Writable, Stream);
  48477. function nop() {}
  48478. function WritableState(options, stream, isDuplex) {
  48479. Duplex = Duplex || require('./_stream_duplex');
  48480. options = options || {};
  48481. // Duplex streams are both readable and writable, but share
  48482. // the same options object.
  48483. // However, some cases require setting options to different
  48484. // values for the readable and the writable sides of the duplex stream,
  48485. // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
  48486. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
  48487. // object stream flag to indicate whether or not this stream
  48488. // contains buffers or objects.
  48489. this.objectMode = !!options.objectMode;
  48490. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  48491. // the point at which write() starts returning false
  48492. // Note: 0 is a valid value, means that we always return false if
  48493. // the entire buffer is not flushed immediately on write()
  48494. this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex);
  48495. // if _final has been called
  48496. this.finalCalled = false;
  48497. // drain event flag.
  48498. this.needDrain = false;
  48499. // at the start of calling end()
  48500. this.ending = false;
  48501. // when end() has been called, and returned
  48502. this.ended = false;
  48503. // when 'finish' is emitted
  48504. this.finished = false;
  48505. // has it been destroyed
  48506. this.destroyed = false;
  48507. // should we decode strings into buffers before passing to _write?
  48508. // this is here so that some node-core streams can optimize string
  48509. // handling at a lower level.
  48510. var noDecode = options.decodeStrings === false;
  48511. this.decodeStrings = !noDecode;
  48512. // Crypto is kind of old and crusty. Historically, its default string
  48513. // encoding is 'binary' so we have to make this configurable.
  48514. // Everything else in the universe uses 'utf8', though.
  48515. this.defaultEncoding = options.defaultEncoding || 'utf8';
  48516. // not an actual buffer we keep track of, but a measurement
  48517. // of how much we're waiting to get pushed to some underlying
  48518. // socket or file.
  48519. this.length = 0;
  48520. // a flag to see when we're in the middle of a write.
  48521. this.writing = false;
  48522. // when true all writes will be buffered until .uncork() call
  48523. this.corked = 0;
  48524. // a flag to be able to tell if the onwrite cb is called immediately,
  48525. // or on a later tick. We set this to true at first, because any
  48526. // actions that shouldn't happen until "later" should generally also
  48527. // not happen before the first write call.
  48528. this.sync = true;
  48529. // a flag to know if we're processing previously buffered items, which
  48530. // may call the _write() callback in the same tick, so that we don't
  48531. // end up in an overlapped onwrite situation.
  48532. this.bufferProcessing = false;
  48533. // the callback that's passed to _write(chunk,cb)
  48534. this.onwrite = function (er) {
  48535. onwrite(stream, er);
  48536. };
  48537. // the callback that the user supplies to write(chunk,encoding,cb)
  48538. this.writecb = null;
  48539. // the amount that is being written when _write is called.
  48540. this.writelen = 0;
  48541. this.bufferedRequest = null;
  48542. this.lastBufferedRequest = null;
  48543. // number of pending user-supplied write callbacks
  48544. // this must be 0 before 'finish' can be emitted
  48545. this.pendingcb = 0;
  48546. // emit prefinish if the only thing we're waiting for is _write cbs
  48547. // This is relevant for synchronous Transform streams
  48548. this.prefinished = false;
  48549. // True if the error was already emitted and should not be thrown again
  48550. this.errorEmitted = false;
  48551. // Should close be emitted on destroy. Defaults to true.
  48552. this.emitClose = options.emitClose !== false;
  48553. // Should .destroy() be called after 'finish' (and potentially 'end')
  48554. this.autoDestroy = !!options.autoDestroy;
  48555. // count buffered requests
  48556. this.bufferedRequestCount = 0;
  48557. // allocate the first CorkedRequest, there is always
  48558. // one allocated and free to use, and we maintain at most two
  48559. this.corkedRequestsFree = new CorkedRequest(this);
  48560. }
  48561. WritableState.prototype.getBuffer = function getBuffer() {
  48562. var current = this.bufferedRequest;
  48563. var out = [];
  48564. while (current) {
  48565. out.push(current);
  48566. current = current.next;
  48567. }
  48568. return out;
  48569. };
  48570. (function () {
  48571. try {
  48572. Object.defineProperty(WritableState.prototype, 'buffer', {
  48573. get: internalUtil.deprecate(function writableStateBufferGetter() {
  48574. return this.getBuffer();
  48575. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  48576. });
  48577. } catch (_) {}
  48578. })();
  48579. // Test _writableState for inheritance to account for Duplex streams,
  48580. // whose prototype chain only points to Readable.
  48581. var realHasInstance;
  48582. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  48583. realHasInstance = Function.prototype[Symbol.hasInstance];
  48584. Object.defineProperty(Writable, Symbol.hasInstance, {
  48585. value: function value(object) {
  48586. if (realHasInstance.call(this, object)) return true;
  48587. if (this !== Writable) return false;
  48588. return object && object._writableState instanceof WritableState;
  48589. }
  48590. });
  48591. } else {
  48592. realHasInstance = function realHasInstance(object) {
  48593. return object instanceof this;
  48594. };
  48595. }
  48596. function Writable(options) {
  48597. Duplex = Duplex || require('./_stream_duplex');
  48598. // Writable ctor is applied to Duplexes, too.
  48599. // `realHasInstance` is necessary because using plain `instanceof`
  48600. // would return false, as no `_writableState` property is attached.
  48601. // Trying to use the custom `instanceof` for Writable here will also break the
  48602. // Node.js LazyTransform implementation, which has a non-trivial getter for
  48603. // `_writableState` that would lead to infinite recursion.
  48604. // Checking for a Stream.Duplex instance is faster here instead of inside
  48605. // the WritableState constructor, at least with V8 6.5
  48606. var isDuplex = this instanceof Duplex;
  48607. if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
  48608. this._writableState = new WritableState(options, this, isDuplex);
  48609. // legacy.
  48610. this.writable = true;
  48611. if (options) {
  48612. if (typeof options.write === 'function') this._write = options.write;
  48613. if (typeof options.writev === 'function') this._writev = options.writev;
  48614. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  48615. if (typeof options.final === 'function') this._final = options.final;
  48616. }
  48617. Stream.call(this);
  48618. }
  48619. // Otherwise people can pipe Writable streams, which is just wrong.
  48620. Writable.prototype.pipe = function () {
  48621. errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
  48622. };
  48623. function writeAfterEnd(stream, cb) {
  48624. var er = new ERR_STREAM_WRITE_AFTER_END();
  48625. // TODO: defer error events consistently everywhere, not just the cb
  48626. errorOrDestroy(stream, er);
  48627. process.nextTick(cb, er);
  48628. }
  48629. // Checks that a user-supplied chunk is valid, especially for the particular
  48630. // mode the stream is in. Currently this means that `null` is never accepted
  48631. // and undefined/non-string values are only allowed in object mode.
  48632. function validChunk(stream, state, chunk, cb) {
  48633. var er;
  48634. if (chunk === null) {
  48635. er = new ERR_STREAM_NULL_VALUES();
  48636. } else if (typeof chunk !== 'string' && !state.objectMode) {
  48637. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
  48638. }
  48639. if (er) {
  48640. errorOrDestroy(stream, er);
  48641. process.nextTick(cb, er);
  48642. return false;
  48643. }
  48644. return true;
  48645. }
  48646. Writable.prototype.write = function (chunk, encoding, cb) {
  48647. var state = this._writableState;
  48648. var ret = false;
  48649. var isBuf = !state.objectMode && _isUint8Array(chunk);
  48650. if (isBuf && !Buffer.isBuffer(chunk)) {
  48651. chunk = _uint8ArrayToBuffer(chunk);
  48652. }
  48653. if (typeof encoding === 'function') {
  48654. cb = encoding;
  48655. encoding = null;
  48656. }
  48657. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  48658. if (typeof cb !== 'function') cb = nop;
  48659. if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  48660. state.pendingcb++;
  48661. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  48662. }
  48663. return ret;
  48664. };
  48665. Writable.prototype.cork = function () {
  48666. this._writableState.corked++;
  48667. };
  48668. Writable.prototype.uncork = function () {
  48669. var state = this._writableState;
  48670. if (state.corked) {
  48671. state.corked--;
  48672. if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  48673. }
  48674. };
  48675. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  48676. // node::ParseEncoding() requires lower case.
  48677. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  48678. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
  48679. this._writableState.defaultEncoding = encoding;
  48680. return this;
  48681. };
  48682. Object.defineProperty(Writable.prototype, 'writableBuffer', {
  48683. // making it explicit this property is not enumerable
  48684. // because otherwise some prototype manipulation in
  48685. // userland will fail
  48686. enumerable: false,
  48687. get: function get() {
  48688. return this._writableState && this._writableState.getBuffer();
  48689. }
  48690. });
  48691. function decodeChunk(state, chunk, encoding) {
  48692. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  48693. chunk = Buffer.from(chunk, encoding);
  48694. }
  48695. return chunk;
  48696. }
  48697. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  48698. // making it explicit this property is not enumerable
  48699. // because otherwise some prototype manipulation in
  48700. // userland will fail
  48701. enumerable: false,
  48702. get: function get() {
  48703. return this._writableState.highWaterMark;
  48704. }
  48705. });
  48706. // if we're already writing something, then just put this
  48707. // in the queue, and wait our turn. Otherwise, call _write
  48708. // If we return false, then we need a drain event, so set that flag.
  48709. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  48710. if (!isBuf) {
  48711. var newChunk = decodeChunk(state, chunk, encoding);
  48712. if (chunk !== newChunk) {
  48713. isBuf = true;
  48714. encoding = 'buffer';
  48715. chunk = newChunk;
  48716. }
  48717. }
  48718. var len = state.objectMode ? 1 : chunk.length;
  48719. state.length += len;
  48720. var ret = state.length < state.highWaterMark;
  48721. // we must ensure that previous needDrain will not be reset to false.
  48722. if (!ret) state.needDrain = true;
  48723. if (state.writing || state.corked) {
  48724. var last = state.lastBufferedRequest;
  48725. state.lastBufferedRequest = {
  48726. chunk: chunk,
  48727. encoding: encoding,
  48728. isBuf: isBuf,
  48729. callback: cb,
  48730. next: null
  48731. };
  48732. if (last) {
  48733. last.next = state.lastBufferedRequest;
  48734. } else {
  48735. state.bufferedRequest = state.lastBufferedRequest;
  48736. }
  48737. state.bufferedRequestCount += 1;
  48738. } else {
  48739. doWrite(stream, state, false, len, chunk, encoding, cb);
  48740. }
  48741. return ret;
  48742. }
  48743. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  48744. state.writelen = len;
  48745. state.writecb = cb;
  48746. state.writing = true;
  48747. state.sync = true;
  48748. if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  48749. state.sync = false;
  48750. }
  48751. function onwriteError(stream, state, sync, er, cb) {
  48752. --state.pendingcb;
  48753. if (sync) {
  48754. // defer the callback if we are being called synchronously
  48755. // to avoid piling up things on the stack
  48756. process.nextTick(cb, er);
  48757. // this can emit finish, and it will always happen
  48758. // after error
  48759. process.nextTick(finishMaybe, stream, state);
  48760. stream._writableState.errorEmitted = true;
  48761. errorOrDestroy(stream, er);
  48762. } else {
  48763. // the caller expect this to happen before if
  48764. // it is async
  48765. cb(er);
  48766. stream._writableState.errorEmitted = true;
  48767. errorOrDestroy(stream, er);
  48768. // this can emit finish, but finish must
  48769. // always follow error
  48770. finishMaybe(stream, state);
  48771. }
  48772. }
  48773. function onwriteStateUpdate(state) {
  48774. state.writing = false;
  48775. state.writecb = null;
  48776. state.length -= state.writelen;
  48777. state.writelen = 0;
  48778. }
  48779. function onwrite(stream, er) {
  48780. var state = stream._writableState;
  48781. var sync = state.sync;
  48782. var cb = state.writecb;
  48783. if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
  48784. onwriteStateUpdate(state);
  48785. if (er) onwriteError(stream, state, sync, er, cb);else {
  48786. // Check if we're actually ready to finish, but don't emit yet
  48787. var finished = needFinish(state) || stream.destroyed;
  48788. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  48789. clearBuffer(stream, state);
  48790. }
  48791. if (sync) {
  48792. process.nextTick(afterWrite, stream, state, finished, cb);
  48793. } else {
  48794. afterWrite(stream, state, finished, cb);
  48795. }
  48796. }
  48797. }
  48798. function afterWrite(stream, state, finished, cb) {
  48799. if (!finished) onwriteDrain(stream, state);
  48800. state.pendingcb--;
  48801. cb();
  48802. finishMaybe(stream, state);
  48803. }
  48804. // Must force callback to be called on nextTick, so that we don't
  48805. // emit 'drain' before the write() consumer gets the 'false' return
  48806. // value, and has a chance to attach a 'drain' listener.
  48807. function onwriteDrain(stream, state) {
  48808. if (state.length === 0 && state.needDrain) {
  48809. state.needDrain = false;
  48810. stream.emit('drain');
  48811. }
  48812. }
  48813. // if there's something in the buffer waiting, then process it
  48814. function clearBuffer(stream, state) {
  48815. state.bufferProcessing = true;
  48816. var entry = state.bufferedRequest;
  48817. if (stream._writev && entry && entry.next) {
  48818. // Fast case, write everything using _writev()
  48819. var l = state.bufferedRequestCount;
  48820. var buffer = new Array(l);
  48821. var holder = state.corkedRequestsFree;
  48822. holder.entry = entry;
  48823. var count = 0;
  48824. var allBuffers = true;
  48825. while (entry) {
  48826. buffer[count] = entry;
  48827. if (!entry.isBuf) allBuffers = false;
  48828. entry = entry.next;
  48829. count += 1;
  48830. }
  48831. buffer.allBuffers = allBuffers;
  48832. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  48833. // doWrite is almost always async, defer these to save a bit of time
  48834. // as the hot path ends with doWrite
  48835. state.pendingcb++;
  48836. state.lastBufferedRequest = null;
  48837. if (holder.next) {
  48838. state.corkedRequestsFree = holder.next;
  48839. holder.next = null;
  48840. } else {
  48841. state.corkedRequestsFree = new CorkedRequest(state);
  48842. }
  48843. state.bufferedRequestCount = 0;
  48844. } else {
  48845. // Slow case, write chunks one-by-one
  48846. while (entry) {
  48847. var chunk = entry.chunk;
  48848. var encoding = entry.encoding;
  48849. var cb = entry.callback;
  48850. var len = state.objectMode ? 1 : chunk.length;
  48851. doWrite(stream, state, false, len, chunk, encoding, cb);
  48852. entry = entry.next;
  48853. state.bufferedRequestCount--;
  48854. // if we didn't call the onwrite immediately, then
  48855. // it means that we need to wait until it does.
  48856. // also, that means that the chunk and cb are currently
  48857. // being processed, so move the buffer counter past them.
  48858. if (state.writing) {
  48859. break;
  48860. }
  48861. }
  48862. if (entry === null) state.lastBufferedRequest = null;
  48863. }
  48864. state.bufferedRequest = entry;
  48865. state.bufferProcessing = false;
  48866. }
  48867. Writable.prototype._write = function (chunk, encoding, cb) {
  48868. cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
  48869. };
  48870. Writable.prototype._writev = null;
  48871. Writable.prototype.end = function (chunk, encoding, cb) {
  48872. var state = this._writableState;
  48873. if (typeof chunk === 'function') {
  48874. cb = chunk;
  48875. chunk = null;
  48876. encoding = null;
  48877. } else if (typeof encoding === 'function') {
  48878. cb = encoding;
  48879. encoding = null;
  48880. }
  48881. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  48882. // .end() fully uncorks
  48883. if (state.corked) {
  48884. state.corked = 1;
  48885. this.uncork();
  48886. }
  48887. // ignore unnecessary end() calls.
  48888. if (!state.ending) endWritable(this, state, cb);
  48889. return this;
  48890. };
  48891. Object.defineProperty(Writable.prototype, 'writableLength', {
  48892. // making it explicit this property is not enumerable
  48893. // because otherwise some prototype manipulation in
  48894. // userland will fail
  48895. enumerable: false,
  48896. get: function get() {
  48897. return this._writableState.length;
  48898. }
  48899. });
  48900. function needFinish(state) {
  48901. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  48902. }
  48903. function callFinal(stream, state) {
  48904. stream._final(function (err) {
  48905. state.pendingcb--;
  48906. if (err) {
  48907. errorOrDestroy(stream, err);
  48908. }
  48909. state.prefinished = true;
  48910. stream.emit('prefinish');
  48911. finishMaybe(stream, state);
  48912. });
  48913. }
  48914. function prefinish(stream, state) {
  48915. if (!state.prefinished && !state.finalCalled) {
  48916. if (typeof stream._final === 'function' && !state.destroyed) {
  48917. state.pendingcb++;
  48918. state.finalCalled = true;
  48919. process.nextTick(callFinal, stream, state);
  48920. } else {
  48921. state.prefinished = true;
  48922. stream.emit('prefinish');
  48923. }
  48924. }
  48925. }
  48926. function finishMaybe(stream, state) {
  48927. var need = needFinish(state);
  48928. if (need) {
  48929. prefinish(stream, state);
  48930. if (state.pendingcb === 0) {
  48931. state.finished = true;
  48932. stream.emit('finish');
  48933. if (state.autoDestroy) {
  48934. // In case of duplex streams we need a way to detect
  48935. // if the readable side is ready for autoDestroy as well
  48936. var rState = stream._readableState;
  48937. if (!rState || rState.autoDestroy && rState.endEmitted) {
  48938. stream.destroy();
  48939. }
  48940. }
  48941. }
  48942. }
  48943. return need;
  48944. }
  48945. function endWritable(stream, state, cb) {
  48946. state.ending = true;
  48947. finishMaybe(stream, state);
  48948. if (cb) {
  48949. if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
  48950. }
  48951. state.ended = true;
  48952. stream.writable = false;
  48953. }
  48954. function onCorkedFinish(corkReq, state, err) {
  48955. var entry = corkReq.entry;
  48956. corkReq.entry = null;
  48957. while (entry) {
  48958. var cb = entry.callback;
  48959. state.pendingcb--;
  48960. cb(err);
  48961. entry = entry.next;
  48962. }
  48963. // reuse the free corkReq.
  48964. state.corkedRequestsFree.next = corkReq;
  48965. }
  48966. Object.defineProperty(Writable.prototype, 'destroyed', {
  48967. // making it explicit this property is not enumerable
  48968. // because otherwise some prototype manipulation in
  48969. // userland will fail
  48970. enumerable: false,
  48971. get: function get() {
  48972. if (this._writableState === undefined) {
  48973. return false;
  48974. }
  48975. return this._writableState.destroyed;
  48976. },
  48977. set: function set(value) {
  48978. // we ignore the value if the stream
  48979. // has not been initialized yet
  48980. if (!this._writableState) {
  48981. return;
  48982. }
  48983. // backward compatibility, the user is explicitly
  48984. // managing destroyed
  48985. this._writableState.destroyed = value;
  48986. }
  48987. });
  48988. Writable.prototype.destroy = destroyImpl.destroy;
  48989. Writable.prototype._undestroy = destroyImpl.undestroy;
  48990. Writable.prototype._destroy = function (err, cb) {
  48991. cb(err);
  48992. };
  48993. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  48994. },{"../errors":477,"./_stream_duplex":478,"./internal/streams/destroy":485,"./internal/streams/state":489,"./internal/streams/stream":490,"_process":467,"buffer":220,"inherits":440,"util-deprecate":524}],483:[function(require,module,exports){
  48995. (function (process){(function (){
  48996. 'use strict';
  48997. var _Object$setPrototypeO;
  48998. function _defineProperty(obj, key, value) {
  48999. key = _toPropertyKey(key);
  49000. if (key in obj) {
  49001. Object.defineProperty(obj, key, {
  49002. value: value,
  49003. enumerable: true,
  49004. configurable: true,
  49005. writable: true
  49006. });
  49007. } else {
  49008. obj[key] = value;
  49009. }
  49010. return obj;
  49011. }
  49012. function _toPropertyKey(arg) {
  49013. var key = _toPrimitive(arg, "string");
  49014. return typeof key === "symbol" ? key : String(key);
  49015. }
  49016. function _toPrimitive(input, hint) {
  49017. if (typeof input !== "object" || input === null) return input;
  49018. var prim = input[Symbol.toPrimitive];
  49019. if (prim !== undefined) {
  49020. var res = prim.call(input, hint || "default");
  49021. if (typeof res !== "object") return res;
  49022. throw new TypeError("@@toPrimitive must return a primitive value.");
  49023. }
  49024. return (hint === "string" ? String : Number)(input);
  49025. }
  49026. var finished = require('./end-of-stream');
  49027. var kLastResolve = Symbol('lastResolve');
  49028. var kLastReject = Symbol('lastReject');
  49029. var kError = Symbol('error');
  49030. var kEnded = Symbol('ended');
  49031. var kLastPromise = Symbol('lastPromise');
  49032. var kHandlePromise = Symbol('handlePromise');
  49033. var kStream = Symbol('stream');
  49034. function createIterResult(value, done) {
  49035. return {
  49036. value: value,
  49037. done: done
  49038. };
  49039. }
  49040. function readAndResolve(iter) {
  49041. var resolve = iter[kLastResolve];
  49042. if (resolve !== null) {
  49043. var data = iter[kStream].read();
  49044. // we defer if data is null
  49045. // we can be expecting either 'end' or
  49046. // 'error'
  49047. if (data !== null) {
  49048. iter[kLastPromise] = null;
  49049. iter[kLastResolve] = null;
  49050. iter[kLastReject] = null;
  49051. resolve(createIterResult(data, false));
  49052. }
  49053. }
  49054. }
  49055. function onReadable(iter) {
  49056. // we wait for the next tick, because it might
  49057. // emit an error with process.nextTick
  49058. process.nextTick(readAndResolve, iter);
  49059. }
  49060. function wrapForNext(lastPromise, iter) {
  49061. return function (resolve, reject) {
  49062. lastPromise.then(function () {
  49063. if (iter[kEnded]) {
  49064. resolve(createIterResult(undefined, true));
  49065. return;
  49066. }
  49067. iter[kHandlePromise](resolve, reject);
  49068. }, reject);
  49069. };
  49070. }
  49071. var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
  49072. var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
  49073. get stream() {
  49074. return this[kStream];
  49075. },
  49076. next: function next() {
  49077. var _this = this;
  49078. // if we have detected an error in the meanwhile
  49079. // reject straight away
  49080. var error = this[kError];
  49081. if (error !== null) {
  49082. return Promise.reject(error);
  49083. }
  49084. if (this[kEnded]) {
  49085. return Promise.resolve(createIterResult(undefined, true));
  49086. }
  49087. if (this[kStream].destroyed) {
  49088. // We need to defer via nextTick because if .destroy(err) is
  49089. // called, the error will be emitted via nextTick, and
  49090. // we cannot guarantee that there is no error lingering around
  49091. // waiting to be emitted.
  49092. return new Promise(function (resolve, reject) {
  49093. process.nextTick(function () {
  49094. if (_this[kError]) {
  49095. reject(_this[kError]);
  49096. } else {
  49097. resolve(createIterResult(undefined, true));
  49098. }
  49099. });
  49100. });
  49101. }
  49102. // if we have multiple next() calls
  49103. // we will wait for the previous Promise to finish
  49104. // this logic is optimized to support for await loops,
  49105. // where next() is only called once at a time
  49106. var lastPromise = this[kLastPromise];
  49107. var promise;
  49108. if (lastPromise) {
  49109. promise = new Promise(wrapForNext(lastPromise, this));
  49110. } else {
  49111. // fast path needed to support multiple this.push()
  49112. // without triggering the next() queue
  49113. var data = this[kStream].read();
  49114. if (data !== null) {
  49115. return Promise.resolve(createIterResult(data, false));
  49116. }
  49117. promise = new Promise(this[kHandlePromise]);
  49118. }
  49119. this[kLastPromise] = promise;
  49120. return promise;
  49121. }
  49122. }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
  49123. return this;
  49124. }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
  49125. var _this2 = this;
  49126. // destroy(err, cb) is a private API
  49127. // we can guarantee we have that here, because we control the
  49128. // Readable class this is attached to
  49129. return new Promise(function (resolve, reject) {
  49130. _this2[kStream].destroy(null, function (err) {
  49131. if (err) {
  49132. reject(err);
  49133. return;
  49134. }
  49135. resolve(createIterResult(undefined, true));
  49136. });
  49137. });
  49138. }), _Object$setPrototypeO), AsyncIteratorPrototype);
  49139. var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
  49140. var _Object$create;
  49141. var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
  49142. value: stream,
  49143. writable: true
  49144. }), _defineProperty(_Object$create, kLastResolve, {
  49145. value: null,
  49146. writable: true
  49147. }), _defineProperty(_Object$create, kLastReject, {
  49148. value: null,
  49149. writable: true
  49150. }), _defineProperty(_Object$create, kError, {
  49151. value: null,
  49152. writable: true
  49153. }), _defineProperty(_Object$create, kEnded, {
  49154. value: stream._readableState.endEmitted,
  49155. writable: true
  49156. }), _defineProperty(_Object$create, kHandlePromise, {
  49157. value: function value(resolve, reject) {
  49158. var data = iterator[kStream].read();
  49159. if (data) {
  49160. iterator[kLastPromise] = null;
  49161. iterator[kLastResolve] = null;
  49162. iterator[kLastReject] = null;
  49163. resolve(createIterResult(data, false));
  49164. } else {
  49165. iterator[kLastResolve] = resolve;
  49166. iterator[kLastReject] = reject;
  49167. }
  49168. },
  49169. writable: true
  49170. }), _Object$create));
  49171. iterator[kLastPromise] = null;
  49172. finished(stream, function (err) {
  49173. if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
  49174. var reject = iterator[kLastReject];
  49175. // reject if we are waiting for data in the Promise
  49176. // returned by next() and store the error
  49177. if (reject !== null) {
  49178. iterator[kLastPromise] = null;
  49179. iterator[kLastResolve] = null;
  49180. iterator[kLastReject] = null;
  49181. reject(err);
  49182. }
  49183. iterator[kError] = err;
  49184. return;
  49185. }
  49186. var resolve = iterator[kLastResolve];
  49187. if (resolve !== null) {
  49188. iterator[kLastPromise] = null;
  49189. iterator[kLastResolve] = null;
  49190. iterator[kLastReject] = null;
  49191. resolve(createIterResult(undefined, true));
  49192. }
  49193. iterator[kEnded] = true;
  49194. });
  49195. stream.on('readable', onReadable.bind(null, iterator));
  49196. return iterator;
  49197. };
  49198. module.exports = createReadableStreamAsyncIterator;
  49199. }).call(this)}).call(this,require('_process'))
  49200. },{"./end-of-stream":486,"_process":467}],484:[function(require,module,exports){
  49201. 'use strict';
  49202. function ownKeys(object, enumerableOnly) {
  49203. var keys = Object.keys(object);
  49204. if (Object.getOwnPropertySymbols) {
  49205. var symbols = Object.getOwnPropertySymbols(object);
  49206. enumerableOnly && (symbols = symbols.filter(function (sym) {
  49207. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  49208. })), keys.push.apply(keys, symbols);
  49209. }
  49210. return keys;
  49211. }
  49212. function _objectSpread(target) {
  49213. for (var i = 1; i < arguments.length; i++) {
  49214. var source = null != arguments[i] ? arguments[i] : {};
  49215. i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
  49216. _defineProperty(target, key, source[key]);
  49217. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
  49218. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  49219. });
  49220. }
  49221. return target;
  49222. }
  49223. function _defineProperty(obj, key, value) {
  49224. key = _toPropertyKey(key);
  49225. if (key in obj) {
  49226. Object.defineProperty(obj, key, {
  49227. value: value,
  49228. enumerable: true,
  49229. configurable: true,
  49230. writable: true
  49231. });
  49232. } else {
  49233. obj[key] = value;
  49234. }
  49235. return obj;
  49236. }
  49237. function _classCallCheck(instance, Constructor) {
  49238. if (!(instance instanceof Constructor)) {
  49239. throw new TypeError("Cannot call a class as a function");
  49240. }
  49241. }
  49242. function _defineProperties(target, props) {
  49243. for (var i = 0; i < props.length; i++) {
  49244. var descriptor = props[i];
  49245. descriptor.enumerable = descriptor.enumerable || false;
  49246. descriptor.configurable = true;
  49247. if ("value" in descriptor) descriptor.writable = true;
  49248. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  49249. }
  49250. }
  49251. function _createClass(Constructor, protoProps, staticProps) {
  49252. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  49253. if (staticProps) _defineProperties(Constructor, staticProps);
  49254. Object.defineProperty(Constructor, "prototype", {
  49255. writable: false
  49256. });
  49257. return Constructor;
  49258. }
  49259. function _toPropertyKey(arg) {
  49260. var key = _toPrimitive(arg, "string");
  49261. return typeof key === "symbol" ? key : String(key);
  49262. }
  49263. function _toPrimitive(input, hint) {
  49264. if (typeof input !== "object" || input === null) return input;
  49265. var prim = input[Symbol.toPrimitive];
  49266. if (prim !== undefined) {
  49267. var res = prim.call(input, hint || "default");
  49268. if (typeof res !== "object") return res;
  49269. throw new TypeError("@@toPrimitive must return a primitive value.");
  49270. }
  49271. return (hint === "string" ? String : Number)(input);
  49272. }
  49273. var _require = require('buffer'),
  49274. Buffer = _require.Buffer;
  49275. var _require2 = require('util'),
  49276. inspect = _require2.inspect;
  49277. var custom = inspect && inspect.custom || 'inspect';
  49278. function copyBuffer(src, target, offset) {
  49279. Buffer.prototype.copy.call(src, target, offset);
  49280. }
  49281. module.exports = /*#__PURE__*/function () {
  49282. function BufferList() {
  49283. _classCallCheck(this, BufferList);
  49284. this.head = null;
  49285. this.tail = null;
  49286. this.length = 0;
  49287. }
  49288. _createClass(BufferList, [{
  49289. key: "push",
  49290. value: function push(v) {
  49291. var entry = {
  49292. data: v,
  49293. next: null
  49294. };
  49295. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  49296. this.tail = entry;
  49297. ++this.length;
  49298. }
  49299. }, {
  49300. key: "unshift",
  49301. value: function unshift(v) {
  49302. var entry = {
  49303. data: v,
  49304. next: this.head
  49305. };
  49306. if (this.length === 0) this.tail = entry;
  49307. this.head = entry;
  49308. ++this.length;
  49309. }
  49310. }, {
  49311. key: "shift",
  49312. value: function shift() {
  49313. if (this.length === 0) return;
  49314. var ret = this.head.data;
  49315. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  49316. --this.length;
  49317. return ret;
  49318. }
  49319. }, {
  49320. key: "clear",
  49321. value: function clear() {
  49322. this.head = this.tail = null;
  49323. this.length = 0;
  49324. }
  49325. }, {
  49326. key: "join",
  49327. value: function join(s) {
  49328. if (this.length === 0) return '';
  49329. var p = this.head;
  49330. var ret = '' + p.data;
  49331. while (p = p.next) ret += s + p.data;
  49332. return ret;
  49333. }
  49334. }, {
  49335. key: "concat",
  49336. value: function concat(n) {
  49337. if (this.length === 0) return Buffer.alloc(0);
  49338. var ret = Buffer.allocUnsafe(n >>> 0);
  49339. var p = this.head;
  49340. var i = 0;
  49341. while (p) {
  49342. copyBuffer(p.data, ret, i);
  49343. i += p.data.length;
  49344. p = p.next;
  49345. }
  49346. return ret;
  49347. }
  49348. // Consumes a specified amount of bytes or characters from the buffered data.
  49349. }, {
  49350. key: "consume",
  49351. value: function consume(n, hasStrings) {
  49352. var ret;
  49353. if (n < this.head.data.length) {
  49354. // `slice` is the same for buffers and strings.
  49355. ret = this.head.data.slice(0, n);
  49356. this.head.data = this.head.data.slice(n);
  49357. } else if (n === this.head.data.length) {
  49358. // First chunk is a perfect match.
  49359. ret = this.shift();
  49360. } else {
  49361. // Result spans more than one buffer.
  49362. ret = hasStrings ? this._getString(n) : this._getBuffer(n);
  49363. }
  49364. return ret;
  49365. }
  49366. }, {
  49367. key: "first",
  49368. value: function first() {
  49369. return this.head.data;
  49370. }
  49371. // Consumes a specified amount of characters from the buffered data.
  49372. }, {
  49373. key: "_getString",
  49374. value: function _getString(n) {
  49375. var p = this.head;
  49376. var c = 1;
  49377. var ret = p.data;
  49378. n -= ret.length;
  49379. while (p = p.next) {
  49380. var str = p.data;
  49381. var nb = n > str.length ? str.length : n;
  49382. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  49383. n -= nb;
  49384. if (n === 0) {
  49385. if (nb === str.length) {
  49386. ++c;
  49387. if (p.next) this.head = p.next;else this.head = this.tail = null;
  49388. } else {
  49389. this.head = p;
  49390. p.data = str.slice(nb);
  49391. }
  49392. break;
  49393. }
  49394. ++c;
  49395. }
  49396. this.length -= c;
  49397. return ret;
  49398. }
  49399. // Consumes a specified amount of bytes from the buffered data.
  49400. }, {
  49401. key: "_getBuffer",
  49402. value: function _getBuffer(n) {
  49403. var ret = Buffer.allocUnsafe(n);
  49404. var p = this.head;
  49405. var c = 1;
  49406. p.data.copy(ret);
  49407. n -= p.data.length;
  49408. while (p = p.next) {
  49409. var buf = p.data;
  49410. var nb = n > buf.length ? buf.length : n;
  49411. buf.copy(ret, ret.length - n, 0, nb);
  49412. n -= nb;
  49413. if (n === 0) {
  49414. if (nb === buf.length) {
  49415. ++c;
  49416. if (p.next) this.head = p.next;else this.head = this.tail = null;
  49417. } else {
  49418. this.head = p;
  49419. p.data = buf.slice(nb);
  49420. }
  49421. break;
  49422. }
  49423. ++c;
  49424. }
  49425. this.length -= c;
  49426. return ret;
  49427. }
  49428. // Make sure the linked list only shows the minimal necessary information.
  49429. }, {
  49430. key: custom,
  49431. value: function value(_, options) {
  49432. return inspect(this, _objectSpread(_objectSpread({}, options), {}, {
  49433. // Only inspect one level.
  49434. depth: 0,
  49435. // It should not recurse.
  49436. customInspect: false
  49437. }));
  49438. }
  49439. }]);
  49440. return BufferList;
  49441. }();
  49442. },{"buffer":220,"util":188}],485:[function(require,module,exports){
  49443. (function (process){(function (){
  49444. 'use strict';
  49445. // undocumented cb() API, needed for core, not for public API
  49446. function destroy(err, cb) {
  49447. var _this = this;
  49448. var readableDestroyed = this._readableState && this._readableState.destroyed;
  49449. var writableDestroyed = this._writableState && this._writableState.destroyed;
  49450. if (readableDestroyed || writableDestroyed) {
  49451. if (cb) {
  49452. cb(err);
  49453. } else if (err) {
  49454. if (!this._writableState) {
  49455. process.nextTick(emitErrorNT, this, err);
  49456. } else if (!this._writableState.errorEmitted) {
  49457. this._writableState.errorEmitted = true;
  49458. process.nextTick(emitErrorNT, this, err);
  49459. }
  49460. }
  49461. return this;
  49462. }
  49463. // we set destroyed to true before firing error callbacks in order
  49464. // to make it re-entrance safe in case destroy() is called within callbacks
  49465. if (this._readableState) {
  49466. this._readableState.destroyed = true;
  49467. }
  49468. // if this is a duplex stream mark the writable part as destroyed as well
  49469. if (this._writableState) {
  49470. this._writableState.destroyed = true;
  49471. }
  49472. this._destroy(err || null, function (err) {
  49473. if (!cb && err) {
  49474. if (!_this._writableState) {
  49475. process.nextTick(emitErrorAndCloseNT, _this, err);
  49476. } else if (!_this._writableState.errorEmitted) {
  49477. _this._writableState.errorEmitted = true;
  49478. process.nextTick(emitErrorAndCloseNT, _this, err);
  49479. } else {
  49480. process.nextTick(emitCloseNT, _this);
  49481. }
  49482. } else if (cb) {
  49483. process.nextTick(emitCloseNT, _this);
  49484. cb(err);
  49485. } else {
  49486. process.nextTick(emitCloseNT, _this);
  49487. }
  49488. });
  49489. return this;
  49490. }
  49491. function emitErrorAndCloseNT(self, err) {
  49492. emitErrorNT(self, err);
  49493. emitCloseNT(self);
  49494. }
  49495. function emitCloseNT(self) {
  49496. if (self._writableState && !self._writableState.emitClose) return;
  49497. if (self._readableState && !self._readableState.emitClose) return;
  49498. self.emit('close');
  49499. }
  49500. function undestroy() {
  49501. if (this._readableState) {
  49502. this._readableState.destroyed = false;
  49503. this._readableState.reading = false;
  49504. this._readableState.ended = false;
  49505. this._readableState.endEmitted = false;
  49506. }
  49507. if (this._writableState) {
  49508. this._writableState.destroyed = false;
  49509. this._writableState.ended = false;
  49510. this._writableState.ending = false;
  49511. this._writableState.finalCalled = false;
  49512. this._writableState.prefinished = false;
  49513. this._writableState.finished = false;
  49514. this._writableState.errorEmitted = false;
  49515. }
  49516. }
  49517. function emitErrorNT(self, err) {
  49518. self.emit('error', err);
  49519. }
  49520. function errorOrDestroy(stream, err) {
  49521. // We have tests that rely on errors being emitted
  49522. // in the same tick, so changing this is semver major.
  49523. // For now when you opt-in to autoDestroy we allow
  49524. // the error to be emitted nextTick. In a future
  49525. // semver major update we should change the default to this.
  49526. var rState = stream._readableState;
  49527. var wState = stream._writableState;
  49528. if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
  49529. }
  49530. module.exports = {
  49531. destroy: destroy,
  49532. undestroy: undestroy,
  49533. errorOrDestroy: errorOrDestroy
  49534. };
  49535. }).call(this)}).call(this,require('_process'))
  49536. },{"_process":467}],486:[function(require,module,exports){
  49537. // Ported from https://github.com/mafintosh/end-of-stream with
  49538. // permission from the author, Mathias Buus (@mafintosh).
  49539. 'use strict';
  49540. var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
  49541. function once(callback) {
  49542. var called = false;
  49543. return function () {
  49544. if (called) return;
  49545. called = true;
  49546. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  49547. args[_key] = arguments[_key];
  49548. }
  49549. callback.apply(this, args);
  49550. };
  49551. }
  49552. function noop() {}
  49553. function isRequest(stream) {
  49554. return stream.setHeader && typeof stream.abort === 'function';
  49555. }
  49556. function eos(stream, opts, callback) {
  49557. if (typeof opts === 'function') return eos(stream, null, opts);
  49558. if (!opts) opts = {};
  49559. callback = once(callback || noop);
  49560. var readable = opts.readable || opts.readable !== false && stream.readable;
  49561. var writable = opts.writable || opts.writable !== false && stream.writable;
  49562. var onlegacyfinish = function onlegacyfinish() {
  49563. if (!stream.writable) onfinish();
  49564. };
  49565. var writableEnded = stream._writableState && stream._writableState.finished;
  49566. var onfinish = function onfinish() {
  49567. writable = false;
  49568. writableEnded = true;
  49569. if (!readable) callback.call(stream);
  49570. };
  49571. var readableEnded = stream._readableState && stream._readableState.endEmitted;
  49572. var onend = function onend() {
  49573. readable = false;
  49574. readableEnded = true;
  49575. if (!writable) callback.call(stream);
  49576. };
  49577. var onerror = function onerror(err) {
  49578. callback.call(stream, err);
  49579. };
  49580. var onclose = function onclose() {
  49581. var err;
  49582. if (readable && !readableEnded) {
  49583. if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  49584. return callback.call(stream, err);
  49585. }
  49586. if (writable && !writableEnded) {
  49587. if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  49588. return callback.call(stream, err);
  49589. }
  49590. };
  49591. var onrequest = function onrequest() {
  49592. stream.req.on('finish', onfinish);
  49593. };
  49594. if (isRequest(stream)) {
  49595. stream.on('complete', onfinish);
  49596. stream.on('abort', onclose);
  49597. if (stream.req) onrequest();else stream.on('request', onrequest);
  49598. } else if (writable && !stream._writableState) {
  49599. // legacy streams
  49600. stream.on('end', onlegacyfinish);
  49601. stream.on('close', onlegacyfinish);
  49602. }
  49603. stream.on('end', onend);
  49604. stream.on('finish', onfinish);
  49605. if (opts.error !== false) stream.on('error', onerror);
  49606. stream.on('close', onclose);
  49607. return function () {
  49608. stream.removeListener('complete', onfinish);
  49609. stream.removeListener('abort', onclose);
  49610. stream.removeListener('request', onrequest);
  49611. if (stream.req) stream.req.removeListener('finish', onfinish);
  49612. stream.removeListener('end', onlegacyfinish);
  49613. stream.removeListener('close', onlegacyfinish);
  49614. stream.removeListener('finish', onfinish);
  49615. stream.removeListener('end', onend);
  49616. stream.removeListener('error', onerror);
  49617. stream.removeListener('close', onclose);
  49618. };
  49619. }
  49620. module.exports = eos;
  49621. },{"../../../errors":477}],487:[function(require,module,exports){
  49622. "use strict";
  49623. module.exports = function () {
  49624. throw new Error('Readable.from is not available in the browser');
  49625. };
  49626. },{}],488:[function(require,module,exports){
  49627. // Ported from https://github.com/mafintosh/pump with
  49628. // permission from the author, Mathias Buus (@mafintosh).
  49629. 'use strict';
  49630. var eos;
  49631. function once(callback) {
  49632. var called = false;
  49633. return function () {
  49634. if (called) return;
  49635. called = true;
  49636. callback.apply(void 0, arguments);
  49637. };
  49638. }
  49639. var _require$codes = require('../../../errors').codes,
  49640. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
  49641. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
  49642. function noop(err) {
  49643. // Rethrow the error if it exists to avoid swallowing it
  49644. if (err) throw err;
  49645. }
  49646. function isRequest(stream) {
  49647. return stream.setHeader && typeof stream.abort === 'function';
  49648. }
  49649. function destroyer(stream, reading, writing, callback) {
  49650. callback = once(callback);
  49651. var closed = false;
  49652. stream.on('close', function () {
  49653. closed = true;
  49654. });
  49655. if (eos === undefined) eos = require('./end-of-stream');
  49656. eos(stream, {
  49657. readable: reading,
  49658. writable: writing
  49659. }, function (err) {
  49660. if (err) return callback(err);
  49661. closed = true;
  49662. callback();
  49663. });
  49664. var destroyed = false;
  49665. return function (err) {
  49666. if (closed) return;
  49667. if (destroyed) return;
  49668. destroyed = true;
  49669. // request.destroy just do .end - .abort is what we want
  49670. if (isRequest(stream)) return stream.abort();
  49671. if (typeof stream.destroy === 'function') return stream.destroy();
  49672. callback(err || new ERR_STREAM_DESTROYED('pipe'));
  49673. };
  49674. }
  49675. function call(fn) {
  49676. fn();
  49677. }
  49678. function pipe(from, to) {
  49679. return from.pipe(to);
  49680. }
  49681. function popCallback(streams) {
  49682. if (!streams.length) return noop;
  49683. if (typeof streams[streams.length - 1] !== 'function') return noop;
  49684. return streams.pop();
  49685. }
  49686. function pipeline() {
  49687. for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
  49688. streams[_key] = arguments[_key];
  49689. }
  49690. var callback = popCallback(streams);
  49691. if (Array.isArray(streams[0])) streams = streams[0];
  49692. if (streams.length < 2) {
  49693. throw new ERR_MISSING_ARGS('streams');
  49694. }
  49695. var error;
  49696. var destroys = streams.map(function (stream, i) {
  49697. var reading = i < streams.length - 1;
  49698. var writing = i > 0;
  49699. return destroyer(stream, reading, writing, function (err) {
  49700. if (!error) error = err;
  49701. if (err) destroys.forEach(call);
  49702. if (reading) return;
  49703. destroys.forEach(call);
  49704. callback(error);
  49705. });
  49706. });
  49707. return streams.reduce(pipe);
  49708. }
  49709. module.exports = pipeline;
  49710. },{"../../../errors":477,"./end-of-stream":486}],489:[function(require,module,exports){
  49711. 'use strict';
  49712. var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
  49713. function highWaterMarkFrom(options, isDuplex, duplexKey) {
  49714. return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
  49715. }
  49716. function getHighWaterMark(state, options, duplexKey, isDuplex) {
  49717. var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
  49718. if (hwm != null) {
  49719. if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
  49720. var name = isDuplex ? duplexKey : 'highWaterMark';
  49721. throw new ERR_INVALID_OPT_VALUE(name, hwm);
  49722. }
  49723. return Math.floor(hwm);
  49724. }
  49725. // Default value
  49726. return state.objectMode ? 16 : 16 * 1024;
  49727. }
  49728. module.exports = {
  49729. getHighWaterMark: getHighWaterMark
  49730. };
  49731. },{"../../../errors":477}],490:[function(require,module,exports){
  49732. "use strict";
  49733. module.exports = require('events').EventEmitter;
  49734. },{"events":422}],491:[function(require,module,exports){
  49735. "use strict";
  49736. exports = module.exports = require('./lib/_stream_readable.js');
  49737. exports.Stream = exports;
  49738. exports.Readable = exports;
  49739. exports.Writable = require('./lib/_stream_writable.js');
  49740. exports.Duplex = require('./lib/_stream_duplex.js');
  49741. exports.Transform = require('./lib/_stream_transform.js');
  49742. exports.PassThrough = require('./lib/_stream_passthrough.js');
  49743. exports.finished = require('./lib/internal/streams/end-of-stream.js');
  49744. exports.pipeline = require('./lib/internal/streams/pipeline.js');
  49745. },{"./lib/_stream_duplex.js":478,"./lib/_stream_passthrough.js":479,"./lib/_stream_readable.js":480,"./lib/_stream_transform.js":481,"./lib/_stream_writable.js":482,"./lib/internal/streams/end-of-stream.js":486,"./lib/internal/streams/pipeline.js":488}],492:[function(require,module,exports){
  49746. "use strict";
  49747. /**
  49748. * Copyright (c) 2014-present, Facebook, Inc.
  49749. *
  49750. * This source code is licensed under the MIT license found in the
  49751. * LICENSE file in the root directory of this source tree.
  49752. */
  49753. var runtime = function (exports) {
  49754. "use strict";
  49755. var Op = Object.prototype;
  49756. var hasOwn = Op.hasOwnProperty;
  49757. var defineProperty = Object.defineProperty || function (obj, key, desc) {
  49758. obj[key] = desc.value;
  49759. };
  49760. var undefined; // More compressible than void 0.
  49761. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  49762. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  49763. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  49764. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  49765. function define(obj, key, value) {
  49766. Object.defineProperty(obj, key, {
  49767. value: value,
  49768. enumerable: true,
  49769. configurable: true,
  49770. writable: true
  49771. });
  49772. return obj[key];
  49773. }
  49774. try {
  49775. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  49776. define({}, "");
  49777. } catch (err) {
  49778. define = function (obj, key, value) {
  49779. return obj[key] = value;
  49780. };
  49781. }
  49782. function wrap(innerFn, outerFn, self, tryLocsList) {
  49783. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  49784. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  49785. var generator = Object.create(protoGenerator.prototype);
  49786. var context = new Context(tryLocsList || []);
  49787. // The ._invoke method unifies the implementations of the .next,
  49788. // .throw, and .return methods.
  49789. defineProperty(generator, "_invoke", {
  49790. value: makeInvokeMethod(innerFn, self, context)
  49791. });
  49792. return generator;
  49793. }
  49794. exports.wrap = wrap;
  49795. // Try/catch helper to minimize deoptimizations. Returns a completion
  49796. // record like context.tryEntries[i].completion. This interface could
  49797. // have been (and was previously) designed to take a closure to be
  49798. // invoked without arguments, but in all the cases we care about we
  49799. // already have an existing method we want to call, so there's no need
  49800. // to create a new function object. We can even get away with assuming
  49801. // the method takes exactly one argument, since that happens to be true
  49802. // in every case, so we don't have to touch the arguments object. The
  49803. // only additional allocation required is the completion record, which
  49804. // has a stable shape and so hopefully should be cheap to allocate.
  49805. function tryCatch(fn, obj, arg) {
  49806. try {
  49807. return {
  49808. type: "normal",
  49809. arg: fn.call(obj, arg)
  49810. };
  49811. } catch (err) {
  49812. return {
  49813. type: "throw",
  49814. arg: err
  49815. };
  49816. }
  49817. }
  49818. var GenStateSuspendedStart = "suspendedStart";
  49819. var GenStateSuspendedYield = "suspendedYield";
  49820. var GenStateExecuting = "executing";
  49821. var GenStateCompleted = "completed";
  49822. // Returning this object from the innerFn has the same effect as
  49823. // breaking out of the dispatch switch statement.
  49824. var ContinueSentinel = {};
  49825. // Dummy constructor functions that we use as the .constructor and
  49826. // .constructor.prototype properties for functions that return Generator
  49827. // objects. For full spec compliance, you may wish to configure your
  49828. // minifier not to mangle the names of these two functions.
  49829. function Generator() {}
  49830. function GeneratorFunction() {}
  49831. function GeneratorFunctionPrototype() {}
  49832. // This is a polyfill for %IteratorPrototype% for environments that
  49833. // don't natively support it.
  49834. var IteratorPrototype = {};
  49835. define(IteratorPrototype, iteratorSymbol, function () {
  49836. return this;
  49837. });
  49838. var getProto = Object.getPrototypeOf;
  49839. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  49840. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  49841. // This environment has a native %IteratorPrototype%; use it instead
  49842. // of the polyfill.
  49843. IteratorPrototype = NativeIteratorPrototype;
  49844. }
  49845. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  49846. GeneratorFunction.prototype = GeneratorFunctionPrototype;
  49847. defineProperty(Gp, "constructor", {
  49848. value: GeneratorFunctionPrototype,
  49849. configurable: true
  49850. });
  49851. defineProperty(GeneratorFunctionPrototype, "constructor", {
  49852. value: GeneratorFunction,
  49853. configurable: true
  49854. });
  49855. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
  49856. // Helper for defining the .next, .throw, and .return methods of the
  49857. // Iterator interface in terms of a single ._invoke method.
  49858. function defineIteratorMethods(prototype) {
  49859. ["next", "throw", "return"].forEach(function (method) {
  49860. define(prototype, method, function (arg) {
  49861. return this._invoke(method, arg);
  49862. });
  49863. });
  49864. }
  49865. exports.isGeneratorFunction = function (genFun) {
  49866. var ctor = typeof genFun === "function" && genFun.constructor;
  49867. return ctor ? ctor === GeneratorFunction ||
  49868. // For the native GeneratorFunction constructor, the best we can
  49869. // do is to check its .name property.
  49870. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  49871. };
  49872. exports.mark = function (genFun) {
  49873. if (Object.setPrototypeOf) {
  49874. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  49875. } else {
  49876. genFun.__proto__ = GeneratorFunctionPrototype;
  49877. define(genFun, toStringTagSymbol, "GeneratorFunction");
  49878. }
  49879. genFun.prototype = Object.create(Gp);
  49880. return genFun;
  49881. };
  49882. // Within the body of any async function, `await x` is transformed to
  49883. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  49884. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  49885. // meant to be awaited.
  49886. exports.awrap = function (arg) {
  49887. return {
  49888. __await: arg
  49889. };
  49890. };
  49891. function AsyncIterator(generator, PromiseImpl) {
  49892. function invoke(method, arg, resolve, reject) {
  49893. var record = tryCatch(generator[method], generator, arg);
  49894. if (record.type === "throw") {
  49895. reject(record.arg);
  49896. } else {
  49897. var result = record.arg;
  49898. var value = result.value;
  49899. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  49900. return PromiseImpl.resolve(value.__await).then(function (value) {
  49901. invoke("next", value, resolve, reject);
  49902. }, function (err) {
  49903. invoke("throw", err, resolve, reject);
  49904. });
  49905. }
  49906. return PromiseImpl.resolve(value).then(function (unwrapped) {
  49907. // When a yielded Promise is resolved, its final value becomes
  49908. // the .value of the Promise<{value,done}> result for the
  49909. // current iteration.
  49910. result.value = unwrapped;
  49911. resolve(result);
  49912. }, function (error) {
  49913. // If a rejected Promise was yielded, throw the rejection back
  49914. // into the async generator function so it can be handled there.
  49915. return invoke("throw", error, resolve, reject);
  49916. });
  49917. }
  49918. }
  49919. var previousPromise;
  49920. function enqueue(method, arg) {
  49921. function callInvokeWithMethodAndArg() {
  49922. return new PromiseImpl(function (resolve, reject) {
  49923. invoke(method, arg, resolve, reject);
  49924. });
  49925. }
  49926. return previousPromise =
  49927. // If enqueue has been called before, then we want to wait until
  49928. // all previous Promises have been resolved before calling invoke,
  49929. // so that results are always delivered in the correct order. If
  49930. // enqueue has not been called before, then it is important to
  49931. // call invoke immediately, without waiting on a callback to fire,
  49932. // so that the async generator function has the opportunity to do
  49933. // any necessary setup in a predictable way. This predictability
  49934. // is why the Promise constructor synchronously invokes its
  49935. // executor callback, and why async functions synchronously
  49936. // execute code before the first await. Since we implement simple
  49937. // async functions in terms of async generators, it is especially
  49938. // important to get this right, even though it requires care.
  49939. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg,
  49940. // Avoid propagating failures to Promises returned by later
  49941. // invocations of the iterator.
  49942. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  49943. }
  49944. // Define the unified helper method that is used to implement .next,
  49945. // .throw, and .return (see defineIteratorMethods).
  49946. defineProperty(this, "_invoke", {
  49947. value: enqueue
  49948. });
  49949. }
  49950. defineIteratorMethods(AsyncIterator.prototype);
  49951. define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  49952. return this;
  49953. });
  49954. exports.AsyncIterator = AsyncIterator;
  49955. // Note that simple async functions are implemented on top of
  49956. // AsyncIterator objects; they just return a Promise for the value of
  49957. // the final result produced by the iterator.
  49958. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  49959. if (PromiseImpl === void 0) PromiseImpl = Promise;
  49960. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  49961. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  49962. : iter.next().then(function (result) {
  49963. return result.done ? result.value : iter.next();
  49964. });
  49965. };
  49966. function makeInvokeMethod(innerFn, self, context) {
  49967. var state = GenStateSuspendedStart;
  49968. return function invoke(method, arg) {
  49969. if (state === GenStateExecuting) {
  49970. throw new Error("Generator is already running");
  49971. }
  49972. if (state === GenStateCompleted) {
  49973. if (method === "throw") {
  49974. throw arg;
  49975. }
  49976. // Be forgiving, per 25.3.3.3.3 of the spec:
  49977. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  49978. return doneResult();
  49979. }
  49980. context.method = method;
  49981. context.arg = arg;
  49982. while (true) {
  49983. var delegate = context.delegate;
  49984. if (delegate) {
  49985. var delegateResult = maybeInvokeDelegate(delegate, context);
  49986. if (delegateResult) {
  49987. if (delegateResult === ContinueSentinel) continue;
  49988. return delegateResult;
  49989. }
  49990. }
  49991. if (context.method === "next") {
  49992. // Setting context._sent for legacy support of Babel's
  49993. // function.sent implementation.
  49994. context.sent = context._sent = context.arg;
  49995. } else if (context.method === "throw") {
  49996. if (state === GenStateSuspendedStart) {
  49997. state = GenStateCompleted;
  49998. throw context.arg;
  49999. }
  50000. context.dispatchException(context.arg);
  50001. } else if (context.method === "return") {
  50002. context.abrupt("return", context.arg);
  50003. }
  50004. state = GenStateExecuting;
  50005. var record = tryCatch(innerFn, self, context);
  50006. if (record.type === "normal") {
  50007. // If an exception is thrown from innerFn, we leave state ===
  50008. // GenStateExecuting and loop back for another invocation.
  50009. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  50010. if (record.arg === ContinueSentinel) {
  50011. continue;
  50012. }
  50013. return {
  50014. value: record.arg,
  50015. done: context.done
  50016. };
  50017. } else if (record.type === "throw") {
  50018. state = GenStateCompleted;
  50019. // Dispatch the exception by looping back around to the
  50020. // context.dispatchException(context.arg) call above.
  50021. context.method = "throw";
  50022. context.arg = record.arg;
  50023. }
  50024. }
  50025. };
  50026. }
  50027. // Call delegate.iterator[context.method](context.arg) and handle the
  50028. // result, either by returning a { value, done } result from the
  50029. // delegate iterator, or by modifying context.method and context.arg,
  50030. // setting context.delegate to null, and returning the ContinueSentinel.
  50031. function maybeInvokeDelegate(delegate, context) {
  50032. var methodName = context.method;
  50033. var method = delegate.iterator[methodName];
  50034. if (method === undefined) {
  50035. // A .throw or .return when the delegate iterator has no .throw
  50036. // method, or a missing .next mehtod, always terminate the
  50037. // yield* loop.
  50038. context.delegate = null;
  50039. // Note: ["return"] must be used for ES3 parsing compatibility.
  50040. if (methodName === "throw" && delegate.iterator["return"]) {
  50041. // If the delegate iterator has a return method, give it a
  50042. // chance to clean up.
  50043. context.method = "return";
  50044. context.arg = undefined;
  50045. maybeInvokeDelegate(delegate, context);
  50046. if (context.method === "throw") {
  50047. // If maybeInvokeDelegate(context) changed context.method from
  50048. // "return" to "throw", let that override the TypeError below.
  50049. return ContinueSentinel;
  50050. }
  50051. }
  50052. if (methodName !== "return") {
  50053. context.method = "throw";
  50054. context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method");
  50055. }
  50056. return ContinueSentinel;
  50057. }
  50058. var record = tryCatch(method, delegate.iterator, context.arg);
  50059. if (record.type === "throw") {
  50060. context.method = "throw";
  50061. context.arg = record.arg;
  50062. context.delegate = null;
  50063. return ContinueSentinel;
  50064. }
  50065. var info = record.arg;
  50066. if (!info) {
  50067. context.method = "throw";
  50068. context.arg = new TypeError("iterator result is not an object");
  50069. context.delegate = null;
  50070. return ContinueSentinel;
  50071. }
  50072. if (info.done) {
  50073. // Assign the result of the finished delegate to the temporary
  50074. // variable specified by delegate.resultName (see delegateYield).
  50075. context[delegate.resultName] = info.value;
  50076. // Resume execution at the desired location (see delegateYield).
  50077. context.next = delegate.nextLoc;
  50078. // If context.method was "throw" but the delegate handled the
  50079. // exception, let the outer generator proceed normally. If
  50080. // context.method was "next", forget context.arg since it has been
  50081. // "consumed" by the delegate iterator. If context.method was
  50082. // "return", allow the original .return call to continue in the
  50083. // outer generator.
  50084. if (context.method !== "return") {
  50085. context.method = "next";
  50086. context.arg = undefined;
  50087. }
  50088. } else {
  50089. // Re-yield the result returned by the delegate method.
  50090. return info;
  50091. }
  50092. // The delegate iterator is finished, so forget it and continue with
  50093. // the outer generator.
  50094. context.delegate = null;
  50095. return ContinueSentinel;
  50096. }
  50097. // Define Generator.prototype.{next,throw,return} in terms of the
  50098. // unified ._invoke helper method.
  50099. defineIteratorMethods(Gp);
  50100. define(Gp, toStringTagSymbol, "Generator");
  50101. // A Generator should always return itself as the iterator object when the
  50102. // @@iterator function is called on it. Some browsers' implementations of the
  50103. // iterator prototype chain incorrectly implement this, causing the Generator
  50104. // object to not be returned from this call. This ensures that doesn't happen.
  50105. // See https://github.com/facebook/regenerator/issues/274 for more details.
  50106. define(Gp, iteratorSymbol, function () {
  50107. return this;
  50108. });
  50109. define(Gp, "toString", function () {
  50110. return "[object Generator]";
  50111. });
  50112. function pushTryEntry(locs) {
  50113. var entry = {
  50114. tryLoc: locs[0]
  50115. };
  50116. if (1 in locs) {
  50117. entry.catchLoc = locs[1];
  50118. }
  50119. if (2 in locs) {
  50120. entry.finallyLoc = locs[2];
  50121. entry.afterLoc = locs[3];
  50122. }
  50123. this.tryEntries.push(entry);
  50124. }
  50125. function resetTryEntry(entry) {
  50126. var record = entry.completion || {};
  50127. record.type = "normal";
  50128. delete record.arg;
  50129. entry.completion = record;
  50130. }
  50131. function Context(tryLocsList) {
  50132. // The root entry object (effectively a try statement without a catch
  50133. // or a finally block) gives us a place to store values thrown from
  50134. // locations where there is no enclosing try statement.
  50135. this.tryEntries = [{
  50136. tryLoc: "root"
  50137. }];
  50138. tryLocsList.forEach(pushTryEntry, this);
  50139. this.reset(true);
  50140. }
  50141. exports.keys = function (val) {
  50142. var object = Object(val);
  50143. var keys = [];
  50144. for (var key in object) {
  50145. keys.push(key);
  50146. }
  50147. keys.reverse();
  50148. // Rather than returning an object with a next method, we keep
  50149. // things simple and return the next function itself.
  50150. return function next() {
  50151. while (keys.length) {
  50152. var key = keys.pop();
  50153. if (key in object) {
  50154. next.value = key;
  50155. next.done = false;
  50156. return next;
  50157. }
  50158. }
  50159. // To avoid creating an additional object, we just hang the .value
  50160. // and .done properties off the next function object itself. This
  50161. // also ensures that the minifier will not anonymize the function.
  50162. next.done = true;
  50163. return next;
  50164. };
  50165. };
  50166. function values(iterable) {
  50167. if (iterable) {
  50168. var iteratorMethod = iterable[iteratorSymbol];
  50169. if (iteratorMethod) {
  50170. return iteratorMethod.call(iterable);
  50171. }
  50172. if (typeof iterable.next === "function") {
  50173. return iterable;
  50174. }
  50175. if (!isNaN(iterable.length)) {
  50176. var i = -1,
  50177. next = function next() {
  50178. while (++i < iterable.length) {
  50179. if (hasOwn.call(iterable, i)) {
  50180. next.value = iterable[i];
  50181. next.done = false;
  50182. return next;
  50183. }
  50184. }
  50185. next.value = undefined;
  50186. next.done = true;
  50187. return next;
  50188. };
  50189. return next.next = next;
  50190. }
  50191. }
  50192. // Return an iterator with no values.
  50193. return {
  50194. next: doneResult
  50195. };
  50196. }
  50197. exports.values = values;
  50198. function doneResult() {
  50199. return {
  50200. value: undefined,
  50201. done: true
  50202. };
  50203. }
  50204. Context.prototype = {
  50205. constructor: Context,
  50206. reset: function (skipTempReset) {
  50207. this.prev = 0;
  50208. this.next = 0;
  50209. // Resetting context._sent for legacy support of Babel's
  50210. // function.sent implementation.
  50211. this.sent = this._sent = undefined;
  50212. this.done = false;
  50213. this.delegate = null;
  50214. this.method = "next";
  50215. this.arg = undefined;
  50216. this.tryEntries.forEach(resetTryEntry);
  50217. if (!skipTempReset) {
  50218. for (var name in this) {
  50219. // Not sure about the optimal order of these conditions:
  50220. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  50221. this[name] = undefined;
  50222. }
  50223. }
  50224. }
  50225. },
  50226. stop: function () {
  50227. this.done = true;
  50228. var rootEntry = this.tryEntries[0];
  50229. var rootRecord = rootEntry.completion;
  50230. if (rootRecord.type === "throw") {
  50231. throw rootRecord.arg;
  50232. }
  50233. return this.rval;
  50234. },
  50235. dispatchException: function (exception) {
  50236. if (this.done) {
  50237. throw exception;
  50238. }
  50239. var context = this;
  50240. function handle(loc, caught) {
  50241. record.type = "throw";
  50242. record.arg = exception;
  50243. context.next = loc;
  50244. if (caught) {
  50245. // If the dispatched exception was caught by a catch block,
  50246. // then let that catch block handle the exception normally.
  50247. context.method = "next";
  50248. context.arg = undefined;
  50249. }
  50250. return !!caught;
  50251. }
  50252. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  50253. var entry = this.tryEntries[i];
  50254. var record = entry.completion;
  50255. if (entry.tryLoc === "root") {
  50256. // Exception thrown outside of any try block that could handle
  50257. // it, so set the completion value of the entire function to
  50258. // throw the exception.
  50259. return handle("end");
  50260. }
  50261. if (entry.tryLoc <= this.prev) {
  50262. var hasCatch = hasOwn.call(entry, "catchLoc");
  50263. var hasFinally = hasOwn.call(entry, "finallyLoc");
  50264. if (hasCatch && hasFinally) {
  50265. if (this.prev < entry.catchLoc) {
  50266. return handle(entry.catchLoc, true);
  50267. } else if (this.prev < entry.finallyLoc) {
  50268. return handle(entry.finallyLoc);
  50269. }
  50270. } else if (hasCatch) {
  50271. if (this.prev < entry.catchLoc) {
  50272. return handle(entry.catchLoc, true);
  50273. }
  50274. } else if (hasFinally) {
  50275. if (this.prev < entry.finallyLoc) {
  50276. return handle(entry.finallyLoc);
  50277. }
  50278. } else {
  50279. throw new Error("try statement without catch or finally");
  50280. }
  50281. }
  50282. }
  50283. },
  50284. abrupt: function (type, arg) {
  50285. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  50286. var entry = this.tryEntries[i];
  50287. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  50288. var finallyEntry = entry;
  50289. break;
  50290. }
  50291. }
  50292. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  50293. // Ignore the finally entry if control is not jumping to a
  50294. // location outside the try/catch block.
  50295. finallyEntry = null;
  50296. }
  50297. var record = finallyEntry ? finallyEntry.completion : {};
  50298. record.type = type;
  50299. record.arg = arg;
  50300. if (finallyEntry) {
  50301. this.method = "next";
  50302. this.next = finallyEntry.finallyLoc;
  50303. return ContinueSentinel;
  50304. }
  50305. return this.complete(record);
  50306. },
  50307. complete: function (record, afterLoc) {
  50308. if (record.type === "throw") {
  50309. throw record.arg;
  50310. }
  50311. if (record.type === "break" || record.type === "continue") {
  50312. this.next = record.arg;
  50313. } else if (record.type === "return") {
  50314. this.rval = this.arg = record.arg;
  50315. this.method = "return";
  50316. this.next = "end";
  50317. } else if (record.type === "normal" && afterLoc) {
  50318. this.next = afterLoc;
  50319. }
  50320. return ContinueSentinel;
  50321. },
  50322. finish: function (finallyLoc) {
  50323. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  50324. var entry = this.tryEntries[i];
  50325. if (entry.finallyLoc === finallyLoc) {
  50326. this.complete(entry.completion, entry.afterLoc);
  50327. resetTryEntry(entry);
  50328. return ContinueSentinel;
  50329. }
  50330. }
  50331. },
  50332. "catch": function (tryLoc) {
  50333. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  50334. var entry = this.tryEntries[i];
  50335. if (entry.tryLoc === tryLoc) {
  50336. var record = entry.completion;
  50337. if (record.type === "throw") {
  50338. var thrown = record.arg;
  50339. resetTryEntry(entry);
  50340. }
  50341. return thrown;
  50342. }
  50343. }
  50344. // The context.catch method must only be called with a location
  50345. // argument that corresponds to a known catch block.
  50346. throw new Error("illegal catch attempt");
  50347. },
  50348. delegateYield: function (iterable, resultName, nextLoc) {
  50349. this.delegate = {
  50350. iterator: values(iterable),
  50351. resultName: resultName,
  50352. nextLoc: nextLoc
  50353. };
  50354. if (this.method === "next") {
  50355. // Deliberately forget the last sent value so that we don't
  50356. // accidentally pass it on to the delegate.
  50357. this.arg = undefined;
  50358. }
  50359. return ContinueSentinel;
  50360. }
  50361. };
  50362. // Regardless of whether this script is executing as a CommonJS module
  50363. // or not, return the runtime object so that we can declare the variable
  50364. // regeneratorRuntime in the outer scope, which allows this module to be
  50365. // injected easily by `bin/regenerator --include-runtime script.js`.
  50366. return exports;
  50367. }(
  50368. // If this script is executing as a CommonJS module, use module.exports
  50369. // as the regeneratorRuntime namespace. Otherwise create a new empty
  50370. // object. Either way, the resulting object will be used to initialize
  50371. // the regeneratorRuntime variable at the top of this file.
  50372. typeof module === "object" ? module.exports : {});
  50373. try {
  50374. regeneratorRuntime = runtime;
  50375. } catch (accidentalStrictMode) {
  50376. // This module should not be running in strict mode, so the above
  50377. // assignment should always work unless something is misconfigured. Just
  50378. // in case runtime.js accidentally runs in strict mode, in modern engines
  50379. // we can explicitly access globalThis. In older engines we can escape
  50380. // strict mode using a global Function call. This could conceivably fail
  50381. // if a Content Security Policy forbids using Function, but in that case
  50382. // the proper solution is to fix the accidental strict mode problem. If
  50383. // you've misconfigured your bundler to force strict mode and applied a
  50384. // CSP to forbid Function, and you're not willing to fix either of those
  50385. // problems, please detail your unique predicament in a GitHub issue.
  50386. if (typeof globalThis === "object") {
  50387. globalThis.regeneratorRuntime = runtime;
  50388. } else {
  50389. Function("r", "regeneratorRuntime = r")(runtime);
  50390. }
  50391. }
  50392. },{}],493:[function(require,module,exports){
  50393. 'use strict';
  50394. var Buffer = require('buffer').Buffer;
  50395. var inherits = require('inherits');
  50396. var HashBase = require('hash-base');
  50397. var ARRAY16 = new Array(16);
  50398. var zl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13];
  50399. var zr = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11];
  50400. var sl = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6];
  50401. var sr = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11];
  50402. var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e];
  50403. var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000];
  50404. function RIPEMD160() {
  50405. HashBase.call(this, 64);
  50406. // state
  50407. this._a = 0x67452301;
  50408. this._b = 0xefcdab89;
  50409. this._c = 0x98badcfe;
  50410. this._d = 0x10325476;
  50411. this._e = 0xc3d2e1f0;
  50412. }
  50413. inherits(RIPEMD160, HashBase);
  50414. RIPEMD160.prototype._update = function () {
  50415. var words = ARRAY16;
  50416. for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4);
  50417. var al = this._a | 0;
  50418. var bl = this._b | 0;
  50419. var cl = this._c | 0;
  50420. var dl = this._d | 0;
  50421. var el = this._e | 0;
  50422. var ar = this._a | 0;
  50423. var br = this._b | 0;
  50424. var cr = this._c | 0;
  50425. var dr = this._d | 0;
  50426. var er = this._e | 0;
  50427. // computation
  50428. for (var i = 0; i < 80; i += 1) {
  50429. var tl;
  50430. var tr;
  50431. if (i < 16) {
  50432. tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]);
  50433. tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]);
  50434. } else if (i < 32) {
  50435. tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]);
  50436. tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]);
  50437. } else if (i < 48) {
  50438. tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]);
  50439. tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]);
  50440. } else if (i < 64) {
  50441. tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]);
  50442. tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]);
  50443. } else {
  50444. // if (i<80) {
  50445. tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]);
  50446. tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]);
  50447. }
  50448. al = el;
  50449. el = dl;
  50450. dl = rotl(cl, 10);
  50451. cl = bl;
  50452. bl = tl;
  50453. ar = er;
  50454. er = dr;
  50455. dr = rotl(cr, 10);
  50456. cr = br;
  50457. br = tr;
  50458. }
  50459. // update state
  50460. var t = this._b + cl + dr | 0;
  50461. this._b = this._c + dl + er | 0;
  50462. this._c = this._d + el + ar | 0;
  50463. this._d = this._e + al + br | 0;
  50464. this._e = this._a + bl + cr | 0;
  50465. this._a = t;
  50466. };
  50467. RIPEMD160.prototype._digest = function () {
  50468. // create padding and handle blocks
  50469. this._block[this._blockOffset++] = 0x80;
  50470. if (this._blockOffset > 56) {
  50471. this._block.fill(0, this._blockOffset, 64);
  50472. this._update();
  50473. this._blockOffset = 0;
  50474. }
  50475. this._block.fill(0, this._blockOffset, 56);
  50476. this._block.writeUInt32LE(this._length[0], 56);
  50477. this._block.writeUInt32LE(this._length[1], 60);
  50478. this._update();
  50479. // produce result
  50480. var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20);
  50481. buffer.writeInt32LE(this._a, 0);
  50482. buffer.writeInt32LE(this._b, 4);
  50483. buffer.writeInt32LE(this._c, 8);
  50484. buffer.writeInt32LE(this._d, 12);
  50485. buffer.writeInt32LE(this._e, 16);
  50486. return buffer;
  50487. };
  50488. function rotl(x, n) {
  50489. return x << n | x >>> 32 - n;
  50490. }
  50491. function fn1(a, b, c, d, e, m, k, s) {
  50492. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0;
  50493. }
  50494. function fn2(a, b, c, d, e, m, k, s) {
  50495. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0;
  50496. }
  50497. function fn3(a, b, c, d, e, m, k, s) {
  50498. return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0;
  50499. }
  50500. function fn4(a, b, c, d, e, m, k, s) {
  50501. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0;
  50502. }
  50503. function fn5(a, b, c, d, e, m, k, s) {
  50504. return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0;
  50505. }
  50506. module.exports = RIPEMD160;
  50507. },{"buffer":220,"hash-base":425,"inherits":440}],494:[function(require,module,exports){
  50508. "use strict";
  50509. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  50510. /* eslint-disable node/no-deprecated-api */
  50511. var buffer = require('buffer');
  50512. var Buffer = buffer.Buffer;
  50513. // alternative to using Object.keys for old browsers
  50514. function copyProps(src, dst) {
  50515. for (var key in src) {
  50516. dst[key] = src[key];
  50517. }
  50518. }
  50519. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  50520. module.exports = buffer;
  50521. } else {
  50522. // Copy properties from require('buffer')
  50523. copyProps(buffer, exports);
  50524. exports.Buffer = SafeBuffer;
  50525. }
  50526. function SafeBuffer(arg, encodingOrOffset, length) {
  50527. return Buffer(arg, encodingOrOffset, length);
  50528. }
  50529. SafeBuffer.prototype = Object.create(Buffer.prototype);
  50530. // Copy static methods from Buffer
  50531. copyProps(Buffer, SafeBuffer);
  50532. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  50533. if (typeof arg === 'number') {
  50534. throw new TypeError('Argument must not be a number');
  50535. }
  50536. return Buffer(arg, encodingOrOffset, length);
  50537. };
  50538. SafeBuffer.alloc = function (size, fill, encoding) {
  50539. if (typeof size !== 'number') {
  50540. throw new TypeError('Argument must be a number');
  50541. }
  50542. var buf = Buffer(size);
  50543. if (fill !== undefined) {
  50544. if (typeof encoding === 'string') {
  50545. buf.fill(fill, encoding);
  50546. } else {
  50547. buf.fill(fill);
  50548. }
  50549. } else {
  50550. buf.fill(0);
  50551. }
  50552. return buf;
  50553. };
  50554. SafeBuffer.allocUnsafe = function (size) {
  50555. if (typeof size !== 'number') {
  50556. throw new TypeError('Argument must be a number');
  50557. }
  50558. return Buffer(size);
  50559. };
  50560. SafeBuffer.allocUnsafeSlow = function (size) {
  50561. if (typeof size !== 'number') {
  50562. throw new TypeError('Argument must be a number');
  50563. }
  50564. return buffer.SlowBuffer(size);
  50565. };
  50566. },{"buffer":220}],495:[function(require,module,exports){
  50567. (function (process){(function (){
  50568. /* eslint-disable node/no-deprecated-api */
  50569. 'use strict';
  50570. var buffer = require('buffer');
  50571. var Buffer = buffer.Buffer;
  50572. var safer = {};
  50573. var key;
  50574. for (key in buffer) {
  50575. if (!buffer.hasOwnProperty(key)) continue;
  50576. if (key === 'SlowBuffer' || key === 'Buffer') continue;
  50577. safer[key] = buffer[key];
  50578. }
  50579. var Safer = safer.Buffer = {};
  50580. for (key in Buffer) {
  50581. if (!Buffer.hasOwnProperty(key)) continue;
  50582. if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue;
  50583. Safer[key] = Buffer[key];
  50584. }
  50585. safer.Buffer.prototype = Buffer.prototype;
  50586. if (!Safer.from || Safer.from === Uint8Array.from) {
  50587. Safer.from = function (value, encodingOrOffset, length) {
  50588. if (typeof value === 'number') {
  50589. throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value);
  50590. }
  50591. if (value && typeof value.length === 'undefined') {
  50592. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value);
  50593. }
  50594. return Buffer(value, encodingOrOffset, length);
  50595. };
  50596. }
  50597. if (!Safer.alloc) {
  50598. Safer.alloc = function (size, fill, encoding) {
  50599. if (typeof size !== 'number') {
  50600. throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size);
  50601. }
  50602. if (size < 0 || size >= 2 * (1 << 30)) {
  50603. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  50604. }
  50605. var buf = Buffer(size);
  50606. if (!fill || fill.length === 0) {
  50607. buf.fill(0);
  50608. } else if (typeof encoding === 'string') {
  50609. buf.fill(fill, encoding);
  50610. } else {
  50611. buf.fill(fill);
  50612. }
  50613. return buf;
  50614. };
  50615. }
  50616. if (!safer.kStringMaxLength) {
  50617. try {
  50618. safer.kStringMaxLength = process.binding('buffer').kStringMaxLength;
  50619. } catch (e) {
  50620. // we can't determine kStringMaxLength in environments where process.binding
  50621. // is unsupported, so let's not set it
  50622. }
  50623. }
  50624. if (!safer.constants) {
  50625. safer.constants = {
  50626. MAX_LENGTH: safer.kMaxLength
  50627. };
  50628. if (safer.kStringMaxLength) {
  50629. safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
  50630. }
  50631. }
  50632. module.exports = safer;
  50633. }).call(this)}).call(this,require('_process'))
  50634. },{"_process":467,"buffer":220}],496:[function(require,module,exports){
  50635. "use strict";
  50636. Object.defineProperty(exports, "__esModule", {
  50637. value: true
  50638. });
  50639. const ed5 = require("xmlchars/xml/1.0/ed5");
  50640. const ed2 = require("xmlchars/xml/1.1/ed2");
  50641. const NSed3 = require("xmlchars/xmlns/1.0/ed3");
  50642. var isS = ed5.isS;
  50643. var isChar10 = ed5.isChar;
  50644. var isNameStartChar = ed5.isNameStartChar;
  50645. var isNameChar = ed5.isNameChar;
  50646. var S_LIST = ed5.S_LIST;
  50647. var NAME_RE = ed5.NAME_RE;
  50648. var isChar11 = ed2.isChar;
  50649. var isNCNameStartChar = NSed3.isNCNameStartChar;
  50650. var isNCNameChar = NSed3.isNCNameChar;
  50651. var NC_NAME_RE = NSed3.NC_NAME_RE;
  50652. const XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
  50653. const XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
  50654. const rootNS = {
  50655. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  50656. __proto__: null,
  50657. xml: XML_NAMESPACE,
  50658. xmlns: XMLNS_NAMESPACE
  50659. };
  50660. const XML_ENTITIES = {
  50661. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  50662. __proto__: null,
  50663. amp: "&",
  50664. gt: ">",
  50665. lt: "<",
  50666. quot: "\"",
  50667. apos: "'"
  50668. };
  50669. // EOC: end-of-chunk
  50670. const EOC = -1;
  50671. const NL_LIKE = -2;
  50672. const S_BEGIN = 0; // Initial state.
  50673. const S_BEGIN_WHITESPACE = 1; // leading whitespace
  50674. const S_DOCTYPE = 2; // <!DOCTYPE
  50675. const S_DOCTYPE_QUOTE = 3; // <!DOCTYPE "//blah
  50676. const S_DTD = 4; // <!DOCTYPE "//blah" [ ...
  50677. const S_DTD_QUOTED = 5; // <!DOCTYPE "//blah" [ "foo
  50678. const S_DTD_OPEN_WAKA = 6;
  50679. const S_DTD_OPEN_WAKA_BANG = 7;
  50680. const S_DTD_COMMENT = 8; // <!--
  50681. const S_DTD_COMMENT_ENDING = 9; // <!-- blah -
  50682. const S_DTD_COMMENT_ENDED = 10; // <!-- blah --
  50683. const S_DTD_PI = 11; // <?
  50684. const S_DTD_PI_ENDING = 12; // <?hi "there" ?
  50685. const S_TEXT = 13; // general stuff
  50686. const S_ENTITY = 14; // &amp and such
  50687. const S_OPEN_WAKA = 15; // <
  50688. const S_OPEN_WAKA_BANG = 16; // <!...
  50689. const S_COMMENT = 17; // <!--
  50690. const S_COMMENT_ENDING = 18; // <!-- blah -
  50691. const S_COMMENT_ENDED = 19; // <!-- blah --
  50692. const S_CDATA = 20; // <![CDATA[ something
  50693. const S_CDATA_ENDING = 21; // ]
  50694. const S_CDATA_ENDING_2 = 22; // ]]
  50695. const S_PI_FIRST_CHAR = 23; // <?hi, first char
  50696. const S_PI_REST = 24; // <?hi, rest of the name
  50697. const S_PI_BODY = 25; // <?hi there
  50698. const S_PI_ENDING = 26; // <?hi "there" ?
  50699. const S_XML_DECL_NAME_START = 27; // <?xml
  50700. const S_XML_DECL_NAME = 28; // <?xml foo
  50701. const S_XML_DECL_EQ = 29; // <?xml foo=
  50702. const S_XML_DECL_VALUE_START = 30; // <?xml foo=
  50703. const S_XML_DECL_VALUE = 31; // <?xml foo="bar"
  50704. const S_XML_DECL_SEPARATOR = 32; // <?xml foo="bar"
  50705. const S_XML_DECL_ENDING = 33; // <?xml ... ?
  50706. const S_OPEN_TAG = 34; // <strong
  50707. const S_OPEN_TAG_SLASH = 35; // <strong /
  50708. const S_ATTRIB = 36; // <a
  50709. const S_ATTRIB_NAME = 37; // <a foo
  50710. const S_ATTRIB_NAME_SAW_WHITE = 38; // <a foo _
  50711. const S_ATTRIB_VALUE = 39; // <a foo=
  50712. const S_ATTRIB_VALUE_QUOTED = 40; // <a foo="bar
  50713. const S_ATTRIB_VALUE_CLOSED = 41; // <a foo="bar"
  50714. const S_ATTRIB_VALUE_UNQUOTED = 42; // <a foo=bar
  50715. const S_CLOSE_TAG = 43; // </a
  50716. const S_CLOSE_TAG_SAW_WHITE = 44; // </a >
  50717. const TAB = 9;
  50718. const NL = 0xA;
  50719. const CR = 0xD;
  50720. const SPACE = 0x20;
  50721. const BANG = 0x21;
  50722. const DQUOTE = 0x22;
  50723. const AMP = 0x26;
  50724. const SQUOTE = 0x27;
  50725. const MINUS = 0x2D;
  50726. const FORWARD_SLASH = 0x2F;
  50727. const SEMICOLON = 0x3B;
  50728. const LESS = 0x3C;
  50729. const EQUAL = 0x3D;
  50730. const GREATER = 0x3E;
  50731. const QUESTION = 0x3F;
  50732. const OPEN_BRACKET = 0x5B;
  50733. const CLOSE_BRACKET = 0x5D;
  50734. const NEL = 0x85;
  50735. const LS = 0x2028; // Line Separator
  50736. const isQuote = c => c === DQUOTE || c === SQUOTE;
  50737. const QUOTES = [DQUOTE, SQUOTE];
  50738. const DOCTYPE_TERMINATOR = [...QUOTES, OPEN_BRACKET, GREATER];
  50739. const DTD_TERMINATOR = [...QUOTES, LESS, CLOSE_BRACKET];
  50740. const XML_DECL_NAME_TERMINATOR = [EQUAL, QUESTION, ...S_LIST];
  50741. const ATTRIB_VALUE_UNQUOTED_TERMINATOR = [...S_LIST, GREATER, AMP, LESS];
  50742. function nsPairCheck(parser, prefix, uri) {
  50743. switch (prefix) {
  50744. case "xml":
  50745. if (uri !== XML_NAMESPACE) {
  50746. parser.fail(`xml prefix must be bound to ${XML_NAMESPACE}.`);
  50747. }
  50748. break;
  50749. case "xmlns":
  50750. if (uri !== XMLNS_NAMESPACE) {
  50751. parser.fail(`xmlns prefix must be bound to ${XMLNS_NAMESPACE}.`);
  50752. }
  50753. break;
  50754. default:
  50755. }
  50756. switch (uri) {
  50757. case XMLNS_NAMESPACE:
  50758. parser.fail(prefix === "" ? `the default namespace may not be set to ${uri}.` : `may not assign a prefix (even "xmlns") to the URI \
  50759. ${XMLNS_NAMESPACE}.`);
  50760. break;
  50761. case XML_NAMESPACE:
  50762. switch (prefix) {
  50763. case "xml":
  50764. // Assinging the XML namespace to "xml" is fine.
  50765. break;
  50766. case "":
  50767. parser.fail(`the default namespace may not be set to ${uri}.`);
  50768. break;
  50769. default:
  50770. parser.fail("may not assign the xml namespace to another prefix.");
  50771. }
  50772. break;
  50773. default:
  50774. }
  50775. }
  50776. function nsMappingCheck(parser, mapping) {
  50777. for (const local of Object.keys(mapping)) {
  50778. nsPairCheck(parser, local, mapping[local]);
  50779. }
  50780. }
  50781. const isNCName = name => NC_NAME_RE.test(name);
  50782. const isName = name => NAME_RE.test(name);
  50783. const FORBIDDEN_START = 0;
  50784. const FORBIDDEN_BRACKET = 1;
  50785. const FORBIDDEN_BRACKET_BRACKET = 2;
  50786. /**
  50787. * The list of supported events.
  50788. */
  50789. exports.EVENTS = ["xmldecl", "text", "processinginstruction", "doctype", "comment", "opentagstart", "attribute", "opentag", "closetag", "cdata", "error", "end", "ready"];
  50790. const EVENT_NAME_TO_HANDLER_NAME = {
  50791. xmldecl: "xmldeclHandler",
  50792. text: "textHandler",
  50793. processinginstruction: "piHandler",
  50794. doctype: "doctypeHandler",
  50795. comment: "commentHandler",
  50796. opentagstart: "openTagStartHandler",
  50797. attribute: "attributeHandler",
  50798. opentag: "openTagHandler",
  50799. closetag: "closeTagHandler",
  50800. cdata: "cdataHandler",
  50801. error: "errorHandler",
  50802. end: "endHandler",
  50803. ready: "readyHandler"
  50804. };
  50805. class SaxesParser {
  50806. /**
  50807. * @param opt The parser options.
  50808. */
  50809. constructor(opt) {
  50810. this.opt = opt !== null && opt !== void 0 ? opt : {};
  50811. this.fragmentOpt = !!this.opt.fragment;
  50812. const xmlnsOpt = this.xmlnsOpt = !!this.opt.xmlns;
  50813. this.trackPosition = this.opt.position !== false;
  50814. this.fileName = this.opt.fileName;
  50815. if (xmlnsOpt) {
  50816. // This is the function we use to perform name checks on PIs and entities.
  50817. // When namespaces are used, colons are not allowed in PI target names or
  50818. // entity names. So the check depends on whether namespaces are used. See:
  50819. //
  50820. // https://www.w3.org/XML/xml-names-19990114-errata.html
  50821. // NE08
  50822. //
  50823. this.nameStartCheck = isNCNameStartChar;
  50824. this.nameCheck = isNCNameChar;
  50825. this.isName = isNCName;
  50826. // eslint-disable-next-line @typescript-eslint/unbound-method
  50827. this.processAttribs = this.processAttribsNS;
  50828. // eslint-disable-next-line @typescript-eslint/unbound-method
  50829. this.pushAttrib = this.pushAttribNS;
  50830. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  50831. this.ns = Object.assign({
  50832. __proto__: null
  50833. }, rootNS);
  50834. const additional = this.opt.additionalNamespaces;
  50835. if (additional != null) {
  50836. nsMappingCheck(this, additional);
  50837. Object.assign(this.ns, additional);
  50838. }
  50839. } else {
  50840. this.nameStartCheck = isNameStartChar;
  50841. this.nameCheck = isNameChar;
  50842. this.isName = isName;
  50843. // eslint-disable-next-line @typescript-eslint/unbound-method
  50844. this.processAttribs = this.processAttribsPlain;
  50845. // eslint-disable-next-line @typescript-eslint/unbound-method
  50846. this.pushAttrib = this.pushAttribPlain;
  50847. }
  50848. //
  50849. // The order of the members in this table needs to correspond to the state
  50850. // numbers given to the states that correspond to the methods being recorded
  50851. // here.
  50852. //
  50853. this.stateTable = [/* eslint-disable @typescript-eslint/unbound-method */
  50854. this.sBegin, this.sBeginWhitespace, this.sDoctype, this.sDoctypeQuote, this.sDTD, this.sDTDQuoted, this.sDTDOpenWaka, this.sDTDOpenWakaBang, this.sDTDComment, this.sDTDCommentEnding, this.sDTDCommentEnded, this.sDTDPI, this.sDTDPIEnding, this.sText, this.sEntity, this.sOpenWaka, this.sOpenWakaBang, this.sComment, this.sCommentEnding, this.sCommentEnded, this.sCData, this.sCDataEnding, this.sCDataEnding2, this.sPIFirstChar, this.sPIRest, this.sPIBody, this.sPIEnding, this.sXMLDeclNameStart, this.sXMLDeclName, this.sXMLDeclEq, this.sXMLDeclValueStart, this.sXMLDeclValue, this.sXMLDeclSeparator, this.sXMLDeclEnding, this.sOpenTag, this.sOpenTagSlash, this.sAttrib, this.sAttribName, this.sAttribNameSawWhite, this.sAttribValue, this.sAttribValueQuoted, this.sAttribValueClosed, this.sAttribValueUnquoted, this.sCloseTag, this.sCloseTagSawWhite];
  50855. this._init();
  50856. }
  50857. /**
  50858. * Indicates whether or not the parser is closed. If ``true``, wait for
  50859. * the ``ready`` event to write again.
  50860. */
  50861. get closed() {
  50862. return this._closed;
  50863. }
  50864. _init() {
  50865. var _a;
  50866. this.openWakaBang = "";
  50867. this.text = "";
  50868. this.name = "";
  50869. this.piTarget = "";
  50870. this.entity = "";
  50871. this.q = null;
  50872. this.tags = [];
  50873. this.tag = null;
  50874. this.topNS = null;
  50875. this.chunk = "";
  50876. this.chunkPosition = 0;
  50877. this.i = 0;
  50878. this.prevI = 0;
  50879. this.carriedFromPrevious = undefined;
  50880. this.forbiddenState = FORBIDDEN_START;
  50881. this.attribList = [];
  50882. // The logic is organized so as to minimize the need to check
  50883. // this.opt.fragment while parsing.
  50884. const {
  50885. fragmentOpt
  50886. } = this;
  50887. this.state = fragmentOpt ? S_TEXT : S_BEGIN;
  50888. // We want these to be all true if we are dealing with a fragment.
  50889. this.reportedTextBeforeRoot = this.reportedTextAfterRoot = this.closedRoot = this.sawRoot = fragmentOpt;
  50890. // An XML declaration is intially possible only when parsing whole
  50891. // documents.
  50892. this.xmlDeclPossible = !fragmentOpt;
  50893. this.xmlDeclExpects = ["version"];
  50894. this.entityReturnState = undefined;
  50895. let {
  50896. defaultXMLVersion
  50897. } = this.opt;
  50898. if (defaultXMLVersion === undefined) {
  50899. if (this.opt.forceXMLVersion === true) {
  50900. throw new Error("forceXMLVersion set but defaultXMLVersion is not set");
  50901. }
  50902. defaultXMLVersion = "1.0";
  50903. }
  50904. this.setXMLVersion(defaultXMLVersion);
  50905. this.positionAtNewLine = 0;
  50906. this.doctype = false;
  50907. this._closed = false;
  50908. this.xmlDecl = {
  50909. version: undefined,
  50910. encoding: undefined,
  50911. standalone: undefined
  50912. };
  50913. this.line = 1;
  50914. this.column = 0;
  50915. this.ENTITIES = Object.create(XML_ENTITIES);
  50916. // eslint-disable-next-line no-unused-expressions
  50917. (_a = this.readyHandler) === null || _a === void 0 ? void 0 : _a.call(this);
  50918. }
  50919. /**
  50920. * The stream position the parser is currently looking at. This field is
  50921. * zero-based.
  50922. *
  50923. * This field is not based on counting Unicode characters but is to be
  50924. * interpreted as a plain index into a JavaScript string.
  50925. */
  50926. get position() {
  50927. return this.chunkPosition + this.i;
  50928. }
  50929. /**
  50930. * The column number of the next character to be read by the parser. *
  50931. * This field is zero-based. (The first column in a line is 0.)
  50932. *
  50933. * This field reports the index at which the next character would be in the
  50934. * line if the line were represented as a JavaScript string. Note that this
  50935. * *can* be different to a count based on the number of *Unicode characters*
  50936. * due to how JavaScript handles astral plane characters.
  50937. *
  50938. * See [[column]] for a number that corresponds to a count of Unicode
  50939. * characters.
  50940. */
  50941. get columnIndex() {
  50942. return this.position - this.positionAtNewLine;
  50943. }
  50944. /**
  50945. * Set an event listener on an event. The parser supports one handler per
  50946. * event type. If you try to set an event handler over an existing handler,
  50947. * the old handler is silently overwritten.
  50948. *
  50949. * @param name The event to listen to.
  50950. *
  50951. * @param handler The handler to set.
  50952. */
  50953. on(name, handler) {
  50954. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  50955. this[EVENT_NAME_TO_HANDLER_NAME[name]] = handler;
  50956. }
  50957. /**
  50958. * Unset an event handler.
  50959. *
  50960. * @parma name The event to stop listening to.
  50961. */
  50962. off(name) {
  50963. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  50964. this[EVENT_NAME_TO_HANDLER_NAME[name]] = undefined;
  50965. }
  50966. /**
  50967. * Make an error object. The error object will have a message that contains
  50968. * the ``fileName`` option passed at the creation of the parser. If position
  50969. * tracking was turned on, it will also have line and column number
  50970. * information.
  50971. *
  50972. * @param message The message describing the error to report.
  50973. *
  50974. * @returns An error object with a properly formatted message.
  50975. */
  50976. makeError(message) {
  50977. var _a;
  50978. let msg = (_a = this.fileName) !== null && _a !== void 0 ? _a : "";
  50979. if (this.trackPosition) {
  50980. if (msg.length > 0) {
  50981. msg += ":";
  50982. }
  50983. msg += `${this.line}:${this.column}`;
  50984. }
  50985. if (msg.length > 0) {
  50986. msg += ": ";
  50987. }
  50988. return new Error(msg + message);
  50989. }
  50990. /**
  50991. * Report a parsing error. This method is made public so that client code may
  50992. * check for issues that are outside the scope of this project and can report
  50993. * errors.
  50994. *
  50995. * @param message The error to report.
  50996. *
  50997. * @returns this
  50998. */
  50999. fail(message) {
  51000. const err = this.makeError(message);
  51001. const handler = this.errorHandler;
  51002. if (handler === undefined) {
  51003. throw err;
  51004. } else {
  51005. handler(err);
  51006. }
  51007. return this;
  51008. }
  51009. /**
  51010. * Write a XML data to the parser.
  51011. *
  51012. * @param chunk The XML data to write.
  51013. *
  51014. * @returns this
  51015. */
  51016. write(chunk) {
  51017. if (this.closed) {
  51018. return this.fail("cannot write after close; assign an onready handler.");
  51019. }
  51020. let end = false;
  51021. if (chunk === null) {
  51022. // We cannot return immediately because carriedFromPrevious may need
  51023. // processing.
  51024. end = true;
  51025. chunk = "";
  51026. } else if (typeof chunk === "object") {
  51027. chunk = chunk.toString();
  51028. }
  51029. // We checked if performing a pre-decomposition of the string into an array
  51030. // of single complete characters (``Array.from(chunk)``) would be faster
  51031. // than the current repeated calls to ``charCodeAt``. As of August 2018, it
  51032. // isn't. (There may be Node-specific code that would perform faster than
  51033. // ``Array.from`` but don't want to be dependent on Node.)
  51034. if (this.carriedFromPrevious !== undefined) {
  51035. // The previous chunk had char we must carry over.
  51036. chunk = `${this.carriedFromPrevious}${chunk}`;
  51037. this.carriedFromPrevious = undefined;
  51038. }
  51039. let limit = chunk.length;
  51040. const lastCode = chunk.charCodeAt(limit - 1);
  51041. if (!end && (
  51042. // A trailing CR or surrogate must be carried over to the next
  51043. // chunk.
  51044. lastCode === CR || lastCode >= 0xD800 && lastCode <= 0xDBFF)) {
  51045. // The chunk ends with a character that must be carried over. We cannot
  51046. // know how to handle it until we get the next chunk or the end of the
  51047. // stream. So save it for later.
  51048. this.carriedFromPrevious = chunk[limit - 1];
  51049. limit--;
  51050. chunk = chunk.slice(0, limit);
  51051. }
  51052. const {
  51053. stateTable
  51054. } = this;
  51055. this.chunk = chunk;
  51056. this.i = 0;
  51057. while (this.i < limit) {
  51058. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  51059. stateTable[this.state].call(this);
  51060. }
  51061. this.chunkPosition += limit;
  51062. return end ? this.end() : this;
  51063. }
  51064. /**
  51065. * Close the current stream. Perform final well-formedness checks and reset
  51066. * the parser tstate.
  51067. *
  51068. * @returns this
  51069. */
  51070. close() {
  51071. return this.write(null);
  51072. }
  51073. /**
  51074. * Get a single code point out of the current chunk. This updates the current
  51075. * position if we do position tracking.
  51076. *
  51077. * This is the algorithm to use for XML 1.0.
  51078. *
  51079. * @returns The character read.
  51080. */
  51081. getCode10() {
  51082. const {
  51083. chunk,
  51084. i
  51085. } = this;
  51086. this.prevI = i;
  51087. // Yes, we do this instead of doing this.i++. Doing it this way, we do not
  51088. // read this.i again, which is a bit faster.
  51089. this.i = i + 1;
  51090. if (i >= chunk.length) {
  51091. return EOC;
  51092. }
  51093. // Using charCodeAt and handling the surrogates ourselves is faster
  51094. // than using codePointAt.
  51095. const code = chunk.charCodeAt(i);
  51096. this.column++;
  51097. if (code < 0xD800) {
  51098. if (code >= SPACE || code === TAB) {
  51099. return code;
  51100. }
  51101. switch (code) {
  51102. case NL:
  51103. this.line++;
  51104. this.column = 0;
  51105. this.positionAtNewLine = this.position;
  51106. return NL;
  51107. case CR:
  51108. // We may get NaN if we read past the end of the chunk, which is fine.
  51109. if (chunk.charCodeAt(i + 1) === NL) {
  51110. // A \r\n sequence is converted to \n so we have to skip over the
  51111. // next character. We already know it has a size of 1 so ++ is fine
  51112. // here.
  51113. this.i = i + 2;
  51114. }
  51115. // Otherwise, a \r is just converted to \n, so we don't have to skip
  51116. // ahead.
  51117. // In either case, \r becomes \n.
  51118. this.line++;
  51119. this.column = 0;
  51120. this.positionAtNewLine = this.position;
  51121. return NL_LIKE;
  51122. default:
  51123. // If we get here, then code < SPACE and it is not NL CR or TAB.
  51124. this.fail("disallowed character.");
  51125. return code;
  51126. }
  51127. }
  51128. if (code > 0xDBFF) {
  51129. // This is a specialized version of isChar10 that takes into account
  51130. // that in this context code > 0xDBFF and code <= 0xFFFF. So it does not
  51131. // test cases that don't need testing.
  51132. if (!(code >= 0xE000 && code <= 0xFFFD)) {
  51133. this.fail("disallowed character.");
  51134. }
  51135. return code;
  51136. }
  51137. const final = 0x10000 + (code - 0xD800) * 0x400 + (chunk.charCodeAt(i + 1) - 0xDC00);
  51138. this.i = i + 2;
  51139. // This is a specialized version of isChar10 that takes into account that in
  51140. // this context necessarily final >= 0x10000.
  51141. if (final > 0x10FFFF) {
  51142. this.fail("disallowed character.");
  51143. }
  51144. return final;
  51145. }
  51146. /**
  51147. * Get a single code point out of the current chunk. This updates the current
  51148. * position if we do position tracking.
  51149. *
  51150. * This is the algorithm to use for XML 1.1.
  51151. *
  51152. * @returns {number} The character read.
  51153. */
  51154. getCode11() {
  51155. const {
  51156. chunk,
  51157. i
  51158. } = this;
  51159. this.prevI = i;
  51160. // Yes, we do this instead of doing this.i++. Doing it this way, we do not
  51161. // read this.i again, which is a bit faster.
  51162. this.i = i + 1;
  51163. if (i >= chunk.length) {
  51164. return EOC;
  51165. }
  51166. // Using charCodeAt and handling the surrogates ourselves is faster
  51167. // than using codePointAt.
  51168. const code = chunk.charCodeAt(i);
  51169. this.column++;
  51170. if (code < 0xD800) {
  51171. if (code > 0x1F && code < 0x7F || code > 0x9F && code !== LS || code === TAB) {
  51172. return code;
  51173. }
  51174. switch (code) {
  51175. case NL:
  51176. // 0xA
  51177. this.line++;
  51178. this.column = 0;
  51179. this.positionAtNewLine = this.position;
  51180. return NL;
  51181. case CR:
  51182. {
  51183. // 0xD
  51184. // We may get NaN if we read past the end of the chunk, which is
  51185. // fine.
  51186. const next = chunk.charCodeAt(i + 1);
  51187. if (next === NL || next === NEL) {
  51188. // A CR NL or CR NEL sequence is converted to NL so we have to skip
  51189. // over the next character. We already know it has a size of 1.
  51190. this.i = i + 2;
  51191. }
  51192. // Otherwise, a CR is just converted to NL, no skip.
  51193. }
  51194. /* yes, fall through */
  51195. case NEL: // 0x85
  51196. case LS:
  51197. // Ox2028
  51198. this.line++;
  51199. this.column = 0;
  51200. this.positionAtNewLine = this.position;
  51201. return NL_LIKE;
  51202. default:
  51203. this.fail("disallowed character.");
  51204. return code;
  51205. }
  51206. }
  51207. if (code > 0xDBFF) {
  51208. // This is a specialized version of isCharAndNotRestricted that takes into
  51209. // account that in this context code > 0xDBFF and code <= 0xFFFF. So it
  51210. // does not test cases that don't need testing.
  51211. if (!(code >= 0xE000 && code <= 0xFFFD)) {
  51212. this.fail("disallowed character.");
  51213. }
  51214. return code;
  51215. }
  51216. const final = 0x10000 + (code - 0xD800) * 0x400 + (chunk.charCodeAt(i + 1) - 0xDC00);
  51217. this.i = i + 2;
  51218. // This is a specialized version of isCharAndNotRestricted that takes into
  51219. // account that in this context necessarily final >= 0x10000.
  51220. if (final > 0x10FFFF) {
  51221. this.fail("disallowed character.");
  51222. }
  51223. return final;
  51224. }
  51225. /**
  51226. * Like ``getCode`` but with the return value normalized so that ``NL`` is
  51227. * returned for ``NL_LIKE``.
  51228. */
  51229. getCodeNorm() {
  51230. const c = this.getCode();
  51231. return c === NL_LIKE ? NL : c;
  51232. }
  51233. unget() {
  51234. this.i = this.prevI;
  51235. this.column--;
  51236. }
  51237. /**
  51238. * Capture characters into a buffer until encountering one of a set of
  51239. * characters.
  51240. *
  51241. * @param chars An array of codepoints. Encountering a character in the array
  51242. * ends the capture. (``chars`` may safely contain ``NL``.)
  51243. *
  51244. * @return The character code that made the capture end, or ``EOC`` if we hit
  51245. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  51246. * instead.
  51247. */
  51248. captureTo(chars) {
  51249. let {
  51250. i: start
  51251. } = this;
  51252. const {
  51253. chunk
  51254. } = this;
  51255. // eslint-disable-next-line no-constant-condition
  51256. while (true) {
  51257. const c = this.getCode();
  51258. const isNLLike = c === NL_LIKE;
  51259. const final = isNLLike ? NL : c;
  51260. if (final === EOC || chars.includes(final)) {
  51261. this.text += chunk.slice(start, this.prevI);
  51262. return final;
  51263. }
  51264. if (isNLLike) {
  51265. this.text += `${chunk.slice(start, this.prevI)}\n`;
  51266. start = this.i;
  51267. }
  51268. }
  51269. }
  51270. /**
  51271. * Capture characters into a buffer until encountering a character.
  51272. *
  51273. * @param char The codepoint that ends the capture. **NOTE ``char`` MAY NOT
  51274. * CONTAIN ``NL``.** Passing ``NL`` will result in buggy behavior.
  51275. *
  51276. * @return ``true`` if we ran into the character. Otherwise, we ran into the
  51277. * end of the current chunk.
  51278. */
  51279. captureToChar(char) {
  51280. let {
  51281. i: start
  51282. } = this;
  51283. const {
  51284. chunk
  51285. } = this;
  51286. // eslint-disable-next-line no-constant-condition
  51287. while (true) {
  51288. let c = this.getCode();
  51289. switch (c) {
  51290. case NL_LIKE:
  51291. this.text += `${chunk.slice(start, this.prevI)}\n`;
  51292. start = this.i;
  51293. c = NL;
  51294. break;
  51295. case EOC:
  51296. this.text += chunk.slice(start);
  51297. return false;
  51298. default:
  51299. }
  51300. if (c === char) {
  51301. this.text += chunk.slice(start, this.prevI);
  51302. return true;
  51303. }
  51304. }
  51305. }
  51306. /**
  51307. * Capture characters that satisfy ``isNameChar`` into the ``name`` field of
  51308. * this parser.
  51309. *
  51310. * @return The character code that made the test fail, or ``EOC`` if we hit
  51311. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  51312. * instead.
  51313. */
  51314. captureNameChars() {
  51315. const {
  51316. chunk,
  51317. i: start
  51318. } = this;
  51319. // eslint-disable-next-line no-constant-condition
  51320. while (true) {
  51321. const c = this.getCode();
  51322. if (c === EOC) {
  51323. this.name += chunk.slice(start);
  51324. return EOC;
  51325. }
  51326. // NL is not a name char so we don't have to test specifically for it.
  51327. if (!isNameChar(c)) {
  51328. this.name += chunk.slice(start, this.prevI);
  51329. return c === NL_LIKE ? NL : c;
  51330. }
  51331. }
  51332. }
  51333. /**
  51334. * Skip white spaces.
  51335. *
  51336. * @return The character that ended the skip, or ``EOC`` if we hit
  51337. * the end of the chunk. The return value cannot be NL_LIKE: NL is returned
  51338. * instead.
  51339. */
  51340. skipSpaces() {
  51341. // eslint-disable-next-line no-constant-condition
  51342. while (true) {
  51343. const c = this.getCodeNorm();
  51344. if (c === EOC || !isS(c)) {
  51345. return c;
  51346. }
  51347. }
  51348. }
  51349. setXMLVersion(version) {
  51350. this.currentXMLVersion = version;
  51351. /* eslint-disable @typescript-eslint/unbound-method */
  51352. if (version === "1.0") {
  51353. this.isChar = isChar10;
  51354. this.getCode = this.getCode10;
  51355. } else {
  51356. this.isChar = isChar11;
  51357. this.getCode = this.getCode11;
  51358. }
  51359. /* eslint-enable @typescript-eslint/unbound-method */
  51360. }
  51361. // STATE ENGINE METHODS
  51362. // This needs to be a state separate from S_BEGIN_WHITESPACE because we want
  51363. // to be sure never to come back to this state later.
  51364. sBegin() {
  51365. // We are essentially peeking at the first character of the chunk. Since
  51366. // S_BEGIN can be in effect only when we start working on the first chunk,
  51367. // the index at which we must look is necessarily 0. Note also that the
  51368. // following test does not depend on decoding surrogates.
  51369. // If the initial character is 0xFEFF, ignore it.
  51370. if (this.chunk.charCodeAt(0) === 0xFEFF) {
  51371. this.i++;
  51372. this.column++;
  51373. }
  51374. this.state = S_BEGIN_WHITESPACE;
  51375. }
  51376. sBeginWhitespace() {
  51377. // We need to know whether we've encountered spaces or not because as soon
  51378. // as we run into a space, an XML declaration is no longer possible. Rather
  51379. // than slow down skipSpaces even in places where we don't care whether it
  51380. // skipped anything or not, we check whether prevI is equal to the value of
  51381. // i from before we skip spaces.
  51382. const iBefore = this.i;
  51383. const c = this.skipSpaces();
  51384. if (this.prevI !== iBefore) {
  51385. this.xmlDeclPossible = false;
  51386. }
  51387. switch (c) {
  51388. case LESS:
  51389. this.state = S_OPEN_WAKA;
  51390. // We could naively call closeText but in this state, it is not normal
  51391. // to have text be filled with any data.
  51392. if (this.text.length !== 0) {
  51393. throw new Error("no-empty text at start");
  51394. }
  51395. break;
  51396. case EOC:
  51397. break;
  51398. default:
  51399. this.unget();
  51400. this.state = S_TEXT;
  51401. this.xmlDeclPossible = false;
  51402. }
  51403. }
  51404. sDoctype() {
  51405. var _a;
  51406. const c = this.captureTo(DOCTYPE_TERMINATOR);
  51407. switch (c) {
  51408. case GREATER:
  51409. {
  51410. // eslint-disable-next-line no-unused-expressions
  51411. (_a = this.doctypeHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  51412. this.text = "";
  51413. this.state = S_TEXT;
  51414. this.doctype = true; // just remember that we saw it.
  51415. break;
  51416. }
  51417. case EOC:
  51418. break;
  51419. default:
  51420. this.text += String.fromCodePoint(c);
  51421. if (c === OPEN_BRACKET) {
  51422. this.state = S_DTD;
  51423. } else if (isQuote(c)) {
  51424. this.state = S_DOCTYPE_QUOTE;
  51425. this.q = c;
  51426. }
  51427. }
  51428. }
  51429. sDoctypeQuote() {
  51430. const q = this.q;
  51431. if (this.captureToChar(q)) {
  51432. this.text += String.fromCodePoint(q);
  51433. this.q = null;
  51434. this.state = S_DOCTYPE;
  51435. }
  51436. }
  51437. sDTD() {
  51438. const c = this.captureTo(DTD_TERMINATOR);
  51439. if (c === EOC) {
  51440. return;
  51441. }
  51442. this.text += String.fromCodePoint(c);
  51443. if (c === CLOSE_BRACKET) {
  51444. this.state = S_DOCTYPE;
  51445. } else if (c === LESS) {
  51446. this.state = S_DTD_OPEN_WAKA;
  51447. } else if (isQuote(c)) {
  51448. this.state = S_DTD_QUOTED;
  51449. this.q = c;
  51450. }
  51451. }
  51452. sDTDQuoted() {
  51453. const q = this.q;
  51454. if (this.captureToChar(q)) {
  51455. this.text += String.fromCodePoint(q);
  51456. this.state = S_DTD;
  51457. this.q = null;
  51458. }
  51459. }
  51460. sDTDOpenWaka() {
  51461. const c = this.getCodeNorm();
  51462. this.text += String.fromCodePoint(c);
  51463. switch (c) {
  51464. case BANG:
  51465. this.state = S_DTD_OPEN_WAKA_BANG;
  51466. this.openWakaBang = "";
  51467. break;
  51468. case QUESTION:
  51469. this.state = S_DTD_PI;
  51470. break;
  51471. default:
  51472. this.state = S_DTD;
  51473. }
  51474. }
  51475. sDTDOpenWakaBang() {
  51476. const char = String.fromCodePoint(this.getCodeNorm());
  51477. const owb = this.openWakaBang += char;
  51478. this.text += char;
  51479. if (owb !== "-") {
  51480. this.state = owb === "--" ? S_DTD_COMMENT : S_DTD;
  51481. this.openWakaBang = "";
  51482. }
  51483. }
  51484. sDTDComment() {
  51485. if (this.captureToChar(MINUS)) {
  51486. this.text += "-";
  51487. this.state = S_DTD_COMMENT_ENDING;
  51488. }
  51489. }
  51490. sDTDCommentEnding() {
  51491. const c = this.getCodeNorm();
  51492. this.text += String.fromCodePoint(c);
  51493. this.state = c === MINUS ? S_DTD_COMMENT_ENDED : S_DTD_COMMENT;
  51494. }
  51495. sDTDCommentEnded() {
  51496. const c = this.getCodeNorm();
  51497. this.text += String.fromCodePoint(c);
  51498. if (c === GREATER) {
  51499. this.state = S_DTD;
  51500. } else {
  51501. this.fail("malformed comment.");
  51502. // <!-- blah -- bloo --> will be recorded as
  51503. // a comment of " blah -- bloo "
  51504. this.state = S_DTD_COMMENT;
  51505. }
  51506. }
  51507. sDTDPI() {
  51508. if (this.captureToChar(QUESTION)) {
  51509. this.text += "?";
  51510. this.state = S_DTD_PI_ENDING;
  51511. }
  51512. }
  51513. sDTDPIEnding() {
  51514. const c = this.getCodeNorm();
  51515. this.text += String.fromCodePoint(c);
  51516. if (c === GREATER) {
  51517. this.state = S_DTD;
  51518. }
  51519. }
  51520. sText() {
  51521. //
  51522. // We did try a version of saxes where the S_TEXT state was split in two
  51523. // states: one for text inside the root element, and one for text
  51524. // outside. This was avoiding having to test this.tags.length to decide
  51525. // what implementation to actually use.
  51526. //
  51527. // Peformance testing on gigabyte-size files did not show any advantage to
  51528. // using the two states solution instead of the current one. Conversely, it
  51529. // made the code a bit more complicated elsewhere. For instance, a comment
  51530. // can appear before the root element so when a comment ended it was
  51531. // necessary to determine whether to return to the S_TEXT state or to the
  51532. // new text-outside-root state.
  51533. //
  51534. if (this.tags.length !== 0) {
  51535. this.handleTextInRoot();
  51536. } else {
  51537. this.handleTextOutsideRoot();
  51538. }
  51539. }
  51540. sEntity() {
  51541. // This is essentially a specialized version of captureToChar(SEMICOLON...)
  51542. let {
  51543. i: start
  51544. } = this;
  51545. const {
  51546. chunk
  51547. } = this;
  51548. // eslint-disable-next-line no-labels, no-restricted-syntax
  51549. loop:
  51550. // eslint-disable-next-line no-constant-condition
  51551. while (true) {
  51552. switch (this.getCode()) {
  51553. case NL_LIKE:
  51554. this.entity += `${chunk.slice(start, this.prevI)}\n`;
  51555. start = this.i;
  51556. break;
  51557. case SEMICOLON:
  51558. {
  51559. const {
  51560. entityReturnState
  51561. } = this;
  51562. const entity = this.entity + chunk.slice(start, this.prevI);
  51563. this.state = entityReturnState;
  51564. let parsed;
  51565. if (entity === "") {
  51566. this.fail("empty entity name.");
  51567. parsed = "&;";
  51568. } else {
  51569. parsed = this.parseEntity(entity);
  51570. this.entity = "";
  51571. }
  51572. if (entityReturnState !== S_TEXT || this.textHandler !== undefined) {
  51573. this.text += parsed;
  51574. }
  51575. // eslint-disable-next-line no-labels
  51576. break loop;
  51577. }
  51578. case EOC:
  51579. this.entity += chunk.slice(start);
  51580. // eslint-disable-next-line no-labels
  51581. break loop;
  51582. default:
  51583. }
  51584. }
  51585. }
  51586. sOpenWaka() {
  51587. // Reminder: a state handler is called with at least one character
  51588. // available in the current chunk. So the first call to get code inside of
  51589. // a state handler cannot return ``EOC``. That's why we don't test
  51590. // for it.
  51591. const c = this.getCode();
  51592. // either a /, ?, !, or text is coming next.
  51593. if (isNameStartChar(c)) {
  51594. this.state = S_OPEN_TAG;
  51595. this.unget();
  51596. this.xmlDeclPossible = false;
  51597. } else {
  51598. switch (c) {
  51599. case FORWARD_SLASH:
  51600. this.state = S_CLOSE_TAG;
  51601. this.xmlDeclPossible = false;
  51602. break;
  51603. case BANG:
  51604. this.state = S_OPEN_WAKA_BANG;
  51605. this.openWakaBang = "";
  51606. this.xmlDeclPossible = false;
  51607. break;
  51608. case QUESTION:
  51609. this.state = S_PI_FIRST_CHAR;
  51610. break;
  51611. default:
  51612. this.fail("disallowed character in tag name");
  51613. this.state = S_TEXT;
  51614. this.xmlDeclPossible = false;
  51615. }
  51616. }
  51617. }
  51618. sOpenWakaBang() {
  51619. this.openWakaBang += String.fromCodePoint(this.getCodeNorm());
  51620. switch (this.openWakaBang) {
  51621. case "[CDATA[":
  51622. if (!this.sawRoot && !this.reportedTextBeforeRoot) {
  51623. this.fail("text data outside of root node.");
  51624. this.reportedTextBeforeRoot = true;
  51625. }
  51626. if (this.closedRoot && !this.reportedTextAfterRoot) {
  51627. this.fail("text data outside of root node.");
  51628. this.reportedTextAfterRoot = true;
  51629. }
  51630. this.state = S_CDATA;
  51631. this.openWakaBang = "";
  51632. break;
  51633. case "--":
  51634. this.state = S_COMMENT;
  51635. this.openWakaBang = "";
  51636. break;
  51637. case "DOCTYPE":
  51638. this.state = S_DOCTYPE;
  51639. if (this.doctype || this.sawRoot) {
  51640. this.fail("inappropriately located doctype declaration.");
  51641. }
  51642. this.openWakaBang = "";
  51643. break;
  51644. default:
  51645. // 7 happens to be the maximum length of the string that can possibly
  51646. // match one of the cases above.
  51647. if (this.openWakaBang.length >= 7) {
  51648. this.fail("incorrect syntax.");
  51649. }
  51650. }
  51651. }
  51652. sComment() {
  51653. if (this.captureToChar(MINUS)) {
  51654. this.state = S_COMMENT_ENDING;
  51655. }
  51656. }
  51657. sCommentEnding() {
  51658. var _a;
  51659. const c = this.getCodeNorm();
  51660. if (c === MINUS) {
  51661. this.state = S_COMMENT_ENDED;
  51662. // eslint-disable-next-line no-unused-expressions
  51663. (_a = this.commentHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  51664. this.text = "";
  51665. } else {
  51666. this.text += `-${String.fromCodePoint(c)}`;
  51667. this.state = S_COMMENT;
  51668. }
  51669. }
  51670. sCommentEnded() {
  51671. const c = this.getCodeNorm();
  51672. if (c !== GREATER) {
  51673. this.fail("malformed comment.");
  51674. // <!-- blah -- bloo --> will be recorded as
  51675. // a comment of " blah -- bloo "
  51676. this.text += `--${String.fromCodePoint(c)}`;
  51677. this.state = S_COMMENT;
  51678. } else {
  51679. this.state = S_TEXT;
  51680. }
  51681. }
  51682. sCData() {
  51683. if (this.captureToChar(CLOSE_BRACKET)) {
  51684. this.state = S_CDATA_ENDING;
  51685. }
  51686. }
  51687. sCDataEnding() {
  51688. const c = this.getCodeNorm();
  51689. if (c === CLOSE_BRACKET) {
  51690. this.state = S_CDATA_ENDING_2;
  51691. } else {
  51692. this.text += `]${String.fromCodePoint(c)}`;
  51693. this.state = S_CDATA;
  51694. }
  51695. }
  51696. sCDataEnding2() {
  51697. var _a;
  51698. const c = this.getCodeNorm();
  51699. switch (c) {
  51700. case GREATER:
  51701. {
  51702. // eslint-disable-next-line no-unused-expressions
  51703. (_a = this.cdataHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.text);
  51704. this.text = "";
  51705. this.state = S_TEXT;
  51706. break;
  51707. }
  51708. case CLOSE_BRACKET:
  51709. this.text += "]";
  51710. break;
  51711. default:
  51712. this.text += `]]${String.fromCodePoint(c)}`;
  51713. this.state = S_CDATA;
  51714. }
  51715. }
  51716. // We need this separate state to check the first character fo the pi target
  51717. // with this.nameStartCheck which allows less characters than this.nameCheck.
  51718. sPIFirstChar() {
  51719. const c = this.getCodeNorm();
  51720. // This is first because in the case where the file is well-formed this is
  51721. // the branch taken. We optimize for well-formedness.
  51722. if (this.nameStartCheck(c)) {
  51723. this.piTarget += String.fromCodePoint(c);
  51724. this.state = S_PI_REST;
  51725. } else if (c === QUESTION || isS(c)) {
  51726. this.fail("processing instruction without a target.");
  51727. this.state = c === QUESTION ? S_PI_ENDING : S_PI_BODY;
  51728. } else {
  51729. this.fail("disallowed character in processing instruction name.");
  51730. this.piTarget += String.fromCodePoint(c);
  51731. this.state = S_PI_REST;
  51732. }
  51733. }
  51734. sPIRest() {
  51735. // Capture characters into a piTarget while ``this.nameCheck`` run on the
  51736. // character read returns true.
  51737. const {
  51738. chunk,
  51739. i: start
  51740. } = this;
  51741. // eslint-disable-next-line no-constant-condition
  51742. while (true) {
  51743. const c = this.getCodeNorm();
  51744. if (c === EOC) {
  51745. this.piTarget += chunk.slice(start);
  51746. return;
  51747. }
  51748. // NL cannot satisfy this.nameCheck so we don't have to test specifically
  51749. // for it.
  51750. if (!this.nameCheck(c)) {
  51751. this.piTarget += chunk.slice(start, this.prevI);
  51752. const isQuestion = c === QUESTION;
  51753. if (isQuestion || isS(c)) {
  51754. if (this.piTarget === "xml") {
  51755. if (!this.xmlDeclPossible) {
  51756. this.fail("an XML declaration must be at the start of the document.");
  51757. }
  51758. this.state = isQuestion ? S_XML_DECL_ENDING : S_XML_DECL_NAME_START;
  51759. } else {
  51760. this.state = isQuestion ? S_PI_ENDING : S_PI_BODY;
  51761. }
  51762. } else {
  51763. this.fail("disallowed character in processing instruction name.");
  51764. this.piTarget += String.fromCodePoint(c);
  51765. }
  51766. break;
  51767. }
  51768. }
  51769. }
  51770. sPIBody() {
  51771. if (this.text.length === 0) {
  51772. const c = this.getCodeNorm();
  51773. if (c === QUESTION) {
  51774. this.state = S_PI_ENDING;
  51775. } else if (!isS(c)) {
  51776. this.text = String.fromCodePoint(c);
  51777. }
  51778. }
  51779. // The question mark character is not valid inside any of the XML
  51780. // declaration name/value pairs.
  51781. else if (this.captureToChar(QUESTION)) {
  51782. this.state = S_PI_ENDING;
  51783. }
  51784. }
  51785. sPIEnding() {
  51786. var _a;
  51787. const c = this.getCodeNorm();
  51788. if (c === GREATER) {
  51789. const {
  51790. piTarget
  51791. } = this;
  51792. if (piTarget.toLowerCase() === "xml") {
  51793. this.fail("the XML declaration must appear at the start of the document.");
  51794. }
  51795. // eslint-disable-next-line no-unused-expressions
  51796. (_a = this.piHandler) === null || _a === void 0 ? void 0 : _a.call(this, {
  51797. target: piTarget,
  51798. body: this.text
  51799. });
  51800. this.piTarget = this.text = "";
  51801. this.state = S_TEXT;
  51802. } else if (c === QUESTION) {
  51803. // We ran into ?? as part of a processing instruction. We initially took
  51804. // the first ? as a sign that the PI was ending, but it is not. So we have
  51805. // to add it to the body but we take the new ? as a sign that the PI is
  51806. // ending.
  51807. this.text += "?";
  51808. } else {
  51809. this.text += `?${String.fromCodePoint(c)}`;
  51810. this.state = S_PI_BODY;
  51811. }
  51812. this.xmlDeclPossible = false;
  51813. }
  51814. sXMLDeclNameStart() {
  51815. const c = this.skipSpaces();
  51816. // The question mark character is not valid inside any of the XML
  51817. // declaration name/value pairs.
  51818. if (c === QUESTION) {
  51819. // It is valid to go to S_XML_DECL_ENDING from this state.
  51820. this.state = S_XML_DECL_ENDING;
  51821. return;
  51822. }
  51823. if (c !== EOC) {
  51824. this.state = S_XML_DECL_NAME;
  51825. this.name = String.fromCodePoint(c);
  51826. }
  51827. }
  51828. sXMLDeclName() {
  51829. const c = this.captureTo(XML_DECL_NAME_TERMINATOR);
  51830. // The question mark character is not valid inside any of the XML
  51831. // declaration name/value pairs.
  51832. if (c === QUESTION) {
  51833. this.state = S_XML_DECL_ENDING;
  51834. this.name += this.text;
  51835. this.text = "";
  51836. this.fail("XML declaration is incomplete.");
  51837. return;
  51838. }
  51839. if (!(isS(c) || c === EQUAL)) {
  51840. return;
  51841. }
  51842. this.name += this.text;
  51843. this.text = "";
  51844. if (!this.xmlDeclExpects.includes(this.name)) {
  51845. switch (this.name.length) {
  51846. case 0:
  51847. this.fail("did not expect any more name/value pairs.");
  51848. break;
  51849. case 1:
  51850. this.fail(`expected the name ${this.xmlDeclExpects[0]}.`);
  51851. break;
  51852. default:
  51853. this.fail(`expected one of ${this.xmlDeclExpects.join(", ")}`);
  51854. }
  51855. }
  51856. this.state = c === EQUAL ? S_XML_DECL_VALUE_START : S_XML_DECL_EQ;
  51857. }
  51858. sXMLDeclEq() {
  51859. const c = this.getCodeNorm();
  51860. // The question mark character is not valid inside any of the XML
  51861. // declaration name/value pairs.
  51862. if (c === QUESTION) {
  51863. this.state = S_XML_DECL_ENDING;
  51864. this.fail("XML declaration is incomplete.");
  51865. return;
  51866. }
  51867. if (isS(c)) {
  51868. return;
  51869. }
  51870. if (c !== EQUAL) {
  51871. this.fail("value required.");
  51872. }
  51873. this.state = S_XML_DECL_VALUE_START;
  51874. }
  51875. sXMLDeclValueStart() {
  51876. const c = this.getCodeNorm();
  51877. // The question mark character is not valid inside any of the XML
  51878. // declaration name/value pairs.
  51879. if (c === QUESTION) {
  51880. this.state = S_XML_DECL_ENDING;
  51881. this.fail("XML declaration is incomplete.");
  51882. return;
  51883. }
  51884. if (isS(c)) {
  51885. return;
  51886. }
  51887. if (!isQuote(c)) {
  51888. this.fail("value must be quoted.");
  51889. this.q = SPACE;
  51890. } else {
  51891. this.q = c;
  51892. }
  51893. this.state = S_XML_DECL_VALUE;
  51894. }
  51895. sXMLDeclValue() {
  51896. const c = this.captureTo([this.q, QUESTION]);
  51897. // The question mark character is not valid inside any of the XML
  51898. // declaration name/value pairs.
  51899. if (c === QUESTION) {
  51900. this.state = S_XML_DECL_ENDING;
  51901. this.text = "";
  51902. this.fail("XML declaration is incomplete.");
  51903. return;
  51904. }
  51905. if (c === EOC) {
  51906. return;
  51907. }
  51908. const value = this.text;
  51909. this.text = "";
  51910. switch (this.name) {
  51911. case "version":
  51912. {
  51913. this.xmlDeclExpects = ["encoding", "standalone"];
  51914. const version = value;
  51915. this.xmlDecl.version = version;
  51916. // This is the test specified by XML 1.0 but it is fine for XML 1.1.
  51917. if (!/^1\.[0-9]+$/.test(version)) {
  51918. this.fail("version number must match /^1\\.[0-9]+$/.");
  51919. }
  51920. // When forceXMLVersion is set, the XML declaration is ignored.
  51921. else if (!this.opt.forceXMLVersion) {
  51922. this.setXMLVersion(version);
  51923. }
  51924. break;
  51925. }
  51926. case "encoding":
  51927. if (!/^[A-Za-z][A-Za-z0-9._-]*$/.test(value)) {
  51928. this.fail("encoding value must match \
  51929. /^[A-Za-z0-9][A-Za-z0-9._-]*$/.");
  51930. }
  51931. this.xmlDeclExpects = ["standalone"];
  51932. this.xmlDecl.encoding = value;
  51933. break;
  51934. case "standalone":
  51935. if (value !== "yes" && value !== "no") {
  51936. this.fail("standalone value must match \"yes\" or \"no\".");
  51937. }
  51938. this.xmlDeclExpects = [];
  51939. this.xmlDecl.standalone = value;
  51940. break;
  51941. default:
  51942. // We don't need to raise an error here since we've already raised one
  51943. // when checking what name was expected.
  51944. }
  51945. this.name = "";
  51946. this.state = S_XML_DECL_SEPARATOR;
  51947. }
  51948. sXMLDeclSeparator() {
  51949. const c = this.getCodeNorm();
  51950. // The question mark character is not valid inside any of the XML
  51951. // declaration name/value pairs.
  51952. if (c === QUESTION) {
  51953. // It is valid to go to S_XML_DECL_ENDING from this state.
  51954. this.state = S_XML_DECL_ENDING;
  51955. return;
  51956. }
  51957. if (!isS(c)) {
  51958. this.fail("whitespace required.");
  51959. this.unget();
  51960. }
  51961. this.state = S_XML_DECL_NAME_START;
  51962. }
  51963. sXMLDeclEnding() {
  51964. var _a;
  51965. const c = this.getCodeNorm();
  51966. if (c === GREATER) {
  51967. if (this.piTarget !== "xml") {
  51968. this.fail("processing instructions are not allowed before root.");
  51969. } else if (this.name !== "version" && this.xmlDeclExpects.includes("version")) {
  51970. this.fail("XML declaration must contain a version.");
  51971. }
  51972. // eslint-disable-next-line no-unused-expressions
  51973. (_a = this.xmldeclHandler) === null || _a === void 0 ? void 0 : _a.call(this, this.xmlDecl);
  51974. this.name = "";
  51975. this.piTarget = this.text = "";
  51976. this.state = S_TEXT;
  51977. } else {
  51978. // We got here because the previous character was a ?, but the question
  51979. // mark character is not valid inside any of the XML declaration
  51980. // name/value pairs.
  51981. this.fail("The character ? is disallowed anywhere in XML declarations.");
  51982. }
  51983. this.xmlDeclPossible = false;
  51984. }
  51985. sOpenTag() {
  51986. var _a;
  51987. const c = this.captureNameChars();
  51988. if (c === EOC) {
  51989. return;
  51990. }
  51991. const tag = this.tag = {
  51992. name: this.name,
  51993. attributes: Object.create(null)
  51994. };
  51995. this.name = "";
  51996. if (this.xmlnsOpt) {
  51997. this.topNS = tag.ns = Object.create(null);
  51998. }
  51999. // eslint-disable-next-line no-unused-expressions
  52000. (_a = this.openTagStartHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  52001. this.sawRoot = true;
  52002. if (!this.fragmentOpt && this.closedRoot) {
  52003. this.fail("documents may contain only one root.");
  52004. }
  52005. switch (c) {
  52006. case GREATER:
  52007. this.openTag();
  52008. break;
  52009. case FORWARD_SLASH:
  52010. this.state = S_OPEN_TAG_SLASH;
  52011. break;
  52012. default:
  52013. if (!isS(c)) {
  52014. this.fail("disallowed character in tag name.");
  52015. }
  52016. this.state = S_ATTRIB;
  52017. }
  52018. }
  52019. sOpenTagSlash() {
  52020. if (this.getCode() === GREATER) {
  52021. this.openSelfClosingTag();
  52022. } else {
  52023. this.fail("forward-slash in opening tag not followed by >.");
  52024. this.state = S_ATTRIB;
  52025. }
  52026. }
  52027. sAttrib() {
  52028. const c = this.skipSpaces();
  52029. if (c === EOC) {
  52030. return;
  52031. }
  52032. if (isNameStartChar(c)) {
  52033. this.unget();
  52034. this.state = S_ATTRIB_NAME;
  52035. } else if (c === GREATER) {
  52036. this.openTag();
  52037. } else if (c === FORWARD_SLASH) {
  52038. this.state = S_OPEN_TAG_SLASH;
  52039. } else {
  52040. this.fail("disallowed character in attribute name.");
  52041. }
  52042. }
  52043. sAttribName() {
  52044. const c = this.captureNameChars();
  52045. if (c === EQUAL) {
  52046. this.state = S_ATTRIB_VALUE;
  52047. } else if (isS(c)) {
  52048. this.state = S_ATTRIB_NAME_SAW_WHITE;
  52049. } else if (c === GREATER) {
  52050. this.fail("attribute without value.");
  52051. this.pushAttrib(this.name, this.name);
  52052. this.name = this.text = "";
  52053. this.openTag();
  52054. } else if (c !== EOC) {
  52055. this.fail("disallowed character in attribute name.");
  52056. }
  52057. }
  52058. sAttribNameSawWhite() {
  52059. const c = this.skipSpaces();
  52060. switch (c) {
  52061. case EOC:
  52062. return;
  52063. case EQUAL:
  52064. this.state = S_ATTRIB_VALUE;
  52065. break;
  52066. default:
  52067. this.fail("attribute without value.");
  52068. // Should we do this???
  52069. // this.tag.attributes[this.name] = "";
  52070. this.text = "";
  52071. this.name = "";
  52072. if (c === GREATER) {
  52073. this.openTag();
  52074. } else if (isNameStartChar(c)) {
  52075. this.unget();
  52076. this.state = S_ATTRIB_NAME;
  52077. } else {
  52078. this.fail("disallowed character in attribute name.");
  52079. this.state = S_ATTRIB;
  52080. }
  52081. }
  52082. }
  52083. sAttribValue() {
  52084. const c = this.getCodeNorm();
  52085. if (isQuote(c)) {
  52086. this.q = c;
  52087. this.state = S_ATTRIB_VALUE_QUOTED;
  52088. } else if (!isS(c)) {
  52089. this.fail("unquoted attribute value.");
  52090. this.state = S_ATTRIB_VALUE_UNQUOTED;
  52091. this.unget();
  52092. }
  52093. }
  52094. sAttribValueQuoted() {
  52095. // We deliberately do not use captureTo here. The specialized code we use
  52096. // here is faster than using captureTo.
  52097. const {
  52098. q,
  52099. chunk
  52100. } = this;
  52101. let {
  52102. i: start
  52103. } = this;
  52104. // eslint-disable-next-line no-constant-condition
  52105. while (true) {
  52106. switch (this.getCode()) {
  52107. case q:
  52108. this.pushAttrib(this.name, this.text + chunk.slice(start, this.prevI));
  52109. this.name = this.text = "";
  52110. this.q = null;
  52111. this.state = S_ATTRIB_VALUE_CLOSED;
  52112. return;
  52113. case AMP:
  52114. this.text += chunk.slice(start, this.prevI);
  52115. this.state = S_ENTITY;
  52116. this.entityReturnState = S_ATTRIB_VALUE_QUOTED;
  52117. return;
  52118. case NL:
  52119. case NL_LIKE:
  52120. case TAB:
  52121. this.text += `${chunk.slice(start, this.prevI)} `;
  52122. start = this.i;
  52123. break;
  52124. case LESS:
  52125. this.text += chunk.slice(start, this.prevI);
  52126. this.fail("disallowed character.");
  52127. return;
  52128. case EOC:
  52129. this.text += chunk.slice(start);
  52130. return;
  52131. default:
  52132. }
  52133. }
  52134. }
  52135. sAttribValueClosed() {
  52136. const c = this.getCodeNorm();
  52137. if (isS(c)) {
  52138. this.state = S_ATTRIB;
  52139. } else if (c === GREATER) {
  52140. this.openTag();
  52141. } else if (c === FORWARD_SLASH) {
  52142. this.state = S_OPEN_TAG_SLASH;
  52143. } else if (isNameStartChar(c)) {
  52144. this.fail("no whitespace between attributes.");
  52145. this.unget();
  52146. this.state = S_ATTRIB_NAME;
  52147. } else {
  52148. this.fail("disallowed character in attribute name.");
  52149. }
  52150. }
  52151. sAttribValueUnquoted() {
  52152. // We don't do anything regarding EOL or space handling for unquoted
  52153. // attributes. We already have failed by the time we get here, and the
  52154. // contract that saxes upholds states that upon failure, it is not safe to
  52155. // rely on the data passed to event handlers (other than
  52156. // ``onerror``). Passing "bad" data is not a problem.
  52157. const c = this.captureTo(ATTRIB_VALUE_UNQUOTED_TERMINATOR);
  52158. switch (c) {
  52159. case AMP:
  52160. this.state = S_ENTITY;
  52161. this.entityReturnState = S_ATTRIB_VALUE_UNQUOTED;
  52162. break;
  52163. case LESS:
  52164. this.fail("disallowed character.");
  52165. break;
  52166. case EOC:
  52167. break;
  52168. default:
  52169. if (this.text.includes("]]>")) {
  52170. this.fail("the string \"]]>\" is disallowed in char data.");
  52171. }
  52172. this.pushAttrib(this.name, this.text);
  52173. this.name = this.text = "";
  52174. if (c === GREATER) {
  52175. this.openTag();
  52176. } else {
  52177. this.state = S_ATTRIB;
  52178. }
  52179. }
  52180. }
  52181. sCloseTag() {
  52182. const c = this.captureNameChars();
  52183. if (c === GREATER) {
  52184. this.closeTag();
  52185. } else if (isS(c)) {
  52186. this.state = S_CLOSE_TAG_SAW_WHITE;
  52187. } else if (c !== EOC) {
  52188. this.fail("disallowed character in closing tag.");
  52189. }
  52190. }
  52191. sCloseTagSawWhite() {
  52192. switch (this.skipSpaces()) {
  52193. case GREATER:
  52194. this.closeTag();
  52195. break;
  52196. case EOC:
  52197. break;
  52198. default:
  52199. this.fail("disallowed character in closing tag.");
  52200. }
  52201. }
  52202. // END OF STATE ENGINE METHODS
  52203. handleTextInRoot() {
  52204. // This is essentially a specialized version of captureTo which is optimized
  52205. // for performing the ]]> check. A previous version of this code, checked
  52206. // ``this.text`` for the presence of ]]>. It simplified the code but was
  52207. // very costly when character data contained a lot of entities to be parsed.
  52208. //
  52209. // Since we are using a specialized loop, we also keep track of the presence
  52210. // of ]]> in text data. The sequence ]]> is forbidden to appear as-is.
  52211. //
  52212. let {
  52213. i: start,
  52214. forbiddenState
  52215. } = this;
  52216. const {
  52217. chunk,
  52218. textHandler: handler
  52219. } = this;
  52220. // eslint-disable-next-line no-labels, no-restricted-syntax
  52221. scanLoop:
  52222. // eslint-disable-next-line no-constant-condition
  52223. while (true) {
  52224. switch (this.getCode()) {
  52225. case LESS:
  52226. {
  52227. this.state = S_OPEN_WAKA;
  52228. if (handler !== undefined) {
  52229. const {
  52230. text
  52231. } = this;
  52232. const slice = chunk.slice(start, this.prevI);
  52233. if (text.length !== 0) {
  52234. handler(text + slice);
  52235. this.text = "";
  52236. } else if (slice.length !== 0) {
  52237. handler(slice);
  52238. }
  52239. }
  52240. forbiddenState = FORBIDDEN_START;
  52241. // eslint-disable-next-line no-labels
  52242. break scanLoop;
  52243. }
  52244. case AMP:
  52245. this.state = S_ENTITY;
  52246. this.entityReturnState = S_TEXT;
  52247. if (handler !== undefined) {
  52248. this.text += chunk.slice(start, this.prevI);
  52249. }
  52250. forbiddenState = FORBIDDEN_START;
  52251. // eslint-disable-next-line no-labels
  52252. break scanLoop;
  52253. case CLOSE_BRACKET:
  52254. switch (forbiddenState) {
  52255. case FORBIDDEN_START:
  52256. forbiddenState = FORBIDDEN_BRACKET;
  52257. break;
  52258. case FORBIDDEN_BRACKET:
  52259. forbiddenState = FORBIDDEN_BRACKET_BRACKET;
  52260. break;
  52261. case FORBIDDEN_BRACKET_BRACKET:
  52262. break;
  52263. default:
  52264. throw new Error("impossible state");
  52265. }
  52266. break;
  52267. case GREATER:
  52268. if (forbiddenState === FORBIDDEN_BRACKET_BRACKET) {
  52269. this.fail("the string \"]]>\" is disallowed in char data.");
  52270. }
  52271. forbiddenState = FORBIDDEN_START;
  52272. break;
  52273. case NL_LIKE:
  52274. if (handler !== undefined) {
  52275. this.text += `${chunk.slice(start, this.prevI)}\n`;
  52276. }
  52277. start = this.i;
  52278. forbiddenState = FORBIDDEN_START;
  52279. break;
  52280. case EOC:
  52281. if (handler !== undefined) {
  52282. this.text += chunk.slice(start);
  52283. }
  52284. // eslint-disable-next-line no-labels
  52285. break scanLoop;
  52286. default:
  52287. forbiddenState = FORBIDDEN_START;
  52288. }
  52289. }
  52290. this.forbiddenState = forbiddenState;
  52291. }
  52292. handleTextOutsideRoot() {
  52293. // This is essentially a specialized version of captureTo which is optimized
  52294. // for a specialized task. We keep track of the presence of non-space
  52295. // characters in the text since these are errors when appearing outside the
  52296. // document root element.
  52297. let {
  52298. i: start
  52299. } = this;
  52300. const {
  52301. chunk,
  52302. textHandler: handler
  52303. } = this;
  52304. let nonSpace = false;
  52305. // eslint-disable-next-line no-labels, no-restricted-syntax
  52306. outRootLoop:
  52307. // eslint-disable-next-line no-constant-condition
  52308. while (true) {
  52309. const code = this.getCode();
  52310. switch (code) {
  52311. case LESS:
  52312. {
  52313. this.state = S_OPEN_WAKA;
  52314. if (handler !== undefined) {
  52315. const {
  52316. text
  52317. } = this;
  52318. const slice = chunk.slice(start, this.prevI);
  52319. if (text.length !== 0) {
  52320. handler(text + slice);
  52321. this.text = "";
  52322. } else if (slice.length !== 0) {
  52323. handler(slice);
  52324. }
  52325. }
  52326. // eslint-disable-next-line no-labels
  52327. break outRootLoop;
  52328. }
  52329. case AMP:
  52330. this.state = S_ENTITY;
  52331. this.entityReturnState = S_TEXT;
  52332. if (handler !== undefined) {
  52333. this.text += chunk.slice(start, this.prevI);
  52334. }
  52335. nonSpace = true;
  52336. // eslint-disable-next-line no-labels
  52337. break outRootLoop;
  52338. case NL_LIKE:
  52339. if (handler !== undefined) {
  52340. this.text += `${chunk.slice(start, this.prevI)}\n`;
  52341. }
  52342. start = this.i;
  52343. break;
  52344. case EOC:
  52345. if (handler !== undefined) {
  52346. this.text += chunk.slice(start);
  52347. }
  52348. // eslint-disable-next-line no-labels
  52349. break outRootLoop;
  52350. default:
  52351. if (!isS(code)) {
  52352. nonSpace = true;
  52353. }
  52354. }
  52355. }
  52356. if (!nonSpace) {
  52357. return;
  52358. }
  52359. // We use the reportedTextBeforeRoot and reportedTextAfterRoot flags
  52360. // to avoid reporting errors for every single character that is out of
  52361. // place.
  52362. if (!this.sawRoot && !this.reportedTextBeforeRoot) {
  52363. this.fail("text data outside of root node.");
  52364. this.reportedTextBeforeRoot = true;
  52365. }
  52366. if (this.closedRoot && !this.reportedTextAfterRoot) {
  52367. this.fail("text data outside of root node.");
  52368. this.reportedTextAfterRoot = true;
  52369. }
  52370. }
  52371. pushAttribNS(name, value) {
  52372. var _a;
  52373. const {
  52374. prefix,
  52375. local
  52376. } = this.qname(name);
  52377. const attr = {
  52378. name,
  52379. prefix,
  52380. local,
  52381. value
  52382. };
  52383. this.attribList.push(attr);
  52384. // eslint-disable-next-line no-unused-expressions
  52385. (_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
  52386. if (prefix === "xmlns") {
  52387. const trimmed = value.trim();
  52388. if (this.currentXMLVersion === "1.0" && trimmed === "") {
  52389. this.fail("invalid attempt to undefine prefix in XML 1.0");
  52390. }
  52391. this.topNS[local] = trimmed;
  52392. nsPairCheck(this, local, trimmed);
  52393. } else if (name === "xmlns") {
  52394. const trimmed = value.trim();
  52395. this.topNS[""] = trimmed;
  52396. nsPairCheck(this, "", trimmed);
  52397. }
  52398. }
  52399. pushAttribPlain(name, value) {
  52400. var _a;
  52401. const attr = {
  52402. name,
  52403. value
  52404. };
  52405. this.attribList.push(attr);
  52406. // eslint-disable-next-line no-unused-expressions
  52407. (_a = this.attributeHandler) === null || _a === void 0 ? void 0 : _a.call(this, attr);
  52408. }
  52409. /**
  52410. * End parsing. This performs final well-formedness checks and resets the
  52411. * parser to a clean state.
  52412. *
  52413. * @returns this
  52414. */
  52415. end() {
  52416. var _a, _b;
  52417. if (!this.sawRoot) {
  52418. this.fail("document must contain a root element.");
  52419. }
  52420. const {
  52421. tags
  52422. } = this;
  52423. while (tags.length > 0) {
  52424. const tag = tags.pop();
  52425. this.fail(`unclosed tag: ${tag.name}`);
  52426. }
  52427. if (this.state !== S_BEGIN && this.state !== S_TEXT) {
  52428. this.fail("unexpected end.");
  52429. }
  52430. const {
  52431. text
  52432. } = this;
  52433. if (text.length !== 0) {
  52434. // eslint-disable-next-line no-unused-expressions
  52435. (_a = this.textHandler) === null || _a === void 0 ? void 0 : _a.call(this, text);
  52436. this.text = "";
  52437. }
  52438. this._closed = true;
  52439. // eslint-disable-next-line no-unused-expressions
  52440. (_b = this.endHandler) === null || _b === void 0 ? void 0 : _b.call(this);
  52441. this._init();
  52442. return this;
  52443. }
  52444. /**
  52445. * Resolve a namespace prefix.
  52446. *
  52447. * @param prefix The prefix to resolve.
  52448. *
  52449. * @returns The namespace URI or ``undefined`` if the prefix is not defined.
  52450. */
  52451. resolve(prefix) {
  52452. var _a, _b;
  52453. let uri = this.topNS[prefix];
  52454. if (uri !== undefined) {
  52455. return uri;
  52456. }
  52457. const {
  52458. tags
  52459. } = this;
  52460. for (let index = tags.length - 1; index >= 0; index--) {
  52461. uri = tags[index].ns[prefix];
  52462. if (uri !== undefined) {
  52463. return uri;
  52464. }
  52465. }
  52466. uri = this.ns[prefix];
  52467. if (uri !== undefined) {
  52468. return uri;
  52469. }
  52470. return (_b = (_a = this.opt).resolvePrefix) === null || _b === void 0 ? void 0 : _b.call(_a, prefix);
  52471. }
  52472. /**
  52473. * Parse a qname into its prefix and local name parts.
  52474. *
  52475. * @param name The name to parse
  52476. *
  52477. * @returns
  52478. */
  52479. qname(name) {
  52480. // This is faster than using name.split(":").
  52481. const colon = name.indexOf(":");
  52482. if (colon === -1) {
  52483. return {
  52484. prefix: "",
  52485. local: name
  52486. };
  52487. }
  52488. const local = name.slice(colon + 1);
  52489. const prefix = name.slice(0, colon);
  52490. if (prefix === "" || local === "" || local.includes(":")) {
  52491. this.fail(`malformed name: ${name}.`);
  52492. }
  52493. return {
  52494. prefix,
  52495. local
  52496. };
  52497. }
  52498. processAttribsNS() {
  52499. var _a;
  52500. const {
  52501. attribList
  52502. } = this;
  52503. const tag = this.tag;
  52504. {
  52505. // add namespace info to tag
  52506. const {
  52507. prefix,
  52508. local
  52509. } = this.qname(tag.name);
  52510. tag.prefix = prefix;
  52511. tag.local = local;
  52512. const uri = tag.uri = (_a = this.resolve(prefix)) !== null && _a !== void 0 ? _a : "";
  52513. if (prefix !== "") {
  52514. if (prefix === "xmlns") {
  52515. this.fail("tags may not have \"xmlns\" as prefix.");
  52516. }
  52517. if (uri === "") {
  52518. this.fail(`unbound namespace prefix: ${JSON.stringify(prefix)}.`);
  52519. tag.uri = prefix;
  52520. }
  52521. }
  52522. }
  52523. if (attribList.length === 0) {
  52524. return;
  52525. }
  52526. const {
  52527. attributes
  52528. } = tag;
  52529. const seen = new Set();
  52530. // Note: do not apply default ns to attributes:
  52531. // http://www.w3.org/TR/REC-xml-names/#defaulting
  52532. for (const attr of attribList) {
  52533. const {
  52534. name,
  52535. prefix,
  52536. local
  52537. } = attr;
  52538. let uri;
  52539. let eqname;
  52540. if (prefix === "") {
  52541. uri = name === "xmlns" ? XMLNS_NAMESPACE : "";
  52542. eqname = name;
  52543. } else {
  52544. uri = this.resolve(prefix);
  52545. // if there's any attributes with an undefined namespace,
  52546. // then fail on them now.
  52547. if (uri === undefined) {
  52548. this.fail(`unbound namespace prefix: ${JSON.stringify(prefix)}.`);
  52549. uri = prefix;
  52550. }
  52551. eqname = `{${uri}}${local}`;
  52552. }
  52553. if (seen.has(eqname)) {
  52554. this.fail(`duplicate attribute: ${eqname}.`);
  52555. }
  52556. seen.add(eqname);
  52557. attr.uri = uri;
  52558. attributes[name] = attr;
  52559. }
  52560. this.attribList = [];
  52561. }
  52562. processAttribsPlain() {
  52563. const {
  52564. attribList
  52565. } = this;
  52566. // eslint-disable-next-line prefer-destructuring
  52567. const attributes = this.tag.attributes;
  52568. for (const {
  52569. name,
  52570. value
  52571. } of attribList) {
  52572. if (attributes[name] !== undefined) {
  52573. this.fail(`duplicate attribute: ${name}.`);
  52574. }
  52575. attributes[name] = value;
  52576. }
  52577. this.attribList = [];
  52578. }
  52579. /**
  52580. * Handle a complete open tag. This parser code calls this once it has seen
  52581. * the whole tag. This method checks for well-formeness and then emits
  52582. * ``onopentag``.
  52583. */
  52584. openTag() {
  52585. var _a;
  52586. this.processAttribs();
  52587. const {
  52588. tags
  52589. } = this;
  52590. const tag = this.tag;
  52591. tag.isSelfClosing = false;
  52592. // There cannot be any pending text here due to the onopentagstart that was
  52593. // necessarily emitted before we get here. So we do not check text.
  52594. // eslint-disable-next-line no-unused-expressions
  52595. (_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  52596. tags.push(tag);
  52597. this.state = S_TEXT;
  52598. this.name = "";
  52599. }
  52600. /**
  52601. * Handle a complete self-closing tag. This parser code calls this once it has
  52602. * seen the whole tag. This method checks for well-formeness and then emits
  52603. * ``onopentag`` and ``onclosetag``.
  52604. */
  52605. openSelfClosingTag() {
  52606. var _a, _b, _c;
  52607. this.processAttribs();
  52608. const {
  52609. tags
  52610. } = this;
  52611. const tag = this.tag;
  52612. tag.isSelfClosing = true;
  52613. // There cannot be any pending text here due to the onopentagstart that was
  52614. // necessarily emitted before we get here. So we do not check text.
  52615. // eslint-disable-next-line no-unused-expressions
  52616. (_a = this.openTagHandler) === null || _a === void 0 ? void 0 : _a.call(this, tag);
  52617. // eslint-disable-next-line no-unused-expressions
  52618. (_b = this.closeTagHandler) === null || _b === void 0 ? void 0 : _b.call(this, tag);
  52619. const top = this.tag = (_c = tags[tags.length - 1]) !== null && _c !== void 0 ? _c : null;
  52620. if (top === null) {
  52621. this.closedRoot = true;
  52622. }
  52623. this.state = S_TEXT;
  52624. this.name = "";
  52625. }
  52626. /**
  52627. * Handle a complete close tag. This parser code calls this once it has seen
  52628. * the whole tag. This method checks for well-formeness and then emits
  52629. * ``onclosetag``.
  52630. */
  52631. closeTag() {
  52632. const {
  52633. tags,
  52634. name
  52635. } = this;
  52636. // Our state after this will be S_TEXT, no matter what, and we can clear
  52637. // tagName now.
  52638. this.state = S_TEXT;
  52639. this.name = "";
  52640. if (name === "") {
  52641. this.fail("weird empty close tag.");
  52642. this.text += "</>";
  52643. return;
  52644. }
  52645. const handler = this.closeTagHandler;
  52646. let l = tags.length;
  52647. while (l-- > 0) {
  52648. const tag = this.tag = tags.pop();
  52649. this.topNS = tag.ns;
  52650. // eslint-disable-next-line no-unused-expressions
  52651. handler === null || handler === void 0 ? void 0 : handler(tag);
  52652. if (tag.name === name) {
  52653. break;
  52654. }
  52655. this.fail("unexpected close tag.");
  52656. }
  52657. if (l === 0) {
  52658. this.closedRoot = true;
  52659. } else if (l < 0) {
  52660. this.fail(`unmatched closing tag: ${name}.`);
  52661. this.text += `</${name}>`;
  52662. }
  52663. }
  52664. /**
  52665. * Resolves an entity. Makes any necessary well-formedness checks.
  52666. *
  52667. * @param entity The entity to resolve.
  52668. *
  52669. * @returns The parsed entity.
  52670. */
  52671. parseEntity(entity) {
  52672. // startsWith would be significantly slower for this test.
  52673. // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
  52674. if (entity[0] !== "#") {
  52675. const defined = this.ENTITIES[entity];
  52676. if (defined !== undefined) {
  52677. return defined;
  52678. }
  52679. this.fail(this.isName(entity) ? "undefined entity." : "disallowed character in entity name.");
  52680. return `&${entity};`;
  52681. }
  52682. let num = NaN;
  52683. if (entity[1] === "x" && /^#x[0-9a-f]+$/i.test(entity)) {
  52684. num = parseInt(entity.slice(2), 16);
  52685. } else if (/^#[0-9]+$/.test(entity)) {
  52686. num = parseInt(entity.slice(1), 10);
  52687. }
  52688. // The character reference is required to match the CHAR production.
  52689. if (!this.isChar(num)) {
  52690. this.fail("malformed character entity.");
  52691. return `&${entity};`;
  52692. }
  52693. return String.fromCodePoint(num);
  52694. }
  52695. }
  52696. exports.SaxesParser = SaxesParser;
  52697. },{"xmlchars/xml/1.0/ed5":543,"xmlchars/xml/1.1/ed2":544,"xmlchars/xmlns/1.0/ed3":545}],497:[function(require,module,exports){
  52698. "use strict";
  52699. var Buffer = require('safe-buffer').Buffer;
  52700. // prototype class for hash functions
  52701. function Hash(blockSize, finalSize) {
  52702. this._block = Buffer.alloc(blockSize);
  52703. this._finalSize = finalSize;
  52704. this._blockSize = blockSize;
  52705. this._len = 0;
  52706. }
  52707. Hash.prototype.update = function (data, enc) {
  52708. if (typeof data === 'string') {
  52709. enc = enc || 'utf8';
  52710. data = Buffer.from(data, enc);
  52711. }
  52712. var block = this._block;
  52713. var blockSize = this._blockSize;
  52714. var length = data.length;
  52715. var accum = this._len;
  52716. for (var offset = 0; offset < length;) {
  52717. var assigned = accum % blockSize;
  52718. var remainder = Math.min(length - offset, blockSize - assigned);
  52719. for (var i = 0; i < remainder; i++) {
  52720. block[assigned + i] = data[offset + i];
  52721. }
  52722. accum += remainder;
  52723. offset += remainder;
  52724. if (accum % blockSize === 0) {
  52725. this._update(block);
  52726. }
  52727. }
  52728. this._len += length;
  52729. return this;
  52730. };
  52731. Hash.prototype.digest = function (enc) {
  52732. var rem = this._len % this._blockSize;
  52733. this._block[rem] = 0x80;
  52734. // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
  52735. // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
  52736. this._block.fill(0, rem + 1);
  52737. if (rem >= this._finalSize) {
  52738. this._update(this._block);
  52739. this._block.fill(0);
  52740. }
  52741. var bits = this._len * 8;
  52742. // uint32
  52743. if (bits <= 0xffffffff) {
  52744. this._block.writeUInt32BE(bits, this._blockSize - 4);
  52745. // uint64
  52746. } else {
  52747. var lowBits = (bits & 0xffffffff) >>> 0;
  52748. var highBits = (bits - lowBits) / 0x100000000;
  52749. this._block.writeUInt32BE(highBits, this._blockSize - 8);
  52750. this._block.writeUInt32BE(lowBits, this._blockSize - 4);
  52751. }
  52752. this._update(this._block);
  52753. var hash = this._hash();
  52754. return enc ? hash.toString(enc) : hash;
  52755. };
  52756. Hash.prototype._update = function () {
  52757. throw new Error('_update must be implemented by subclass');
  52758. };
  52759. module.exports = Hash;
  52760. },{"safe-buffer":494}],498:[function(require,module,exports){
  52761. "use strict";
  52762. var _exports = module.exports = function SHA(algorithm) {
  52763. algorithm = algorithm.toLowerCase();
  52764. var Algorithm = _exports[algorithm];
  52765. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)');
  52766. return new Algorithm();
  52767. };
  52768. _exports.sha = require('./sha');
  52769. _exports.sha1 = require('./sha1');
  52770. _exports.sha224 = require('./sha224');
  52771. _exports.sha256 = require('./sha256');
  52772. _exports.sha384 = require('./sha384');
  52773. _exports.sha512 = require('./sha512');
  52774. },{"./sha":499,"./sha1":500,"./sha224":501,"./sha256":502,"./sha384":503,"./sha512":504}],499:[function(require,module,exports){
  52775. "use strict";
  52776. /*
  52777. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  52778. * in FIPS PUB 180-1
  52779. * This source code is derived from sha1.js of the same repository.
  52780. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  52781. * operation was added.
  52782. */
  52783. var inherits = require('inherits');
  52784. var Hash = require('./hash');
  52785. var Buffer = require('safe-buffer').Buffer;
  52786. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  52787. var W = new Array(80);
  52788. function Sha() {
  52789. this.init();
  52790. this._w = W;
  52791. Hash.call(this, 64, 56);
  52792. }
  52793. inherits(Sha, Hash);
  52794. Sha.prototype.init = function () {
  52795. this._a = 0x67452301;
  52796. this._b = 0xefcdab89;
  52797. this._c = 0x98badcfe;
  52798. this._d = 0x10325476;
  52799. this._e = 0xc3d2e1f0;
  52800. return this;
  52801. };
  52802. function rotl5(num) {
  52803. return num << 5 | num >>> 27;
  52804. }
  52805. function rotl30(num) {
  52806. return num << 30 | num >>> 2;
  52807. }
  52808. function ft(s, b, c, d) {
  52809. if (s === 0) return b & c | ~b & d;
  52810. if (s === 2) return b & c | b & d | c & d;
  52811. return b ^ c ^ d;
  52812. }
  52813. Sha.prototype._update = function (M) {
  52814. var W = this._w;
  52815. var a = this._a | 0;
  52816. var b = this._b | 0;
  52817. var c = this._c | 0;
  52818. var d = this._d | 0;
  52819. var e = this._e | 0;
  52820. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4);
  52821. for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  52822. for (var j = 0; j < 80; ++j) {
  52823. var s = ~~(j / 20);
  52824. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  52825. e = d;
  52826. d = c;
  52827. c = rotl30(b);
  52828. b = a;
  52829. a = t;
  52830. }
  52831. this._a = a + this._a | 0;
  52832. this._b = b + this._b | 0;
  52833. this._c = c + this._c | 0;
  52834. this._d = d + this._d | 0;
  52835. this._e = e + this._e | 0;
  52836. };
  52837. Sha.prototype._hash = function () {
  52838. var H = Buffer.allocUnsafe(20);
  52839. H.writeInt32BE(this._a | 0, 0);
  52840. H.writeInt32BE(this._b | 0, 4);
  52841. H.writeInt32BE(this._c | 0, 8);
  52842. H.writeInt32BE(this._d | 0, 12);
  52843. H.writeInt32BE(this._e | 0, 16);
  52844. return H;
  52845. };
  52846. module.exports = Sha;
  52847. },{"./hash":497,"inherits":440,"safe-buffer":494}],500:[function(require,module,exports){
  52848. "use strict";
  52849. /*
  52850. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  52851. * in FIPS PUB 180-1
  52852. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  52853. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  52854. * Distributed under the BSD License
  52855. * See http://pajhome.org.uk/crypt/md5 for details.
  52856. */
  52857. var inherits = require('inherits');
  52858. var Hash = require('./hash');
  52859. var Buffer = require('safe-buffer').Buffer;
  52860. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  52861. var W = new Array(80);
  52862. function Sha1() {
  52863. this.init();
  52864. this._w = W;
  52865. Hash.call(this, 64, 56);
  52866. }
  52867. inherits(Sha1, Hash);
  52868. Sha1.prototype.init = function () {
  52869. this._a = 0x67452301;
  52870. this._b = 0xefcdab89;
  52871. this._c = 0x98badcfe;
  52872. this._d = 0x10325476;
  52873. this._e = 0xc3d2e1f0;
  52874. return this;
  52875. };
  52876. function rotl1(num) {
  52877. return num << 1 | num >>> 31;
  52878. }
  52879. function rotl5(num) {
  52880. return num << 5 | num >>> 27;
  52881. }
  52882. function rotl30(num) {
  52883. return num << 30 | num >>> 2;
  52884. }
  52885. function ft(s, b, c, d) {
  52886. if (s === 0) return b & c | ~b & d;
  52887. if (s === 2) return b & c | b & d | c & d;
  52888. return b ^ c ^ d;
  52889. }
  52890. Sha1.prototype._update = function (M) {
  52891. var W = this._w;
  52892. var a = this._a | 0;
  52893. var b = this._b | 0;
  52894. var c = this._c | 0;
  52895. var d = this._d | 0;
  52896. var e = this._e | 0;
  52897. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4);
  52898. for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
  52899. for (var j = 0; j < 80; ++j) {
  52900. var s = ~~(j / 20);
  52901. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  52902. e = d;
  52903. d = c;
  52904. c = rotl30(b);
  52905. b = a;
  52906. a = t;
  52907. }
  52908. this._a = a + this._a | 0;
  52909. this._b = b + this._b | 0;
  52910. this._c = c + this._c | 0;
  52911. this._d = d + this._d | 0;
  52912. this._e = e + this._e | 0;
  52913. };
  52914. Sha1.prototype._hash = function () {
  52915. var H = Buffer.allocUnsafe(20);
  52916. H.writeInt32BE(this._a | 0, 0);
  52917. H.writeInt32BE(this._b | 0, 4);
  52918. H.writeInt32BE(this._c | 0, 8);
  52919. H.writeInt32BE(this._d | 0, 12);
  52920. H.writeInt32BE(this._e | 0, 16);
  52921. return H;
  52922. };
  52923. module.exports = Sha1;
  52924. },{"./hash":497,"inherits":440,"safe-buffer":494}],501:[function(require,module,exports){
  52925. "use strict";
  52926. /**
  52927. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  52928. * in FIPS 180-2
  52929. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  52930. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  52931. *
  52932. */
  52933. var inherits = require('inherits');
  52934. var Sha256 = require('./sha256');
  52935. var Hash = require('./hash');
  52936. var Buffer = require('safe-buffer').Buffer;
  52937. var W = new Array(64);
  52938. function Sha224() {
  52939. this.init();
  52940. this._w = W; // new Array(64)
  52941. Hash.call(this, 64, 56);
  52942. }
  52943. inherits(Sha224, Sha256);
  52944. Sha224.prototype.init = function () {
  52945. this._a = 0xc1059ed8;
  52946. this._b = 0x367cd507;
  52947. this._c = 0x3070dd17;
  52948. this._d = 0xf70e5939;
  52949. this._e = 0xffc00b31;
  52950. this._f = 0x68581511;
  52951. this._g = 0x64f98fa7;
  52952. this._h = 0xbefa4fa4;
  52953. return this;
  52954. };
  52955. Sha224.prototype._hash = function () {
  52956. var H = Buffer.allocUnsafe(28);
  52957. H.writeInt32BE(this._a, 0);
  52958. H.writeInt32BE(this._b, 4);
  52959. H.writeInt32BE(this._c, 8);
  52960. H.writeInt32BE(this._d, 12);
  52961. H.writeInt32BE(this._e, 16);
  52962. H.writeInt32BE(this._f, 20);
  52963. H.writeInt32BE(this._g, 24);
  52964. return H;
  52965. };
  52966. module.exports = Sha224;
  52967. },{"./hash":497,"./sha256":502,"inherits":440,"safe-buffer":494}],502:[function(require,module,exports){
  52968. "use strict";
  52969. /**
  52970. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  52971. * in FIPS 180-2
  52972. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  52973. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  52974. *
  52975. */
  52976. var inherits = require('inherits');
  52977. var Hash = require('./hash');
  52978. var Buffer = require('safe-buffer').Buffer;
  52979. var K = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2];
  52980. var W = new Array(64);
  52981. function Sha256() {
  52982. this.init();
  52983. this._w = W; // new Array(64)
  52984. Hash.call(this, 64, 56);
  52985. }
  52986. inherits(Sha256, Hash);
  52987. Sha256.prototype.init = function () {
  52988. this._a = 0x6a09e667;
  52989. this._b = 0xbb67ae85;
  52990. this._c = 0x3c6ef372;
  52991. this._d = 0xa54ff53a;
  52992. this._e = 0x510e527f;
  52993. this._f = 0x9b05688c;
  52994. this._g = 0x1f83d9ab;
  52995. this._h = 0x5be0cd19;
  52996. return this;
  52997. };
  52998. function ch(x, y, z) {
  52999. return z ^ x & (y ^ z);
  53000. }
  53001. function maj(x, y, z) {
  53002. return x & y | z & (x | y);
  53003. }
  53004. function sigma0(x) {
  53005. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
  53006. }
  53007. function sigma1(x) {
  53008. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7);
  53009. }
  53010. function gamma0(x) {
  53011. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3;
  53012. }
  53013. function gamma1(x) {
  53014. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10;
  53015. }
  53016. Sha256.prototype._update = function (M) {
  53017. var W = this._w;
  53018. var a = this._a | 0;
  53019. var b = this._b | 0;
  53020. var c = this._c | 0;
  53021. var d = this._d | 0;
  53022. var e = this._e | 0;
  53023. var f = this._f | 0;
  53024. var g = this._g | 0;
  53025. var h = this._h | 0;
  53026. for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4);
  53027. for (; i < 64; ++i) W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0;
  53028. for (var j = 0; j < 64; ++j) {
  53029. var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0;
  53030. var T2 = sigma0(a) + maj(a, b, c) | 0;
  53031. h = g;
  53032. g = f;
  53033. f = e;
  53034. e = d + T1 | 0;
  53035. d = c;
  53036. c = b;
  53037. b = a;
  53038. a = T1 + T2 | 0;
  53039. }
  53040. this._a = a + this._a | 0;
  53041. this._b = b + this._b | 0;
  53042. this._c = c + this._c | 0;
  53043. this._d = d + this._d | 0;
  53044. this._e = e + this._e | 0;
  53045. this._f = f + this._f | 0;
  53046. this._g = g + this._g | 0;
  53047. this._h = h + this._h | 0;
  53048. };
  53049. Sha256.prototype._hash = function () {
  53050. var H = Buffer.allocUnsafe(32);
  53051. H.writeInt32BE(this._a, 0);
  53052. H.writeInt32BE(this._b, 4);
  53053. H.writeInt32BE(this._c, 8);
  53054. H.writeInt32BE(this._d, 12);
  53055. H.writeInt32BE(this._e, 16);
  53056. H.writeInt32BE(this._f, 20);
  53057. H.writeInt32BE(this._g, 24);
  53058. H.writeInt32BE(this._h, 28);
  53059. return H;
  53060. };
  53061. module.exports = Sha256;
  53062. },{"./hash":497,"inherits":440,"safe-buffer":494}],503:[function(require,module,exports){
  53063. "use strict";
  53064. var inherits = require('inherits');
  53065. var SHA512 = require('./sha512');
  53066. var Hash = require('./hash');
  53067. var Buffer = require('safe-buffer').Buffer;
  53068. var W = new Array(160);
  53069. function Sha384() {
  53070. this.init();
  53071. this._w = W;
  53072. Hash.call(this, 128, 112);
  53073. }
  53074. inherits(Sha384, SHA512);
  53075. Sha384.prototype.init = function () {
  53076. this._ah = 0xcbbb9d5d;
  53077. this._bh = 0x629a292a;
  53078. this._ch = 0x9159015a;
  53079. this._dh = 0x152fecd8;
  53080. this._eh = 0x67332667;
  53081. this._fh = 0x8eb44a87;
  53082. this._gh = 0xdb0c2e0d;
  53083. this._hh = 0x47b5481d;
  53084. this._al = 0xc1059ed8;
  53085. this._bl = 0x367cd507;
  53086. this._cl = 0x3070dd17;
  53087. this._dl = 0xf70e5939;
  53088. this._el = 0xffc00b31;
  53089. this._fl = 0x68581511;
  53090. this._gl = 0x64f98fa7;
  53091. this._hl = 0xbefa4fa4;
  53092. return this;
  53093. };
  53094. Sha384.prototype._hash = function () {
  53095. var H = Buffer.allocUnsafe(48);
  53096. function writeInt64BE(h, l, offset) {
  53097. H.writeInt32BE(h, offset);
  53098. H.writeInt32BE(l, offset + 4);
  53099. }
  53100. writeInt64BE(this._ah, this._al, 0);
  53101. writeInt64BE(this._bh, this._bl, 8);
  53102. writeInt64BE(this._ch, this._cl, 16);
  53103. writeInt64BE(this._dh, this._dl, 24);
  53104. writeInt64BE(this._eh, this._el, 32);
  53105. writeInt64BE(this._fh, this._fl, 40);
  53106. return H;
  53107. };
  53108. module.exports = Sha384;
  53109. },{"./hash":497,"./sha512":504,"inherits":440,"safe-buffer":494}],504:[function(require,module,exports){
  53110. "use strict";
  53111. var inherits = require('inherits');
  53112. var Hash = require('./hash');
  53113. var Buffer = require('safe-buffer').Buffer;
  53114. var K = [0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817];
  53115. var W = new Array(160);
  53116. function Sha512() {
  53117. this.init();
  53118. this._w = W;
  53119. Hash.call(this, 128, 112);
  53120. }
  53121. inherits(Sha512, Hash);
  53122. Sha512.prototype.init = function () {
  53123. this._ah = 0x6a09e667;
  53124. this._bh = 0xbb67ae85;
  53125. this._ch = 0x3c6ef372;
  53126. this._dh = 0xa54ff53a;
  53127. this._eh = 0x510e527f;
  53128. this._fh = 0x9b05688c;
  53129. this._gh = 0x1f83d9ab;
  53130. this._hh = 0x5be0cd19;
  53131. this._al = 0xf3bcc908;
  53132. this._bl = 0x84caa73b;
  53133. this._cl = 0xfe94f82b;
  53134. this._dl = 0x5f1d36f1;
  53135. this._el = 0xade682d1;
  53136. this._fl = 0x2b3e6c1f;
  53137. this._gl = 0xfb41bd6b;
  53138. this._hl = 0x137e2179;
  53139. return this;
  53140. };
  53141. function Ch(x, y, z) {
  53142. return z ^ x & (y ^ z);
  53143. }
  53144. function maj(x, y, z) {
  53145. return x & y | z & (x | y);
  53146. }
  53147. function sigma0(x, xl) {
  53148. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25);
  53149. }
  53150. function sigma1(x, xl) {
  53151. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23);
  53152. }
  53153. function Gamma0(x, xl) {
  53154. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7;
  53155. }
  53156. function Gamma0l(x, xl) {
  53157. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25);
  53158. }
  53159. function Gamma1(x, xl) {
  53160. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6;
  53161. }
  53162. function Gamma1l(x, xl) {
  53163. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26);
  53164. }
  53165. function getCarry(a, b) {
  53166. return a >>> 0 < b >>> 0 ? 1 : 0;
  53167. }
  53168. Sha512.prototype._update = function (M) {
  53169. var W = this._w;
  53170. var ah = this._ah | 0;
  53171. var bh = this._bh | 0;
  53172. var ch = this._ch | 0;
  53173. var dh = this._dh | 0;
  53174. var eh = this._eh | 0;
  53175. var fh = this._fh | 0;
  53176. var gh = this._gh | 0;
  53177. var hh = this._hh | 0;
  53178. var al = this._al | 0;
  53179. var bl = this._bl | 0;
  53180. var cl = this._cl | 0;
  53181. var dl = this._dl | 0;
  53182. var el = this._el | 0;
  53183. var fl = this._fl | 0;
  53184. var gl = this._gl | 0;
  53185. var hl = this._hl | 0;
  53186. for (var i = 0; i < 32; i += 2) {
  53187. W[i] = M.readInt32BE(i * 4);
  53188. W[i + 1] = M.readInt32BE(i * 4 + 4);
  53189. }
  53190. for (; i < 160; i += 2) {
  53191. var xh = W[i - 15 * 2];
  53192. var xl = W[i - 15 * 2 + 1];
  53193. var gamma0 = Gamma0(xh, xl);
  53194. var gamma0l = Gamma0l(xl, xh);
  53195. xh = W[i - 2 * 2];
  53196. xl = W[i - 2 * 2 + 1];
  53197. var gamma1 = Gamma1(xh, xl);
  53198. var gamma1l = Gamma1l(xl, xh);
  53199. // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  53200. var Wi7h = W[i - 7 * 2];
  53201. var Wi7l = W[i - 7 * 2 + 1];
  53202. var Wi16h = W[i - 16 * 2];
  53203. var Wi16l = W[i - 16 * 2 + 1];
  53204. var Wil = gamma0l + Wi7l | 0;
  53205. var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0;
  53206. Wil = Wil + gamma1l | 0;
  53207. Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0;
  53208. Wil = Wil + Wi16l | 0;
  53209. Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0;
  53210. W[i] = Wih;
  53211. W[i + 1] = Wil;
  53212. }
  53213. for (var j = 0; j < 160; j += 2) {
  53214. Wih = W[j];
  53215. Wil = W[j + 1];
  53216. var majh = maj(ah, bh, ch);
  53217. var majl = maj(al, bl, cl);
  53218. var sigma0h = sigma0(ah, al);
  53219. var sigma0l = sigma0(al, ah);
  53220. var sigma1h = sigma1(eh, el);
  53221. var sigma1l = sigma1(el, eh);
  53222. // t1 = h + sigma1 + ch + K[j] + W[j]
  53223. var Kih = K[j];
  53224. var Kil = K[j + 1];
  53225. var chh = Ch(eh, fh, gh);
  53226. var chl = Ch(el, fl, gl);
  53227. var t1l = hl + sigma1l | 0;
  53228. var t1h = hh + sigma1h + getCarry(t1l, hl) | 0;
  53229. t1l = t1l + chl | 0;
  53230. t1h = t1h + chh + getCarry(t1l, chl) | 0;
  53231. t1l = t1l + Kil | 0;
  53232. t1h = t1h + Kih + getCarry(t1l, Kil) | 0;
  53233. t1l = t1l + Wil | 0;
  53234. t1h = t1h + Wih + getCarry(t1l, Wil) | 0;
  53235. // t2 = sigma0 + maj
  53236. var t2l = sigma0l + majl | 0;
  53237. var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0;
  53238. hh = gh;
  53239. hl = gl;
  53240. gh = fh;
  53241. gl = fl;
  53242. fh = eh;
  53243. fl = el;
  53244. el = dl + t1l | 0;
  53245. eh = dh + t1h + getCarry(el, dl) | 0;
  53246. dh = ch;
  53247. dl = cl;
  53248. ch = bh;
  53249. cl = bl;
  53250. bh = ah;
  53251. bl = al;
  53252. al = t1l + t2l | 0;
  53253. ah = t1h + t2h + getCarry(al, t1l) | 0;
  53254. }
  53255. this._al = this._al + al | 0;
  53256. this._bl = this._bl + bl | 0;
  53257. this._cl = this._cl + cl | 0;
  53258. this._dl = this._dl + dl | 0;
  53259. this._el = this._el + el | 0;
  53260. this._fl = this._fl + fl | 0;
  53261. this._gl = this._gl + gl | 0;
  53262. this._hl = this._hl + hl | 0;
  53263. this._ah = this._ah + ah + getCarry(this._al, al) | 0;
  53264. this._bh = this._bh + bh + getCarry(this._bl, bl) | 0;
  53265. this._ch = this._ch + ch + getCarry(this._cl, cl) | 0;
  53266. this._dh = this._dh + dh + getCarry(this._dl, dl) | 0;
  53267. this._eh = this._eh + eh + getCarry(this._el, el) | 0;
  53268. this._fh = this._fh + fh + getCarry(this._fl, fl) | 0;
  53269. this._gh = this._gh + gh + getCarry(this._gl, gl) | 0;
  53270. this._hh = this._hh + hh + getCarry(this._hl, hl) | 0;
  53271. };
  53272. Sha512.prototype._hash = function () {
  53273. var H = Buffer.allocUnsafe(64);
  53274. function writeInt64BE(h, l, offset) {
  53275. H.writeInt32BE(h, offset);
  53276. H.writeInt32BE(l, offset + 4);
  53277. }
  53278. writeInt64BE(this._ah, this._al, 0);
  53279. writeInt64BE(this._bh, this._bl, 8);
  53280. writeInt64BE(this._ch, this._cl, 16);
  53281. writeInt64BE(this._dh, this._dl, 24);
  53282. writeInt64BE(this._eh, this._el, 32);
  53283. writeInt64BE(this._fh, this._fl, 40);
  53284. writeInt64BE(this._gh, this._gl, 48);
  53285. writeInt64BE(this._hh, this._hl, 56);
  53286. return H;
  53287. };
  53288. module.exports = Sha512;
  53289. },{"./hash":497,"inherits":440,"safe-buffer":494}],505:[function(require,module,exports){
  53290. "use strict";
  53291. // Copyright Joyent, Inc. and other Node contributors.
  53292. //
  53293. // Permission is hereby granted, free of charge, to any person obtaining a
  53294. // copy of this software and associated documentation files (the
  53295. // "Software"), to deal in the Software without restriction, including
  53296. // without limitation the rights to use, copy, modify, merge, publish,
  53297. // distribute, sublicense, and/or sell copies of the Software, and to permit
  53298. // persons to whom the Software is furnished to do so, subject to the
  53299. // following conditions:
  53300. //
  53301. // The above copyright notice and this permission notice shall be included
  53302. // in all copies or substantial portions of the Software.
  53303. //
  53304. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  53305. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  53306. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  53307. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  53308. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  53309. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  53310. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  53311. module.exports = Stream;
  53312. var EE = require('events').EventEmitter;
  53313. var inherits = require('inherits');
  53314. inherits(Stream, EE);
  53315. Stream.Readable = require('readable-stream/readable.js');
  53316. Stream.Writable = require('readable-stream/writable.js');
  53317. Stream.Duplex = require('readable-stream/duplex.js');
  53318. Stream.Transform = require('readable-stream/transform.js');
  53319. Stream.PassThrough = require('readable-stream/passthrough.js');
  53320. // Backwards-compat with node 0.4.x
  53321. Stream.Stream = Stream;
  53322. // old-style streams. Note that the pipe method (the only relevant
  53323. // part of this class) is overridden in the Readable class.
  53324. function Stream() {
  53325. EE.call(this);
  53326. }
  53327. Stream.prototype.pipe = function (dest, options) {
  53328. var source = this;
  53329. function ondata(chunk) {
  53330. if (dest.writable) {
  53331. if (false === dest.write(chunk) && source.pause) {
  53332. source.pause();
  53333. }
  53334. }
  53335. }
  53336. source.on('data', ondata);
  53337. function ondrain() {
  53338. if (source.readable && source.resume) {
  53339. source.resume();
  53340. }
  53341. }
  53342. dest.on('drain', ondrain);
  53343. // If the 'end' option is not supplied, dest.end() will be called when
  53344. // source gets the 'end' or 'close' events. Only dest.end() once.
  53345. if (!dest._isStdio && (!options || options.end !== false)) {
  53346. source.on('end', onend);
  53347. source.on('close', onclose);
  53348. }
  53349. var didOnEnd = false;
  53350. function onend() {
  53351. if (didOnEnd) return;
  53352. didOnEnd = true;
  53353. dest.end();
  53354. }
  53355. function onclose() {
  53356. if (didOnEnd) return;
  53357. didOnEnd = true;
  53358. if (typeof dest.destroy === 'function') dest.destroy();
  53359. }
  53360. // don't leave dangling pipes when there are errors.
  53361. function onerror(er) {
  53362. cleanup();
  53363. if (EE.listenerCount(this, 'error') === 0) {
  53364. throw er; // Unhandled stream error in pipe.
  53365. }
  53366. }
  53367. source.on('error', onerror);
  53368. dest.on('error', onerror);
  53369. // remove all the event listeners that were added.
  53370. function cleanup() {
  53371. source.removeListener('data', ondata);
  53372. dest.removeListener('drain', ondrain);
  53373. source.removeListener('end', onend);
  53374. source.removeListener('close', onclose);
  53375. source.removeListener('error', onerror);
  53376. dest.removeListener('error', onerror);
  53377. source.removeListener('end', cleanup);
  53378. source.removeListener('close', cleanup);
  53379. dest.removeListener('close', cleanup);
  53380. }
  53381. source.on('end', cleanup);
  53382. source.on('close', cleanup);
  53383. dest.on('close', cleanup);
  53384. dest.emit('pipe', source);
  53385. // Allow for unix-like usage: A.pipe(B).pipe(C)
  53386. return dest;
  53387. };
  53388. },{"events":422,"inherits":440,"readable-stream/duplex.js":507,"readable-stream/passthrough.js":516,"readable-stream/readable.js":517,"readable-stream/transform.js":518,"readable-stream/writable.js":519}],506:[function(require,module,exports){
  53389. "use strict";
  53390. var toString = {}.toString;
  53391. module.exports = Array.isArray || function (arr) {
  53392. return toString.call(arr) == '[object Array]';
  53393. };
  53394. },{}],507:[function(require,module,exports){
  53395. "use strict";
  53396. module.exports = require('./lib/_stream_duplex.js');
  53397. },{"./lib/_stream_duplex.js":508}],508:[function(require,module,exports){
  53398. // Copyright Joyent, Inc. and other Node contributors.
  53399. //
  53400. // Permission is hereby granted, free of charge, to any person obtaining a
  53401. // copy of this software and associated documentation files (the
  53402. // "Software"), to deal in the Software without restriction, including
  53403. // without limitation the rights to use, copy, modify, merge, publish,
  53404. // distribute, sublicense, and/or sell copies of the Software, and to permit
  53405. // persons to whom the Software is furnished to do so, subject to the
  53406. // following conditions:
  53407. //
  53408. // The above copyright notice and this permission notice shall be included
  53409. // in all copies or substantial portions of the Software.
  53410. //
  53411. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  53412. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  53413. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  53414. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  53415. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  53416. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  53417. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  53418. // a duplex stream is just a stream that is both readable and writable.
  53419. // Since JS doesn't have multiple prototypal inheritance, this class
  53420. // prototypally inherits from Readable, and then parasitically from
  53421. // Writable.
  53422. 'use strict';
  53423. /*<replacement>*/
  53424. var pna = require('process-nextick-args');
  53425. /*</replacement>*/
  53426. /*<replacement>*/
  53427. var objectKeys = Object.keys || function (obj) {
  53428. var keys = [];
  53429. for (var key in obj) {
  53430. keys.push(key);
  53431. }
  53432. return keys;
  53433. };
  53434. /*</replacement>*/
  53435. module.exports = Duplex;
  53436. /*<replacement>*/
  53437. var util = Object.create(require('core-util-is'));
  53438. util.inherits = require('inherits');
  53439. /*</replacement>*/
  53440. var Readable = require('./_stream_readable');
  53441. var Writable = require('./_stream_writable');
  53442. util.inherits(Duplex, Readable);
  53443. {
  53444. // avoid scope creep, the keys array can then be collected
  53445. var keys = objectKeys(Writable.prototype);
  53446. for (var v = 0; v < keys.length; v++) {
  53447. var method = keys[v];
  53448. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  53449. }
  53450. }
  53451. function Duplex(options) {
  53452. if (!(this instanceof Duplex)) return new Duplex(options);
  53453. Readable.call(this, options);
  53454. Writable.call(this, options);
  53455. if (options && options.readable === false) this.readable = false;
  53456. if (options && options.writable === false) this.writable = false;
  53457. this.allowHalfOpen = true;
  53458. if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
  53459. this.once('end', onend);
  53460. }
  53461. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  53462. // making it explicit this property is not enumerable
  53463. // because otherwise some prototype manipulation in
  53464. // userland will fail
  53465. enumerable: false,
  53466. get: function () {
  53467. return this._writableState.highWaterMark;
  53468. }
  53469. });
  53470. // the no-half-open enforcer
  53471. function onend() {
  53472. // if we allow half-open state, or if the writable side ended,
  53473. // then we're ok.
  53474. if (this.allowHalfOpen || this._writableState.ended) return;
  53475. // no more data can be written.
  53476. // But allow more writes to happen in this tick.
  53477. pna.nextTick(onEndNT, this);
  53478. }
  53479. function onEndNT(self) {
  53480. self.end();
  53481. }
  53482. Object.defineProperty(Duplex.prototype, 'destroyed', {
  53483. get: function () {
  53484. if (this._readableState === undefined || this._writableState === undefined) {
  53485. return false;
  53486. }
  53487. return this._readableState.destroyed && this._writableState.destroyed;
  53488. },
  53489. set: function (value) {
  53490. // we ignore the value if the stream
  53491. // has not been initialized yet
  53492. if (this._readableState === undefined || this._writableState === undefined) {
  53493. return;
  53494. }
  53495. // backward compatibility, the user is explicitly
  53496. // managing destroyed
  53497. this._readableState.destroyed = value;
  53498. this._writableState.destroyed = value;
  53499. }
  53500. });
  53501. Duplex.prototype._destroy = function (err, cb) {
  53502. this.push(null);
  53503. this.end();
  53504. pna.nextTick(cb, err);
  53505. };
  53506. },{"./_stream_readable":510,"./_stream_writable":512,"core-util-is":383,"inherits":440,"process-nextick-args":466}],509:[function(require,module,exports){
  53507. // Copyright Joyent, Inc. and other Node contributors.
  53508. //
  53509. // Permission is hereby granted, free of charge, to any person obtaining a
  53510. // copy of this software and associated documentation files (the
  53511. // "Software"), to deal in the Software without restriction, including
  53512. // without limitation the rights to use, copy, modify, merge, publish,
  53513. // distribute, sublicense, and/or sell copies of the Software, and to permit
  53514. // persons to whom the Software is furnished to do so, subject to the
  53515. // following conditions:
  53516. //
  53517. // The above copyright notice and this permission notice shall be included
  53518. // in all copies or substantial portions of the Software.
  53519. //
  53520. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  53521. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  53522. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  53523. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  53524. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  53525. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  53526. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  53527. // a passthrough stream.
  53528. // basically just the most minimal sort of Transform stream.
  53529. // Every written chunk gets output as-is.
  53530. 'use strict';
  53531. module.exports = PassThrough;
  53532. var Transform = require('./_stream_transform');
  53533. /*<replacement>*/
  53534. var util = Object.create(require('core-util-is'));
  53535. util.inherits = require('inherits');
  53536. /*</replacement>*/
  53537. util.inherits(PassThrough, Transform);
  53538. function PassThrough(options) {
  53539. if (!(this instanceof PassThrough)) return new PassThrough(options);
  53540. Transform.call(this, options);
  53541. }
  53542. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  53543. cb(null, chunk);
  53544. };
  53545. },{"./_stream_transform":511,"core-util-is":383,"inherits":440}],510:[function(require,module,exports){
  53546. (function (process,global){(function (){
  53547. // Copyright Joyent, Inc. and other Node contributors.
  53548. //
  53549. // Permission is hereby granted, free of charge, to any person obtaining a
  53550. // copy of this software and associated documentation files (the
  53551. // "Software"), to deal in the Software without restriction, including
  53552. // without limitation the rights to use, copy, modify, merge, publish,
  53553. // distribute, sublicense, and/or sell copies of the Software, and to permit
  53554. // persons to whom the Software is furnished to do so, subject to the
  53555. // following conditions:
  53556. //
  53557. // The above copyright notice and this permission notice shall be included
  53558. // in all copies or substantial portions of the Software.
  53559. //
  53560. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  53561. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  53562. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  53563. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  53564. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  53565. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  53566. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  53567. 'use strict';
  53568. /*<replacement>*/
  53569. var pna = require('process-nextick-args');
  53570. /*</replacement>*/
  53571. module.exports = Readable;
  53572. /*<replacement>*/
  53573. var isArray = require('isarray');
  53574. /*</replacement>*/
  53575. /*<replacement>*/
  53576. var Duplex;
  53577. /*</replacement>*/
  53578. Readable.ReadableState = ReadableState;
  53579. /*<replacement>*/
  53580. var EE = require('events').EventEmitter;
  53581. var EElistenerCount = function (emitter, type) {
  53582. return emitter.listeners(type).length;
  53583. };
  53584. /*</replacement>*/
  53585. /*<replacement>*/
  53586. var Stream = require('./internal/streams/stream');
  53587. /*</replacement>*/
  53588. /*<replacement>*/
  53589. var Buffer = require('safe-buffer').Buffer;
  53590. var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
  53591. function _uint8ArrayToBuffer(chunk) {
  53592. return Buffer.from(chunk);
  53593. }
  53594. function _isUint8Array(obj) {
  53595. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  53596. }
  53597. /*</replacement>*/
  53598. /*<replacement>*/
  53599. var util = Object.create(require('core-util-is'));
  53600. util.inherits = require('inherits');
  53601. /*</replacement>*/
  53602. /*<replacement>*/
  53603. var debugUtil = require('util');
  53604. var debug = void 0;
  53605. if (debugUtil && debugUtil.debuglog) {
  53606. debug = debugUtil.debuglog('stream');
  53607. } else {
  53608. debug = function () {};
  53609. }
  53610. /*</replacement>*/
  53611. var BufferList = require('./internal/streams/BufferList');
  53612. var destroyImpl = require('./internal/streams/destroy');
  53613. var StringDecoder;
  53614. util.inherits(Readable, Stream);
  53615. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  53616. function prependListener(emitter, event, fn) {
  53617. // Sadly this is not cacheable as some libraries bundle their own
  53618. // event emitter implementation with them.
  53619. if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
  53620. // This is a hack to make sure that our error handler is attached before any
  53621. // userland ones. NEVER DO THIS. This is here only because this code needs
  53622. // to continue to work with older versions of Node.js that do not include
  53623. // the prependListener() method. The goal is to eventually remove this hack.
  53624. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  53625. }
  53626. function ReadableState(options, stream) {
  53627. Duplex = Duplex || require('./_stream_duplex');
  53628. options = options || {};
  53629. // Duplex streams are both readable and writable, but share
  53630. // the same options object.
  53631. // However, some cases require setting options to different
  53632. // values for the readable and the writable sides of the duplex stream.
  53633. // These options can be provided separately as readableXXX and writableXXX.
  53634. var isDuplex = stream instanceof Duplex;
  53635. // object stream flag. Used to make read(n) ignore n and to
  53636. // make all the buffer merging and length checks go away
  53637. this.objectMode = !!options.objectMode;
  53638. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
  53639. // the point at which it stops calling _read() to fill the buffer
  53640. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  53641. var hwm = options.highWaterMark;
  53642. var readableHwm = options.readableHighWaterMark;
  53643. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  53644. if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
  53645. // cast to ints.
  53646. this.highWaterMark = Math.floor(this.highWaterMark);
  53647. // A linked list is used to store data chunks instead of an array because the
  53648. // linked list can remove elements from the beginning faster than
  53649. // array.shift()
  53650. this.buffer = new BufferList();
  53651. this.length = 0;
  53652. this.pipes = null;
  53653. this.pipesCount = 0;
  53654. this.flowing = null;
  53655. this.ended = false;
  53656. this.endEmitted = false;
  53657. this.reading = false;
  53658. // a flag to be able to tell if the event 'readable'/'data' is emitted
  53659. // immediately, or on a later tick. We set this to true at first, because
  53660. // any actions that shouldn't happen until "later" should generally also
  53661. // not happen before the first read call.
  53662. this.sync = true;
  53663. // whenever we return null, then we set a flag to say
  53664. // that we're awaiting a 'readable' event emission.
  53665. this.needReadable = false;
  53666. this.emittedReadable = false;
  53667. this.readableListening = false;
  53668. this.resumeScheduled = false;
  53669. // has it been destroyed
  53670. this.destroyed = false;
  53671. // Crypto is kind of old and crusty. Historically, its default string
  53672. // encoding is 'binary' so we have to make this configurable.
  53673. // Everything else in the universe uses 'utf8', though.
  53674. this.defaultEncoding = options.defaultEncoding || 'utf8';
  53675. // the number of writers that are awaiting a drain event in .pipe()s
  53676. this.awaitDrain = 0;
  53677. // if true, a maybeReadMore has been scheduled
  53678. this.readingMore = false;
  53679. this.decoder = null;
  53680. this.encoding = null;
  53681. if (options.encoding) {
  53682. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  53683. this.decoder = new StringDecoder(options.encoding);
  53684. this.encoding = options.encoding;
  53685. }
  53686. }
  53687. function Readable(options) {
  53688. Duplex = Duplex || require('./_stream_duplex');
  53689. if (!(this instanceof Readable)) return new Readable(options);
  53690. this._readableState = new ReadableState(options, this);
  53691. // legacy
  53692. this.readable = true;
  53693. if (options) {
  53694. if (typeof options.read === 'function') this._read = options.read;
  53695. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  53696. }
  53697. Stream.call(this);
  53698. }
  53699. Object.defineProperty(Readable.prototype, 'destroyed', {
  53700. get: function () {
  53701. if (this._readableState === undefined) {
  53702. return false;
  53703. }
  53704. return this._readableState.destroyed;
  53705. },
  53706. set: function (value) {
  53707. // we ignore the value if the stream
  53708. // has not been initialized yet
  53709. if (!this._readableState) {
  53710. return;
  53711. }
  53712. // backward compatibility, the user is explicitly
  53713. // managing destroyed
  53714. this._readableState.destroyed = value;
  53715. }
  53716. });
  53717. Readable.prototype.destroy = destroyImpl.destroy;
  53718. Readable.prototype._undestroy = destroyImpl.undestroy;
  53719. Readable.prototype._destroy = function (err, cb) {
  53720. this.push(null);
  53721. cb(err);
  53722. };
  53723. // Manually shove something into the read() buffer.
  53724. // This returns true if the highWaterMark has not been hit yet,
  53725. // similar to how Writable.write() returns true if you should
  53726. // write() some more.
  53727. Readable.prototype.push = function (chunk, encoding) {
  53728. var state = this._readableState;
  53729. var skipChunkCheck;
  53730. if (!state.objectMode) {
  53731. if (typeof chunk === 'string') {
  53732. encoding = encoding || state.defaultEncoding;
  53733. if (encoding !== state.encoding) {
  53734. chunk = Buffer.from(chunk, encoding);
  53735. encoding = '';
  53736. }
  53737. skipChunkCheck = true;
  53738. }
  53739. } else {
  53740. skipChunkCheck = true;
  53741. }
  53742. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  53743. };
  53744. // Unshift should *always* be something directly out of read()
  53745. Readable.prototype.unshift = function (chunk) {
  53746. return readableAddChunk(this, chunk, null, true, false);
  53747. };
  53748. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  53749. var state = stream._readableState;
  53750. if (chunk === null) {
  53751. state.reading = false;
  53752. onEofChunk(stream, state);
  53753. } else {
  53754. var er;
  53755. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  53756. if (er) {
  53757. stream.emit('error', er);
  53758. } else if (state.objectMode || chunk && chunk.length > 0) {
  53759. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  53760. chunk = _uint8ArrayToBuffer(chunk);
  53761. }
  53762. if (addToFront) {
  53763. if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
  53764. } else if (state.ended) {
  53765. stream.emit('error', new Error('stream.push() after EOF'));
  53766. } else {
  53767. state.reading = false;
  53768. if (state.decoder && !encoding) {
  53769. chunk = state.decoder.write(chunk);
  53770. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  53771. } else {
  53772. addChunk(stream, state, chunk, false);
  53773. }
  53774. }
  53775. } else if (!addToFront) {
  53776. state.reading = false;
  53777. }
  53778. }
  53779. return needMoreData(state);
  53780. }
  53781. function addChunk(stream, state, chunk, addToFront) {
  53782. if (state.flowing && state.length === 0 && !state.sync) {
  53783. stream.emit('data', chunk);
  53784. stream.read(0);
  53785. } else {
  53786. // update the buffer info.
  53787. state.length += state.objectMode ? 1 : chunk.length;
  53788. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  53789. if (state.needReadable) emitReadable(stream);
  53790. }
  53791. maybeReadMore(stream, state);
  53792. }
  53793. function chunkInvalid(state, chunk) {
  53794. var er;
  53795. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  53796. er = new TypeError('Invalid non-string/buffer chunk');
  53797. }
  53798. return er;
  53799. }
  53800. // if it's past the high water mark, we can push in some more.
  53801. // Also, if we have no data yet, we can stand some
  53802. // more bytes. This is to work around cases where hwm=0,
  53803. // such as the repl. Also, if the push() triggered a
  53804. // readable event, and the user called read(largeNumber) such that
  53805. // needReadable was set, then we ought to push more, so that another
  53806. // 'readable' event will be triggered.
  53807. function needMoreData(state) {
  53808. return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
  53809. }
  53810. Readable.prototype.isPaused = function () {
  53811. return this._readableState.flowing === false;
  53812. };
  53813. // backwards compatibility.
  53814. Readable.prototype.setEncoding = function (enc) {
  53815. if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
  53816. this._readableState.decoder = new StringDecoder(enc);
  53817. this._readableState.encoding = enc;
  53818. return this;
  53819. };
  53820. // Don't raise the hwm > 8MB
  53821. var MAX_HWM = 0x800000;
  53822. function computeNewHighWaterMark(n) {
  53823. if (n >= MAX_HWM) {
  53824. n = MAX_HWM;
  53825. } else {
  53826. // Get the next highest power of 2 to prevent increasing hwm excessively in
  53827. // tiny amounts
  53828. n--;
  53829. n |= n >>> 1;
  53830. n |= n >>> 2;
  53831. n |= n >>> 4;
  53832. n |= n >>> 8;
  53833. n |= n >>> 16;
  53834. n++;
  53835. }
  53836. return n;
  53837. }
  53838. // This function is designed to be inlinable, so please take care when making
  53839. // changes to the function body.
  53840. function howMuchToRead(n, state) {
  53841. if (n <= 0 || state.length === 0 && state.ended) return 0;
  53842. if (state.objectMode) return 1;
  53843. if (n !== n) {
  53844. // Only flow one buffer at a time
  53845. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  53846. }
  53847. // If we're asking for more than the current hwm, then raise the hwm.
  53848. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  53849. if (n <= state.length) return n;
  53850. // Don't have enough
  53851. if (!state.ended) {
  53852. state.needReadable = true;
  53853. return 0;
  53854. }
  53855. return state.length;
  53856. }
  53857. // you can override either this method, or the async _read(n) below.
  53858. Readable.prototype.read = function (n) {
  53859. debug('read', n);
  53860. n = parseInt(n, 10);
  53861. var state = this._readableState;
  53862. var nOrig = n;
  53863. if (n !== 0) state.emittedReadable = false;
  53864. // if we're doing read(0) to trigger a readable event, but we
  53865. // already have a bunch of data in the buffer, then just trigger
  53866. // the 'readable' event and move on.
  53867. if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
  53868. debug('read: emitReadable', state.length, state.ended);
  53869. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  53870. return null;
  53871. }
  53872. n = howMuchToRead(n, state);
  53873. // if we've ended, and we're now clear, then finish it up.
  53874. if (n === 0 && state.ended) {
  53875. if (state.length === 0) endReadable(this);
  53876. return null;
  53877. }
  53878. // All the actual chunk generation logic needs to be
  53879. // *below* the call to _read. The reason is that in certain
  53880. // synthetic stream cases, such as passthrough streams, _read
  53881. // may be a completely synchronous operation which may change
  53882. // the state of the read buffer, providing enough data when
  53883. // before there was *not* enough.
  53884. //
  53885. // So, the steps are:
  53886. // 1. Figure out what the state of things will be after we do
  53887. // a read from the buffer.
  53888. //
  53889. // 2. If that resulting state will trigger a _read, then call _read.
  53890. // Note that this may be asynchronous, or synchronous. Yes, it is
  53891. // deeply ugly to write APIs this way, but that still doesn't mean
  53892. // that the Readable class should behave improperly, as streams are
  53893. // designed to be sync/async agnostic.
  53894. // Take note if the _read call is sync or async (ie, if the read call
  53895. // has returned yet), so that we know whether or not it's safe to emit
  53896. // 'readable' etc.
  53897. //
  53898. // 3. Actually pull the requested chunks out of the buffer and return.
  53899. // if we need a readable event, then we need to do some reading.
  53900. var doRead = state.needReadable;
  53901. debug('need readable', doRead);
  53902. // if we currently have less than the highWaterMark, then also read some
  53903. if (state.length === 0 || state.length - n < state.highWaterMark) {
  53904. doRead = true;
  53905. debug('length less than watermark', doRead);
  53906. }
  53907. // however, if we've ended, then there's no point, and if we're already
  53908. // reading, then it's unnecessary.
  53909. if (state.ended || state.reading) {
  53910. doRead = false;
  53911. debug('reading or ended', doRead);
  53912. } else if (doRead) {
  53913. debug('do read');
  53914. state.reading = true;
  53915. state.sync = true;
  53916. // if the length is currently zero, then we *need* a readable event.
  53917. if (state.length === 0) state.needReadable = true;
  53918. // call internal read method
  53919. this._read(state.highWaterMark);
  53920. state.sync = false;
  53921. // If _read pushed data synchronously, then `reading` will be false,
  53922. // and we need to re-evaluate how much data we can return to the user.
  53923. if (!state.reading) n = howMuchToRead(nOrig, state);
  53924. }
  53925. var ret;
  53926. if (n > 0) ret = fromList(n, state);else ret = null;
  53927. if (ret === null) {
  53928. state.needReadable = true;
  53929. n = 0;
  53930. } else {
  53931. state.length -= n;
  53932. }
  53933. if (state.length === 0) {
  53934. // If we have nothing in the buffer, then we want to know
  53935. // as soon as we *do* get something into the buffer.
  53936. if (!state.ended) state.needReadable = true;
  53937. // If we tried to read() past the EOF, then emit end on the next tick.
  53938. if (nOrig !== n && state.ended) endReadable(this);
  53939. }
  53940. if (ret !== null) this.emit('data', ret);
  53941. return ret;
  53942. };
  53943. function onEofChunk(stream, state) {
  53944. if (state.ended) return;
  53945. if (state.decoder) {
  53946. var chunk = state.decoder.end();
  53947. if (chunk && chunk.length) {
  53948. state.buffer.push(chunk);
  53949. state.length += state.objectMode ? 1 : chunk.length;
  53950. }
  53951. }
  53952. state.ended = true;
  53953. // emit 'readable' now to make sure it gets picked up.
  53954. emitReadable(stream);
  53955. }
  53956. // Don't emit readable right away in sync mode, because this can trigger
  53957. // another read() call => stack overflow. This way, it might trigger
  53958. // a nextTick recursion warning, but that's not so bad.
  53959. function emitReadable(stream) {
  53960. var state = stream._readableState;
  53961. state.needReadable = false;
  53962. if (!state.emittedReadable) {
  53963. debug('emitReadable', state.flowing);
  53964. state.emittedReadable = true;
  53965. if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
  53966. }
  53967. }
  53968. function emitReadable_(stream) {
  53969. debug('emit readable');
  53970. stream.emit('readable');
  53971. flow(stream);
  53972. }
  53973. // at this point, the user has presumably seen the 'readable' event,
  53974. // and called read() to consume some data. that may have triggered
  53975. // in turn another _read(n) call, in which case reading = true if
  53976. // it's in progress.
  53977. // However, if we're not ended, or reading, and the length < hwm,
  53978. // then go ahead and try to read some more preemptively.
  53979. function maybeReadMore(stream, state) {
  53980. if (!state.readingMore) {
  53981. state.readingMore = true;
  53982. pna.nextTick(maybeReadMore_, stream, state);
  53983. }
  53984. }
  53985. function maybeReadMore_(stream, state) {
  53986. var len = state.length;
  53987. while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
  53988. debug('maybeReadMore read 0');
  53989. stream.read(0);
  53990. if (len === state.length)
  53991. // didn't get any data, stop spinning.
  53992. break;else len = state.length;
  53993. }
  53994. state.readingMore = false;
  53995. }
  53996. // abstract method. to be overridden in specific implementation classes.
  53997. // call cb(er, data) where data is <= n in length.
  53998. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  53999. // arbitrary, and perhaps not very meaningful.
  54000. Readable.prototype._read = function (n) {
  54001. this.emit('error', new Error('_read() is not implemented'));
  54002. };
  54003. Readable.prototype.pipe = function (dest, pipeOpts) {
  54004. var src = this;
  54005. var state = this._readableState;
  54006. switch (state.pipesCount) {
  54007. case 0:
  54008. state.pipes = dest;
  54009. break;
  54010. case 1:
  54011. state.pipes = [state.pipes, dest];
  54012. break;
  54013. default:
  54014. state.pipes.push(dest);
  54015. break;
  54016. }
  54017. state.pipesCount += 1;
  54018. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  54019. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
  54020. var endFn = doEnd ? onend : unpipe;
  54021. if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
  54022. dest.on('unpipe', onunpipe);
  54023. function onunpipe(readable, unpipeInfo) {
  54024. debug('onunpipe');
  54025. if (readable === src) {
  54026. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  54027. unpipeInfo.hasUnpiped = true;
  54028. cleanup();
  54029. }
  54030. }
  54031. }
  54032. function onend() {
  54033. debug('onend');
  54034. dest.end();
  54035. }
  54036. // when the dest drains, it reduces the awaitDrain counter
  54037. // on the source. This would be more elegant with a .once()
  54038. // handler in flow(), but adding and removing repeatedly is
  54039. // too slow.
  54040. var ondrain = pipeOnDrain(src);
  54041. dest.on('drain', ondrain);
  54042. var cleanedUp = false;
  54043. function cleanup() {
  54044. debug('cleanup');
  54045. // cleanup event handlers once the pipe is broken
  54046. dest.removeListener('close', onclose);
  54047. dest.removeListener('finish', onfinish);
  54048. dest.removeListener('drain', ondrain);
  54049. dest.removeListener('error', onerror);
  54050. dest.removeListener('unpipe', onunpipe);
  54051. src.removeListener('end', onend);
  54052. src.removeListener('end', unpipe);
  54053. src.removeListener('data', ondata);
  54054. cleanedUp = true;
  54055. // if the reader is waiting for a drain event from this
  54056. // specific writer, then it would cause it to never start
  54057. // flowing again.
  54058. // So, if this is awaiting a drain, then we just call it now.
  54059. // If we don't know, then assume that we are waiting for one.
  54060. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  54061. }
  54062. // If the user pushes more data while we're writing to dest then we'll end up
  54063. // in ondata again. However, we only want to increase awaitDrain once because
  54064. // dest will only emit one 'drain' event for the multiple writes.
  54065. // => Introduce a guard on increasing awaitDrain.
  54066. var increasedAwaitDrain = false;
  54067. src.on('data', ondata);
  54068. function ondata(chunk) {
  54069. debug('ondata');
  54070. increasedAwaitDrain = false;
  54071. var ret = dest.write(chunk);
  54072. if (false === ret && !increasedAwaitDrain) {
  54073. // If the user unpiped during `dest.write()`, it is possible
  54074. // to get stuck in a permanently paused state if that write
  54075. // also returned false.
  54076. // => Check whether `dest` is still a piping destination.
  54077. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  54078. debug('false write response, pause', state.awaitDrain);
  54079. state.awaitDrain++;
  54080. increasedAwaitDrain = true;
  54081. }
  54082. src.pause();
  54083. }
  54084. }
  54085. // if the dest has an error, then stop piping into it.
  54086. // however, don't suppress the throwing behavior for this.
  54087. function onerror(er) {
  54088. debug('onerror', er);
  54089. unpipe();
  54090. dest.removeListener('error', onerror);
  54091. if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
  54092. }
  54093. // Make sure our error handler is attached before userland ones.
  54094. prependListener(dest, 'error', onerror);
  54095. // Both close and finish should trigger unpipe, but only once.
  54096. function onclose() {
  54097. dest.removeListener('finish', onfinish);
  54098. unpipe();
  54099. }
  54100. dest.once('close', onclose);
  54101. function onfinish() {
  54102. debug('onfinish');
  54103. dest.removeListener('close', onclose);
  54104. unpipe();
  54105. }
  54106. dest.once('finish', onfinish);
  54107. function unpipe() {
  54108. debug('unpipe');
  54109. src.unpipe(dest);
  54110. }
  54111. // tell the dest that it's being piped to
  54112. dest.emit('pipe', src);
  54113. // start the flow if it hasn't been started already.
  54114. if (!state.flowing) {
  54115. debug('pipe resume');
  54116. src.resume();
  54117. }
  54118. return dest;
  54119. };
  54120. function pipeOnDrain(src) {
  54121. return function () {
  54122. var state = src._readableState;
  54123. debug('pipeOnDrain', state.awaitDrain);
  54124. if (state.awaitDrain) state.awaitDrain--;
  54125. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  54126. state.flowing = true;
  54127. flow(src);
  54128. }
  54129. };
  54130. }
  54131. Readable.prototype.unpipe = function (dest) {
  54132. var state = this._readableState;
  54133. var unpipeInfo = {
  54134. hasUnpiped: false
  54135. };
  54136. // if we're not piping anywhere, then do nothing.
  54137. if (state.pipesCount === 0) return this;
  54138. // just one destination. most common case.
  54139. if (state.pipesCount === 1) {
  54140. // passed in one, but it's not the right one.
  54141. if (dest && dest !== state.pipes) return this;
  54142. if (!dest) dest = state.pipes;
  54143. // got a match.
  54144. state.pipes = null;
  54145. state.pipesCount = 0;
  54146. state.flowing = false;
  54147. if (dest) dest.emit('unpipe', this, unpipeInfo);
  54148. return this;
  54149. }
  54150. // slow case. multiple pipe destinations.
  54151. if (!dest) {
  54152. // remove all.
  54153. var dests = state.pipes;
  54154. var len = state.pipesCount;
  54155. state.pipes = null;
  54156. state.pipesCount = 0;
  54157. state.flowing = false;
  54158. for (var i = 0; i < len; i++) {
  54159. dests[i].emit('unpipe', this, {
  54160. hasUnpiped: false
  54161. });
  54162. }
  54163. return this;
  54164. }
  54165. // try to find the right one.
  54166. var index = indexOf(state.pipes, dest);
  54167. if (index === -1) return this;
  54168. state.pipes.splice(index, 1);
  54169. state.pipesCount -= 1;
  54170. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  54171. dest.emit('unpipe', this, unpipeInfo);
  54172. return this;
  54173. };
  54174. // set up data events if they are asked for
  54175. // Ensure readable listeners eventually get something
  54176. Readable.prototype.on = function (ev, fn) {
  54177. var res = Stream.prototype.on.call(this, ev, fn);
  54178. if (ev === 'data') {
  54179. // Start flowing on next tick if stream isn't explicitly paused
  54180. if (this._readableState.flowing !== false) this.resume();
  54181. } else if (ev === 'readable') {
  54182. var state = this._readableState;
  54183. if (!state.endEmitted && !state.readableListening) {
  54184. state.readableListening = state.needReadable = true;
  54185. state.emittedReadable = false;
  54186. if (!state.reading) {
  54187. pna.nextTick(nReadingNextTick, this);
  54188. } else if (state.length) {
  54189. emitReadable(this);
  54190. }
  54191. }
  54192. }
  54193. return res;
  54194. };
  54195. Readable.prototype.addListener = Readable.prototype.on;
  54196. function nReadingNextTick(self) {
  54197. debug('readable nexttick read 0');
  54198. self.read(0);
  54199. }
  54200. // pause() and resume() are remnants of the legacy readable stream API
  54201. // If the user uses them, then switch into old mode.
  54202. Readable.prototype.resume = function () {
  54203. var state = this._readableState;
  54204. if (!state.flowing) {
  54205. debug('resume');
  54206. state.flowing = true;
  54207. resume(this, state);
  54208. }
  54209. return this;
  54210. };
  54211. function resume(stream, state) {
  54212. if (!state.resumeScheduled) {
  54213. state.resumeScheduled = true;
  54214. pna.nextTick(resume_, stream, state);
  54215. }
  54216. }
  54217. function resume_(stream, state) {
  54218. if (!state.reading) {
  54219. debug('resume read 0');
  54220. stream.read(0);
  54221. }
  54222. state.resumeScheduled = false;
  54223. state.awaitDrain = 0;
  54224. stream.emit('resume');
  54225. flow(stream);
  54226. if (state.flowing && !state.reading) stream.read(0);
  54227. }
  54228. Readable.prototype.pause = function () {
  54229. debug('call pause flowing=%j', this._readableState.flowing);
  54230. if (false !== this._readableState.flowing) {
  54231. debug('pause');
  54232. this._readableState.flowing = false;
  54233. this.emit('pause');
  54234. }
  54235. return this;
  54236. };
  54237. function flow(stream) {
  54238. var state = stream._readableState;
  54239. debug('flow', state.flowing);
  54240. while (state.flowing && stream.read() !== null) {}
  54241. }
  54242. // wrap an old-style stream as the async data source.
  54243. // This is *not* part of the readable stream interface.
  54244. // It is an ugly unfortunate mess of history.
  54245. Readable.prototype.wrap = function (stream) {
  54246. var _this = this;
  54247. var state = this._readableState;
  54248. var paused = false;
  54249. stream.on('end', function () {
  54250. debug('wrapped end');
  54251. if (state.decoder && !state.ended) {
  54252. var chunk = state.decoder.end();
  54253. if (chunk && chunk.length) _this.push(chunk);
  54254. }
  54255. _this.push(null);
  54256. });
  54257. stream.on('data', function (chunk) {
  54258. debug('wrapped data');
  54259. if (state.decoder) chunk = state.decoder.write(chunk);
  54260. // don't skip over falsy values in objectMode
  54261. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  54262. var ret = _this.push(chunk);
  54263. if (!ret) {
  54264. paused = true;
  54265. stream.pause();
  54266. }
  54267. });
  54268. // proxy all the other methods.
  54269. // important when wrapping filters and duplexes.
  54270. for (var i in stream) {
  54271. if (this[i] === undefined && typeof stream[i] === 'function') {
  54272. this[i] = function (method) {
  54273. return function () {
  54274. return stream[method].apply(stream, arguments);
  54275. };
  54276. }(i);
  54277. }
  54278. }
  54279. // proxy certain important events.
  54280. for (var n = 0; n < kProxyEvents.length; n++) {
  54281. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  54282. }
  54283. // when we try to consume some more bytes, simply unpause the
  54284. // underlying stream.
  54285. this._read = function (n) {
  54286. debug('wrapped _read', n);
  54287. if (paused) {
  54288. paused = false;
  54289. stream.resume();
  54290. }
  54291. };
  54292. return this;
  54293. };
  54294. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  54295. // making it explicit this property is not enumerable
  54296. // because otherwise some prototype manipulation in
  54297. // userland will fail
  54298. enumerable: false,
  54299. get: function () {
  54300. return this._readableState.highWaterMark;
  54301. }
  54302. });
  54303. // exposed for testing purposes only.
  54304. Readable._fromList = fromList;
  54305. // Pluck off n bytes from an array of buffers.
  54306. // Length is the combined lengths of all the buffers in the list.
  54307. // This function is designed to be inlinable, so please take care when making
  54308. // changes to the function body.
  54309. function fromList(n, state) {
  54310. // nothing buffered
  54311. if (state.length === 0) return null;
  54312. var ret;
  54313. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  54314. // read it all, truncate the list
  54315. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
  54316. state.buffer.clear();
  54317. } else {
  54318. // read part of list
  54319. ret = fromListPartial(n, state.buffer, state.decoder);
  54320. }
  54321. return ret;
  54322. }
  54323. // Extracts only enough buffered data to satisfy the amount requested.
  54324. // This function is designed to be inlinable, so please take care when making
  54325. // changes to the function body.
  54326. function fromListPartial(n, list, hasStrings) {
  54327. var ret;
  54328. if (n < list.head.data.length) {
  54329. // slice is the same for buffers and strings
  54330. ret = list.head.data.slice(0, n);
  54331. list.head.data = list.head.data.slice(n);
  54332. } else if (n === list.head.data.length) {
  54333. // first chunk is a perfect match
  54334. ret = list.shift();
  54335. } else {
  54336. // result spans more than one buffer
  54337. ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
  54338. }
  54339. return ret;
  54340. }
  54341. // Copies a specified amount of characters from the list of buffered data
  54342. // chunks.
  54343. // This function is designed to be inlinable, so please take care when making
  54344. // changes to the function body.
  54345. function copyFromBufferString(n, list) {
  54346. var p = list.head;
  54347. var c = 1;
  54348. var ret = p.data;
  54349. n -= ret.length;
  54350. while (p = p.next) {
  54351. var str = p.data;
  54352. var nb = n > str.length ? str.length : n;
  54353. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  54354. n -= nb;
  54355. if (n === 0) {
  54356. if (nb === str.length) {
  54357. ++c;
  54358. if (p.next) list.head = p.next;else list.head = list.tail = null;
  54359. } else {
  54360. list.head = p;
  54361. p.data = str.slice(nb);
  54362. }
  54363. break;
  54364. }
  54365. ++c;
  54366. }
  54367. list.length -= c;
  54368. return ret;
  54369. }
  54370. // Copies a specified amount of bytes from the list of buffered data chunks.
  54371. // This function is designed to be inlinable, so please take care when making
  54372. // changes to the function body.
  54373. function copyFromBuffer(n, list) {
  54374. var ret = Buffer.allocUnsafe(n);
  54375. var p = list.head;
  54376. var c = 1;
  54377. p.data.copy(ret);
  54378. n -= p.data.length;
  54379. while (p = p.next) {
  54380. var buf = p.data;
  54381. var nb = n > buf.length ? buf.length : n;
  54382. buf.copy(ret, ret.length - n, 0, nb);
  54383. n -= nb;
  54384. if (n === 0) {
  54385. if (nb === buf.length) {
  54386. ++c;
  54387. if (p.next) list.head = p.next;else list.head = list.tail = null;
  54388. } else {
  54389. list.head = p;
  54390. p.data = buf.slice(nb);
  54391. }
  54392. break;
  54393. }
  54394. ++c;
  54395. }
  54396. list.length -= c;
  54397. return ret;
  54398. }
  54399. function endReadable(stream) {
  54400. var state = stream._readableState;
  54401. // If we get here before consuming all the bytes, then that is a
  54402. // bug in node. Should never happen.
  54403. if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
  54404. if (!state.endEmitted) {
  54405. state.ended = true;
  54406. pna.nextTick(endReadableNT, state, stream);
  54407. }
  54408. }
  54409. function endReadableNT(state, stream) {
  54410. // Check that we didn't get one last unshift.
  54411. if (!state.endEmitted && state.length === 0) {
  54412. state.endEmitted = true;
  54413. stream.readable = false;
  54414. stream.emit('end');
  54415. }
  54416. }
  54417. function indexOf(xs, x) {
  54418. for (var i = 0, l = xs.length; i < l; i++) {
  54419. if (xs[i] === x) return i;
  54420. }
  54421. return -1;
  54422. }
  54423. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  54424. },{"./_stream_duplex":508,"./internal/streams/BufferList":513,"./internal/streams/destroy":514,"./internal/streams/stream":515,"_process":467,"core-util-is":383,"events":422,"inherits":440,"isarray":506,"process-nextick-args":466,"safe-buffer":520,"string_decoder/":521,"util":188}],511:[function(require,module,exports){
  54425. // Copyright Joyent, Inc. and other Node contributors.
  54426. //
  54427. // Permission is hereby granted, free of charge, to any person obtaining a
  54428. // copy of this software and associated documentation files (the
  54429. // "Software"), to deal in the Software without restriction, including
  54430. // without limitation the rights to use, copy, modify, merge, publish,
  54431. // distribute, sublicense, and/or sell copies of the Software, and to permit
  54432. // persons to whom the Software is furnished to do so, subject to the
  54433. // following conditions:
  54434. //
  54435. // The above copyright notice and this permission notice shall be included
  54436. // in all copies or substantial portions of the Software.
  54437. //
  54438. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  54439. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  54440. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  54441. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  54442. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  54443. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  54444. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  54445. // a transform stream is a readable/writable stream where you do
  54446. // something with the data. Sometimes it's called a "filter",
  54447. // but that's not a great name for it, since that implies a thing where
  54448. // some bits pass through, and others are simply ignored. (That would
  54449. // be a valid example of a transform, of course.)
  54450. //
  54451. // While the output is causally related to the input, it's not a
  54452. // necessarily symmetric or synchronous transformation. For example,
  54453. // a zlib stream might take multiple plain-text writes(), and then
  54454. // emit a single compressed chunk some time in the future.
  54455. //
  54456. // Here's how this works:
  54457. //
  54458. // The Transform stream has all the aspects of the readable and writable
  54459. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  54460. // internally, and returns false if there's a lot of pending writes
  54461. // buffered up. When you call read(), that calls _read(n) until
  54462. // there's enough pending readable data buffered up.
  54463. //
  54464. // In a transform stream, the written data is placed in a buffer. When
  54465. // _read(n) is called, it transforms the queued up data, calling the
  54466. // buffered _write cb's as it consumes chunks. If consuming a single
  54467. // written chunk would result in multiple output chunks, then the first
  54468. // outputted bit calls the readcb, and subsequent chunks just go into
  54469. // the read buffer, and will cause it to emit 'readable' if necessary.
  54470. //
  54471. // This way, back-pressure is actually determined by the reading side,
  54472. // since _read has to be called to start processing a new chunk. However,
  54473. // a pathological inflate type of transform can cause excessive buffering
  54474. // here. For example, imagine a stream where every byte of input is
  54475. // interpreted as an integer from 0-255, and then results in that many
  54476. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  54477. // 1kb of data being output. In this case, you could write a very small
  54478. // amount of input, and end up with a very large amount of output. In
  54479. // such a pathological inflating mechanism, there'd be no way to tell
  54480. // the system to stop doing the transform. A single 4MB write could
  54481. // cause the system to run out of memory.
  54482. //
  54483. // However, even in such a pathological case, only a single written chunk
  54484. // would be consumed, and then the rest would wait (un-transformed) until
  54485. // the results of the previous transformed chunk were consumed.
  54486. 'use strict';
  54487. module.exports = Transform;
  54488. var Duplex = require('./_stream_duplex');
  54489. /*<replacement>*/
  54490. var util = Object.create(require('core-util-is'));
  54491. util.inherits = require('inherits');
  54492. /*</replacement>*/
  54493. util.inherits(Transform, Duplex);
  54494. function afterTransform(er, data) {
  54495. var ts = this._transformState;
  54496. ts.transforming = false;
  54497. var cb = ts.writecb;
  54498. if (!cb) {
  54499. return this.emit('error', new Error('write callback called multiple times'));
  54500. }
  54501. ts.writechunk = null;
  54502. ts.writecb = null;
  54503. if (data != null)
  54504. // single equals check for both `null` and `undefined`
  54505. this.push(data);
  54506. cb(er);
  54507. var rs = this._readableState;
  54508. rs.reading = false;
  54509. if (rs.needReadable || rs.length < rs.highWaterMark) {
  54510. this._read(rs.highWaterMark);
  54511. }
  54512. }
  54513. function Transform(options) {
  54514. if (!(this instanceof Transform)) return new Transform(options);
  54515. Duplex.call(this, options);
  54516. this._transformState = {
  54517. afterTransform: afterTransform.bind(this),
  54518. needTransform: false,
  54519. transforming: false,
  54520. writecb: null,
  54521. writechunk: null,
  54522. writeencoding: null
  54523. };
  54524. // start out asking for a readable event once data is transformed.
  54525. this._readableState.needReadable = true;
  54526. // we have implemented the _read method, and done the other things
  54527. // that Readable wants before the first _read call, so unset the
  54528. // sync guard flag.
  54529. this._readableState.sync = false;
  54530. if (options) {
  54531. if (typeof options.transform === 'function') this._transform = options.transform;
  54532. if (typeof options.flush === 'function') this._flush = options.flush;
  54533. }
  54534. // When the writable side finishes, then flush out anything remaining.
  54535. this.on('prefinish', prefinish);
  54536. }
  54537. function prefinish() {
  54538. var _this = this;
  54539. if (typeof this._flush === 'function') {
  54540. this._flush(function (er, data) {
  54541. done(_this, er, data);
  54542. });
  54543. } else {
  54544. done(this, null, null);
  54545. }
  54546. }
  54547. Transform.prototype.push = function (chunk, encoding) {
  54548. this._transformState.needTransform = false;
  54549. return Duplex.prototype.push.call(this, chunk, encoding);
  54550. };
  54551. // This is the part where you do stuff!
  54552. // override this function in implementation classes.
  54553. // 'chunk' is an input chunk.
  54554. //
  54555. // Call `push(newChunk)` to pass along transformed output
  54556. // to the readable side. You may call 'push' zero or more times.
  54557. //
  54558. // Call `cb(err)` when you are done with this chunk. If you pass
  54559. // an error, then that'll put the hurt on the whole operation. If you
  54560. // never call cb(), then you'll never get another chunk.
  54561. Transform.prototype._transform = function (chunk, encoding, cb) {
  54562. throw new Error('_transform() is not implemented');
  54563. };
  54564. Transform.prototype._write = function (chunk, encoding, cb) {
  54565. var ts = this._transformState;
  54566. ts.writecb = cb;
  54567. ts.writechunk = chunk;
  54568. ts.writeencoding = encoding;
  54569. if (!ts.transforming) {
  54570. var rs = this._readableState;
  54571. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  54572. }
  54573. };
  54574. // Doesn't matter what the args are here.
  54575. // _transform does all the work.
  54576. // That we got here means that the readable side wants more data.
  54577. Transform.prototype._read = function (n) {
  54578. var ts = this._transformState;
  54579. if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
  54580. ts.transforming = true;
  54581. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  54582. } else {
  54583. // mark that we need a transform, so that any data that comes in
  54584. // will get processed, now that we've asked for it.
  54585. ts.needTransform = true;
  54586. }
  54587. };
  54588. Transform.prototype._destroy = function (err, cb) {
  54589. var _this2 = this;
  54590. Duplex.prototype._destroy.call(this, err, function (err2) {
  54591. cb(err2);
  54592. _this2.emit('close');
  54593. });
  54594. };
  54595. function done(stream, er, data) {
  54596. if (er) return stream.emit('error', er);
  54597. if (data != null)
  54598. // single equals check for both `null` and `undefined`
  54599. stream.push(data);
  54600. // if there's nothing in the write buffer, then that means
  54601. // that nothing more will ever be provided
  54602. if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
  54603. if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
  54604. return stream.push(null);
  54605. }
  54606. },{"./_stream_duplex":508,"core-util-is":383,"inherits":440}],512:[function(require,module,exports){
  54607. (function (process,global,setImmediate){(function (){
  54608. // Copyright Joyent, Inc. and other Node contributors.
  54609. //
  54610. // Permission is hereby granted, free of charge, to any person obtaining a
  54611. // copy of this software and associated documentation files (the
  54612. // "Software"), to deal in the Software without restriction, including
  54613. // without limitation the rights to use, copy, modify, merge, publish,
  54614. // distribute, sublicense, and/or sell copies of the Software, and to permit
  54615. // persons to whom the Software is furnished to do so, subject to the
  54616. // following conditions:
  54617. //
  54618. // The above copyright notice and this permission notice shall be included
  54619. // in all copies or substantial portions of the Software.
  54620. //
  54621. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  54622. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  54623. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  54624. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  54625. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  54626. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  54627. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  54628. // A bit simpler than readable streams.
  54629. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  54630. // the drain event emission and buffering.
  54631. 'use strict';
  54632. /*<replacement>*/
  54633. var pna = require('process-nextick-args');
  54634. /*</replacement>*/
  54635. module.exports = Writable;
  54636. /* <replacement> */
  54637. function WriteReq(chunk, encoding, cb) {
  54638. this.chunk = chunk;
  54639. this.encoding = encoding;
  54640. this.callback = cb;
  54641. this.next = null;
  54642. }
  54643. // It seems a linked list but it is not
  54644. // there will be only 2 of these for each stream
  54645. function CorkedRequest(state) {
  54646. var _this = this;
  54647. this.next = null;
  54648. this.entry = null;
  54649. this.finish = function () {
  54650. onCorkedFinish(_this, state);
  54651. };
  54652. }
  54653. /* </replacement> */
  54654. /*<replacement>*/
  54655. var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
  54656. /*</replacement>*/
  54657. /*<replacement>*/
  54658. var Duplex;
  54659. /*</replacement>*/
  54660. Writable.WritableState = WritableState;
  54661. /*<replacement>*/
  54662. var util = Object.create(require('core-util-is'));
  54663. util.inherits = require('inherits');
  54664. /*</replacement>*/
  54665. /*<replacement>*/
  54666. var internalUtil = {
  54667. deprecate: require('util-deprecate')
  54668. };
  54669. /*</replacement>*/
  54670. /*<replacement>*/
  54671. var Stream = require('./internal/streams/stream');
  54672. /*</replacement>*/
  54673. /*<replacement>*/
  54674. var Buffer = require('safe-buffer').Buffer;
  54675. var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
  54676. function _uint8ArrayToBuffer(chunk) {
  54677. return Buffer.from(chunk);
  54678. }
  54679. function _isUint8Array(obj) {
  54680. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  54681. }
  54682. /*</replacement>*/
  54683. var destroyImpl = require('./internal/streams/destroy');
  54684. util.inherits(Writable, Stream);
  54685. function nop() {}
  54686. function WritableState(options, stream) {
  54687. Duplex = Duplex || require('./_stream_duplex');
  54688. options = options || {};
  54689. // Duplex streams are both readable and writable, but share
  54690. // the same options object.
  54691. // However, some cases require setting options to different
  54692. // values for the readable and the writable sides of the duplex stream.
  54693. // These options can be provided separately as readableXXX and writableXXX.
  54694. var isDuplex = stream instanceof Duplex;
  54695. // object stream flag to indicate whether or not this stream
  54696. // contains buffers or objects.
  54697. this.objectMode = !!options.objectMode;
  54698. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
  54699. // the point at which write() starts returning false
  54700. // Note: 0 is a valid value, means that we always return false if
  54701. // the entire buffer is not flushed immediately on write()
  54702. var hwm = options.highWaterMark;
  54703. var writableHwm = options.writableHighWaterMark;
  54704. var defaultHwm = this.objectMode ? 16 : 16 * 1024;
  54705. if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
  54706. // cast to ints.
  54707. this.highWaterMark = Math.floor(this.highWaterMark);
  54708. // if _final has been called
  54709. this.finalCalled = false;
  54710. // drain event flag.
  54711. this.needDrain = false;
  54712. // at the start of calling end()
  54713. this.ending = false;
  54714. // when end() has been called, and returned
  54715. this.ended = false;
  54716. // when 'finish' is emitted
  54717. this.finished = false;
  54718. // has it been destroyed
  54719. this.destroyed = false;
  54720. // should we decode strings into buffers before passing to _write?
  54721. // this is here so that some node-core streams can optimize string
  54722. // handling at a lower level.
  54723. var noDecode = options.decodeStrings === false;
  54724. this.decodeStrings = !noDecode;
  54725. // Crypto is kind of old and crusty. Historically, its default string
  54726. // encoding is 'binary' so we have to make this configurable.
  54727. // Everything else in the universe uses 'utf8', though.
  54728. this.defaultEncoding = options.defaultEncoding || 'utf8';
  54729. // not an actual buffer we keep track of, but a measurement
  54730. // of how much we're waiting to get pushed to some underlying
  54731. // socket or file.
  54732. this.length = 0;
  54733. // a flag to see when we're in the middle of a write.
  54734. this.writing = false;
  54735. // when true all writes will be buffered until .uncork() call
  54736. this.corked = 0;
  54737. // a flag to be able to tell if the onwrite cb is called immediately,
  54738. // or on a later tick. We set this to true at first, because any
  54739. // actions that shouldn't happen until "later" should generally also
  54740. // not happen before the first write call.
  54741. this.sync = true;
  54742. // a flag to know if we're processing previously buffered items, which
  54743. // may call the _write() callback in the same tick, so that we don't
  54744. // end up in an overlapped onwrite situation.
  54745. this.bufferProcessing = false;
  54746. // the callback that's passed to _write(chunk,cb)
  54747. this.onwrite = function (er) {
  54748. onwrite(stream, er);
  54749. };
  54750. // the callback that the user supplies to write(chunk,encoding,cb)
  54751. this.writecb = null;
  54752. // the amount that is being written when _write is called.
  54753. this.writelen = 0;
  54754. this.bufferedRequest = null;
  54755. this.lastBufferedRequest = null;
  54756. // number of pending user-supplied write callbacks
  54757. // this must be 0 before 'finish' can be emitted
  54758. this.pendingcb = 0;
  54759. // emit prefinish if the only thing we're waiting for is _write cbs
  54760. // This is relevant for synchronous Transform streams
  54761. this.prefinished = false;
  54762. // True if the error was already emitted and should not be thrown again
  54763. this.errorEmitted = false;
  54764. // count buffered requests
  54765. this.bufferedRequestCount = 0;
  54766. // allocate the first CorkedRequest, there is always
  54767. // one allocated and free to use, and we maintain at most two
  54768. this.corkedRequestsFree = new CorkedRequest(this);
  54769. }
  54770. WritableState.prototype.getBuffer = function getBuffer() {
  54771. var current = this.bufferedRequest;
  54772. var out = [];
  54773. while (current) {
  54774. out.push(current);
  54775. current = current.next;
  54776. }
  54777. return out;
  54778. };
  54779. (function () {
  54780. try {
  54781. Object.defineProperty(WritableState.prototype, 'buffer', {
  54782. get: internalUtil.deprecate(function () {
  54783. return this.getBuffer();
  54784. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  54785. });
  54786. } catch (_) {}
  54787. })();
  54788. // Test _writableState for inheritance to account for Duplex streams,
  54789. // whose prototype chain only points to Readable.
  54790. var realHasInstance;
  54791. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  54792. realHasInstance = Function.prototype[Symbol.hasInstance];
  54793. Object.defineProperty(Writable, Symbol.hasInstance, {
  54794. value: function (object) {
  54795. if (realHasInstance.call(this, object)) return true;
  54796. if (this !== Writable) return false;
  54797. return object && object._writableState instanceof WritableState;
  54798. }
  54799. });
  54800. } else {
  54801. realHasInstance = function (object) {
  54802. return object instanceof this;
  54803. };
  54804. }
  54805. function Writable(options) {
  54806. Duplex = Duplex || require('./_stream_duplex');
  54807. // Writable ctor is applied to Duplexes, too.
  54808. // `realHasInstance` is necessary because using plain `instanceof`
  54809. // would return false, as no `_writableState` property is attached.
  54810. // Trying to use the custom `instanceof` for Writable here will also break the
  54811. // Node.js LazyTransform implementation, which has a non-trivial getter for
  54812. // `_writableState` that would lead to infinite recursion.
  54813. if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
  54814. return new Writable(options);
  54815. }
  54816. this._writableState = new WritableState(options, this);
  54817. // legacy.
  54818. this.writable = true;
  54819. if (options) {
  54820. if (typeof options.write === 'function') this._write = options.write;
  54821. if (typeof options.writev === 'function') this._writev = options.writev;
  54822. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  54823. if (typeof options.final === 'function') this._final = options.final;
  54824. }
  54825. Stream.call(this);
  54826. }
  54827. // Otherwise people can pipe Writable streams, which is just wrong.
  54828. Writable.prototype.pipe = function () {
  54829. this.emit('error', new Error('Cannot pipe, not readable'));
  54830. };
  54831. function writeAfterEnd(stream, cb) {
  54832. var er = new Error('write after end');
  54833. // TODO: defer error events consistently everywhere, not just the cb
  54834. stream.emit('error', er);
  54835. pna.nextTick(cb, er);
  54836. }
  54837. // Checks that a user-supplied chunk is valid, especially for the particular
  54838. // mode the stream is in. Currently this means that `null` is never accepted
  54839. // and undefined/non-string values are only allowed in object mode.
  54840. function validChunk(stream, state, chunk, cb) {
  54841. var valid = true;
  54842. var er = false;
  54843. if (chunk === null) {
  54844. er = new TypeError('May not write null values to stream');
  54845. } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  54846. er = new TypeError('Invalid non-string/buffer chunk');
  54847. }
  54848. if (er) {
  54849. stream.emit('error', er);
  54850. pna.nextTick(cb, er);
  54851. valid = false;
  54852. }
  54853. return valid;
  54854. }
  54855. Writable.prototype.write = function (chunk, encoding, cb) {
  54856. var state = this._writableState;
  54857. var ret = false;
  54858. var isBuf = !state.objectMode && _isUint8Array(chunk);
  54859. if (isBuf && !Buffer.isBuffer(chunk)) {
  54860. chunk = _uint8ArrayToBuffer(chunk);
  54861. }
  54862. if (typeof encoding === 'function') {
  54863. cb = encoding;
  54864. encoding = null;
  54865. }
  54866. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  54867. if (typeof cb !== 'function') cb = nop;
  54868. if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  54869. state.pendingcb++;
  54870. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  54871. }
  54872. return ret;
  54873. };
  54874. Writable.prototype.cork = function () {
  54875. var state = this._writableState;
  54876. state.corked++;
  54877. };
  54878. Writable.prototype.uncork = function () {
  54879. var state = this._writableState;
  54880. if (state.corked) {
  54881. state.corked--;
  54882. if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  54883. }
  54884. };
  54885. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  54886. // node::ParseEncoding() requires lower case.
  54887. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  54888. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
  54889. this._writableState.defaultEncoding = encoding;
  54890. return this;
  54891. };
  54892. function decodeChunk(state, chunk, encoding) {
  54893. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  54894. chunk = Buffer.from(chunk, encoding);
  54895. }
  54896. return chunk;
  54897. }
  54898. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  54899. // making it explicit this property is not enumerable
  54900. // because otherwise some prototype manipulation in
  54901. // userland will fail
  54902. enumerable: false,
  54903. get: function () {
  54904. return this._writableState.highWaterMark;
  54905. }
  54906. });
  54907. // if we're already writing something, then just put this
  54908. // in the queue, and wait our turn. Otherwise, call _write
  54909. // If we return false, then we need a drain event, so set that flag.
  54910. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  54911. if (!isBuf) {
  54912. var newChunk = decodeChunk(state, chunk, encoding);
  54913. if (chunk !== newChunk) {
  54914. isBuf = true;
  54915. encoding = 'buffer';
  54916. chunk = newChunk;
  54917. }
  54918. }
  54919. var len = state.objectMode ? 1 : chunk.length;
  54920. state.length += len;
  54921. var ret = state.length < state.highWaterMark;
  54922. // we must ensure that previous needDrain will not be reset to false.
  54923. if (!ret) state.needDrain = true;
  54924. if (state.writing || state.corked) {
  54925. var last = state.lastBufferedRequest;
  54926. state.lastBufferedRequest = {
  54927. chunk: chunk,
  54928. encoding: encoding,
  54929. isBuf: isBuf,
  54930. callback: cb,
  54931. next: null
  54932. };
  54933. if (last) {
  54934. last.next = state.lastBufferedRequest;
  54935. } else {
  54936. state.bufferedRequest = state.lastBufferedRequest;
  54937. }
  54938. state.bufferedRequestCount += 1;
  54939. } else {
  54940. doWrite(stream, state, false, len, chunk, encoding, cb);
  54941. }
  54942. return ret;
  54943. }
  54944. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  54945. state.writelen = len;
  54946. state.writecb = cb;
  54947. state.writing = true;
  54948. state.sync = true;
  54949. if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  54950. state.sync = false;
  54951. }
  54952. function onwriteError(stream, state, sync, er, cb) {
  54953. --state.pendingcb;
  54954. if (sync) {
  54955. // defer the callback if we are being called synchronously
  54956. // to avoid piling up things on the stack
  54957. pna.nextTick(cb, er);
  54958. // this can emit finish, and it will always happen
  54959. // after error
  54960. pna.nextTick(finishMaybe, stream, state);
  54961. stream._writableState.errorEmitted = true;
  54962. stream.emit('error', er);
  54963. } else {
  54964. // the caller expect this to happen before if
  54965. // it is async
  54966. cb(er);
  54967. stream._writableState.errorEmitted = true;
  54968. stream.emit('error', er);
  54969. // this can emit finish, but finish must
  54970. // always follow error
  54971. finishMaybe(stream, state);
  54972. }
  54973. }
  54974. function onwriteStateUpdate(state) {
  54975. state.writing = false;
  54976. state.writecb = null;
  54977. state.length -= state.writelen;
  54978. state.writelen = 0;
  54979. }
  54980. function onwrite(stream, er) {
  54981. var state = stream._writableState;
  54982. var sync = state.sync;
  54983. var cb = state.writecb;
  54984. onwriteStateUpdate(state);
  54985. if (er) onwriteError(stream, state, sync, er, cb);else {
  54986. // Check if we're actually ready to finish, but don't emit yet
  54987. var finished = needFinish(state);
  54988. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  54989. clearBuffer(stream, state);
  54990. }
  54991. if (sync) {
  54992. /*<replacement>*/
  54993. asyncWrite(afterWrite, stream, state, finished, cb);
  54994. /*</replacement>*/
  54995. } else {
  54996. afterWrite(stream, state, finished, cb);
  54997. }
  54998. }
  54999. }
  55000. function afterWrite(stream, state, finished, cb) {
  55001. if (!finished) onwriteDrain(stream, state);
  55002. state.pendingcb--;
  55003. cb();
  55004. finishMaybe(stream, state);
  55005. }
  55006. // Must force callback to be called on nextTick, so that we don't
  55007. // emit 'drain' before the write() consumer gets the 'false' return
  55008. // value, and has a chance to attach a 'drain' listener.
  55009. function onwriteDrain(stream, state) {
  55010. if (state.length === 0 && state.needDrain) {
  55011. state.needDrain = false;
  55012. stream.emit('drain');
  55013. }
  55014. }
  55015. // if there's something in the buffer waiting, then process it
  55016. function clearBuffer(stream, state) {
  55017. state.bufferProcessing = true;
  55018. var entry = state.bufferedRequest;
  55019. if (stream._writev && entry && entry.next) {
  55020. // Fast case, write everything using _writev()
  55021. var l = state.bufferedRequestCount;
  55022. var buffer = new Array(l);
  55023. var holder = state.corkedRequestsFree;
  55024. holder.entry = entry;
  55025. var count = 0;
  55026. var allBuffers = true;
  55027. while (entry) {
  55028. buffer[count] = entry;
  55029. if (!entry.isBuf) allBuffers = false;
  55030. entry = entry.next;
  55031. count += 1;
  55032. }
  55033. buffer.allBuffers = allBuffers;
  55034. doWrite(stream, state, true, state.length, buffer, '', holder.finish);
  55035. // doWrite is almost always async, defer these to save a bit of time
  55036. // as the hot path ends with doWrite
  55037. state.pendingcb++;
  55038. state.lastBufferedRequest = null;
  55039. if (holder.next) {
  55040. state.corkedRequestsFree = holder.next;
  55041. holder.next = null;
  55042. } else {
  55043. state.corkedRequestsFree = new CorkedRequest(state);
  55044. }
  55045. state.bufferedRequestCount = 0;
  55046. } else {
  55047. // Slow case, write chunks one-by-one
  55048. while (entry) {
  55049. var chunk = entry.chunk;
  55050. var encoding = entry.encoding;
  55051. var cb = entry.callback;
  55052. var len = state.objectMode ? 1 : chunk.length;
  55053. doWrite(stream, state, false, len, chunk, encoding, cb);
  55054. entry = entry.next;
  55055. state.bufferedRequestCount--;
  55056. // if we didn't call the onwrite immediately, then
  55057. // it means that we need to wait until it does.
  55058. // also, that means that the chunk and cb are currently
  55059. // being processed, so move the buffer counter past them.
  55060. if (state.writing) {
  55061. break;
  55062. }
  55063. }
  55064. if (entry === null) state.lastBufferedRequest = null;
  55065. }
  55066. state.bufferedRequest = entry;
  55067. state.bufferProcessing = false;
  55068. }
  55069. Writable.prototype._write = function (chunk, encoding, cb) {
  55070. cb(new Error('_write() is not implemented'));
  55071. };
  55072. Writable.prototype._writev = null;
  55073. Writable.prototype.end = function (chunk, encoding, cb) {
  55074. var state = this._writableState;
  55075. if (typeof chunk === 'function') {
  55076. cb = chunk;
  55077. chunk = null;
  55078. encoding = null;
  55079. } else if (typeof encoding === 'function') {
  55080. cb = encoding;
  55081. encoding = null;
  55082. }
  55083. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
  55084. // .end() fully uncorks
  55085. if (state.corked) {
  55086. state.corked = 1;
  55087. this.uncork();
  55088. }
  55089. // ignore unnecessary end() calls.
  55090. if (!state.ending) endWritable(this, state, cb);
  55091. };
  55092. function needFinish(state) {
  55093. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  55094. }
  55095. function callFinal(stream, state) {
  55096. stream._final(function (err) {
  55097. state.pendingcb--;
  55098. if (err) {
  55099. stream.emit('error', err);
  55100. }
  55101. state.prefinished = true;
  55102. stream.emit('prefinish');
  55103. finishMaybe(stream, state);
  55104. });
  55105. }
  55106. function prefinish(stream, state) {
  55107. if (!state.prefinished && !state.finalCalled) {
  55108. if (typeof stream._final === 'function') {
  55109. state.pendingcb++;
  55110. state.finalCalled = true;
  55111. pna.nextTick(callFinal, stream, state);
  55112. } else {
  55113. state.prefinished = true;
  55114. stream.emit('prefinish');
  55115. }
  55116. }
  55117. }
  55118. function finishMaybe(stream, state) {
  55119. var need = needFinish(state);
  55120. if (need) {
  55121. prefinish(stream, state);
  55122. if (state.pendingcb === 0) {
  55123. state.finished = true;
  55124. stream.emit('finish');
  55125. }
  55126. }
  55127. return need;
  55128. }
  55129. function endWritable(stream, state, cb) {
  55130. state.ending = true;
  55131. finishMaybe(stream, state);
  55132. if (cb) {
  55133. if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
  55134. }
  55135. state.ended = true;
  55136. stream.writable = false;
  55137. }
  55138. function onCorkedFinish(corkReq, state, err) {
  55139. var entry = corkReq.entry;
  55140. corkReq.entry = null;
  55141. while (entry) {
  55142. var cb = entry.callback;
  55143. state.pendingcb--;
  55144. cb(err);
  55145. entry = entry.next;
  55146. }
  55147. // reuse the free corkReq.
  55148. state.corkedRequestsFree.next = corkReq;
  55149. }
  55150. Object.defineProperty(Writable.prototype, 'destroyed', {
  55151. get: function () {
  55152. if (this._writableState === undefined) {
  55153. return false;
  55154. }
  55155. return this._writableState.destroyed;
  55156. },
  55157. set: function (value) {
  55158. // we ignore the value if the stream
  55159. // has not been initialized yet
  55160. if (!this._writableState) {
  55161. return;
  55162. }
  55163. // backward compatibility, the user is explicitly
  55164. // managing destroyed
  55165. this._writableState.destroyed = value;
  55166. }
  55167. });
  55168. Writable.prototype.destroy = destroyImpl.destroy;
  55169. Writable.prototype._undestroy = destroyImpl.undestroy;
  55170. Writable.prototype._destroy = function (err, cb) {
  55171. this.end();
  55172. cb(err);
  55173. };
  55174. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
  55175. },{"./_stream_duplex":508,"./internal/streams/destroy":514,"./internal/streams/stream":515,"_process":467,"core-util-is":383,"inherits":440,"process-nextick-args":466,"safe-buffer":520,"timers":523,"util-deprecate":524}],513:[function(require,module,exports){
  55176. 'use strict';
  55177. function _classCallCheck(instance, Constructor) {
  55178. if (!(instance instanceof Constructor)) {
  55179. throw new TypeError("Cannot call a class as a function");
  55180. }
  55181. }
  55182. var Buffer = require('safe-buffer').Buffer;
  55183. var util = require('util');
  55184. function copyBuffer(src, target, offset) {
  55185. src.copy(target, offset);
  55186. }
  55187. module.exports = function () {
  55188. function BufferList() {
  55189. _classCallCheck(this, BufferList);
  55190. this.head = null;
  55191. this.tail = null;
  55192. this.length = 0;
  55193. }
  55194. BufferList.prototype.push = function push(v) {
  55195. var entry = {
  55196. data: v,
  55197. next: null
  55198. };
  55199. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  55200. this.tail = entry;
  55201. ++this.length;
  55202. };
  55203. BufferList.prototype.unshift = function unshift(v) {
  55204. var entry = {
  55205. data: v,
  55206. next: this.head
  55207. };
  55208. if (this.length === 0) this.tail = entry;
  55209. this.head = entry;
  55210. ++this.length;
  55211. };
  55212. BufferList.prototype.shift = function shift() {
  55213. if (this.length === 0) return;
  55214. var ret = this.head.data;
  55215. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  55216. --this.length;
  55217. return ret;
  55218. };
  55219. BufferList.prototype.clear = function clear() {
  55220. this.head = this.tail = null;
  55221. this.length = 0;
  55222. };
  55223. BufferList.prototype.join = function join(s) {
  55224. if (this.length === 0) return '';
  55225. var p = this.head;
  55226. var ret = '' + p.data;
  55227. while (p = p.next) {
  55228. ret += s + p.data;
  55229. }
  55230. return ret;
  55231. };
  55232. BufferList.prototype.concat = function concat(n) {
  55233. if (this.length === 0) return Buffer.alloc(0);
  55234. var ret = Buffer.allocUnsafe(n >>> 0);
  55235. var p = this.head;
  55236. var i = 0;
  55237. while (p) {
  55238. copyBuffer(p.data, ret, i);
  55239. i += p.data.length;
  55240. p = p.next;
  55241. }
  55242. return ret;
  55243. };
  55244. return BufferList;
  55245. }();
  55246. if (util && util.inspect && util.inspect.custom) {
  55247. module.exports.prototype[util.inspect.custom] = function () {
  55248. var obj = util.inspect({
  55249. length: this.length
  55250. });
  55251. return this.constructor.name + ' ' + obj;
  55252. };
  55253. }
  55254. },{"safe-buffer":520,"util":188}],514:[function(require,module,exports){
  55255. 'use strict';
  55256. /*<replacement>*/
  55257. var pna = require('process-nextick-args');
  55258. /*</replacement>*/
  55259. // undocumented cb() API, needed for core, not for public API
  55260. function destroy(err, cb) {
  55261. var _this = this;
  55262. var readableDestroyed = this._readableState && this._readableState.destroyed;
  55263. var writableDestroyed = this._writableState && this._writableState.destroyed;
  55264. if (readableDestroyed || writableDestroyed) {
  55265. if (cb) {
  55266. cb(err);
  55267. } else if (err) {
  55268. if (!this._writableState) {
  55269. pna.nextTick(emitErrorNT, this, err);
  55270. } else if (!this._writableState.errorEmitted) {
  55271. this._writableState.errorEmitted = true;
  55272. pna.nextTick(emitErrorNT, this, err);
  55273. }
  55274. }
  55275. return this;
  55276. }
  55277. // we set destroyed to true before firing error callbacks in order
  55278. // to make it re-entrance safe in case destroy() is called within callbacks
  55279. if (this._readableState) {
  55280. this._readableState.destroyed = true;
  55281. }
  55282. // if this is a duplex stream mark the writable part as destroyed as well
  55283. if (this._writableState) {
  55284. this._writableState.destroyed = true;
  55285. }
  55286. this._destroy(err || null, function (err) {
  55287. if (!cb && err) {
  55288. if (!_this._writableState) {
  55289. pna.nextTick(emitErrorNT, _this, err);
  55290. } else if (!_this._writableState.errorEmitted) {
  55291. _this._writableState.errorEmitted = true;
  55292. pna.nextTick(emitErrorNT, _this, err);
  55293. }
  55294. } else if (cb) {
  55295. cb(err);
  55296. }
  55297. });
  55298. return this;
  55299. }
  55300. function undestroy() {
  55301. if (this._readableState) {
  55302. this._readableState.destroyed = false;
  55303. this._readableState.reading = false;
  55304. this._readableState.ended = false;
  55305. this._readableState.endEmitted = false;
  55306. }
  55307. if (this._writableState) {
  55308. this._writableState.destroyed = false;
  55309. this._writableState.ended = false;
  55310. this._writableState.ending = false;
  55311. this._writableState.finalCalled = false;
  55312. this._writableState.prefinished = false;
  55313. this._writableState.finished = false;
  55314. this._writableState.errorEmitted = false;
  55315. }
  55316. }
  55317. function emitErrorNT(self, err) {
  55318. self.emit('error', err);
  55319. }
  55320. module.exports = {
  55321. destroy: destroy,
  55322. undestroy: undestroy
  55323. };
  55324. },{"process-nextick-args":466}],515:[function(require,module,exports){
  55325. arguments[4][490][0].apply(exports,arguments)
  55326. },{"dup":490,"events":422}],516:[function(require,module,exports){
  55327. "use strict";
  55328. module.exports = require('./readable').PassThrough;
  55329. },{"./readable":517}],517:[function(require,module,exports){
  55330. "use strict";
  55331. exports = module.exports = require('./lib/_stream_readable.js');
  55332. exports.Stream = exports;
  55333. exports.Readable = exports;
  55334. exports.Writable = require('./lib/_stream_writable.js');
  55335. exports.Duplex = require('./lib/_stream_duplex.js');
  55336. exports.Transform = require('./lib/_stream_transform.js');
  55337. exports.PassThrough = require('./lib/_stream_passthrough.js');
  55338. },{"./lib/_stream_duplex.js":508,"./lib/_stream_passthrough.js":509,"./lib/_stream_readable.js":510,"./lib/_stream_transform.js":511,"./lib/_stream_writable.js":512}],518:[function(require,module,exports){
  55339. "use strict";
  55340. module.exports = require('./readable').Transform;
  55341. },{"./readable":517}],519:[function(require,module,exports){
  55342. "use strict";
  55343. module.exports = require('./lib/_stream_writable.js');
  55344. },{"./lib/_stream_writable.js":512}],520:[function(require,module,exports){
  55345. arguments[4][217][0].apply(exports,arguments)
  55346. },{"buffer":220,"dup":217}],521:[function(require,module,exports){
  55347. arguments[4][218][0].apply(exports,arguments)
  55348. },{"dup":218,"safe-buffer":520}],522:[function(require,module,exports){
  55349. arguments[4][218][0].apply(exports,arguments)
  55350. },{"dup":218,"safe-buffer":494}],523:[function(require,module,exports){
  55351. (function (setImmediate,clearImmediate){(function (){
  55352. "use strict";
  55353. var nextTick = require('process/browser.js').nextTick;
  55354. var apply = Function.prototype.apply;
  55355. var slice = Array.prototype.slice;
  55356. var immediateIds = {};
  55357. var nextImmediateId = 0;
  55358. // DOM APIs, for completeness
  55359. exports.setTimeout = function () {
  55360. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  55361. };
  55362. exports.setInterval = function () {
  55363. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  55364. };
  55365. exports.clearTimeout = exports.clearInterval = function (timeout) {
  55366. timeout.close();
  55367. };
  55368. function Timeout(id, clearFn) {
  55369. this._id = id;
  55370. this._clearFn = clearFn;
  55371. }
  55372. Timeout.prototype.unref = Timeout.prototype.ref = function () {};
  55373. Timeout.prototype.close = function () {
  55374. this._clearFn.call(window, this._id);
  55375. };
  55376. // Does not start the time, just sets up the members needed.
  55377. exports.enroll = function (item, msecs) {
  55378. clearTimeout(item._idleTimeoutId);
  55379. item._idleTimeout = msecs;
  55380. };
  55381. exports.unenroll = function (item) {
  55382. clearTimeout(item._idleTimeoutId);
  55383. item._idleTimeout = -1;
  55384. };
  55385. exports._unrefActive = exports.active = function (item) {
  55386. clearTimeout(item._idleTimeoutId);
  55387. var msecs = item._idleTimeout;
  55388. if (msecs >= 0) {
  55389. item._idleTimeoutId = setTimeout(function onTimeout() {
  55390. if (item._onTimeout) item._onTimeout();
  55391. }, msecs);
  55392. }
  55393. };
  55394. // That's not how node.js implements it but the exposed api is the same.
  55395. exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function (fn) {
  55396. var id = nextImmediateId++;
  55397. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  55398. immediateIds[id] = true;
  55399. nextTick(function onNextTick() {
  55400. if (immediateIds[id]) {
  55401. // fn.call() is faster so we optimize for the common use-case
  55402. // @see http://jsperf.com/call-apply-segu
  55403. if (args) {
  55404. fn.apply(null, args);
  55405. } else {
  55406. fn.call(null);
  55407. }
  55408. // Prevent ids from leaking
  55409. exports.clearImmediate(id);
  55410. }
  55411. });
  55412. return id;
  55413. };
  55414. exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function (id) {
  55415. delete immediateIds[id];
  55416. };
  55417. }).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
  55418. },{"process/browser.js":467,"timers":523}],524:[function(require,module,exports){
  55419. (function (global){(function (){
  55420. "use strict";
  55421. /**
  55422. * Module exports.
  55423. */
  55424. module.exports = deprecate;
  55425. /**
  55426. * Mark that a method should not be used.
  55427. * Returns a modified function which warns once by default.
  55428. *
  55429. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  55430. *
  55431. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  55432. * will throw an Error when invoked.
  55433. *
  55434. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  55435. * will invoke `console.trace()` instead of `console.error()`.
  55436. *
  55437. * @param {Function} fn - the function to deprecate
  55438. * @param {String} msg - the string to print to the console when `fn` is invoked
  55439. * @returns {Function} a new "deprecated" version of `fn`
  55440. * @api public
  55441. */
  55442. function deprecate(fn, msg) {
  55443. if (config('noDeprecation')) {
  55444. return fn;
  55445. }
  55446. var warned = false;
  55447. function deprecated() {
  55448. if (!warned) {
  55449. if (config('throwDeprecation')) {
  55450. throw new Error(msg);
  55451. } else if (config('traceDeprecation')) {
  55452. console.trace(msg);
  55453. } else {
  55454. console.warn(msg);
  55455. }
  55456. warned = true;
  55457. }
  55458. return fn.apply(this, arguments);
  55459. }
  55460. return deprecated;
  55461. }
  55462. /**
  55463. * Checks `localStorage` for boolean values for the given `name`.
  55464. *
  55465. * @param {String} name
  55466. * @returns {Boolean}
  55467. * @api private
  55468. */
  55469. function config(name) {
  55470. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  55471. try {
  55472. if (!global.localStorage) return false;
  55473. } catch (_) {
  55474. return false;
  55475. }
  55476. var val = global.localStorage[name];
  55477. if (null == val) return false;
  55478. return String(val).toLowerCase() === 'true';
  55479. }
  55480. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  55481. },{}],525:[function(require,module,exports){
  55482. "use strict";
  55483. if (typeof Object.create === 'function') {
  55484. // implementation from standard node.js 'util' module
  55485. module.exports = function inherits(ctor, superCtor) {
  55486. ctor.super_ = superCtor;
  55487. ctor.prototype = Object.create(superCtor.prototype, {
  55488. constructor: {
  55489. value: ctor,
  55490. enumerable: false,
  55491. writable: true,
  55492. configurable: true
  55493. }
  55494. });
  55495. };
  55496. } else {
  55497. // old school shim for old browsers
  55498. module.exports = function inherits(ctor, superCtor) {
  55499. ctor.super_ = superCtor;
  55500. var TempCtor = function () {};
  55501. TempCtor.prototype = superCtor.prototype;
  55502. ctor.prototype = new TempCtor();
  55503. ctor.prototype.constructor = ctor;
  55504. };
  55505. }
  55506. },{}],526:[function(require,module,exports){
  55507. "use strict";
  55508. module.exports = function isBuffer(arg) {
  55509. return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function';
  55510. };
  55511. },{}],527:[function(require,module,exports){
  55512. (function (process,global){(function (){
  55513. "use strict";
  55514. // Copyright Joyent, Inc. and other Node contributors.
  55515. //
  55516. // Permission is hereby granted, free of charge, to any person obtaining a
  55517. // copy of this software and associated documentation files (the
  55518. // "Software"), to deal in the Software without restriction, including
  55519. // without limitation the rights to use, copy, modify, merge, publish,
  55520. // distribute, sublicense, and/or sell copies of the Software, and to permit
  55521. // persons to whom the Software is furnished to do so, subject to the
  55522. // following conditions:
  55523. //
  55524. // The above copyright notice and this permission notice shall be included
  55525. // in all copies or substantial portions of the Software.
  55526. //
  55527. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  55528. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  55529. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  55530. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  55531. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  55532. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  55533. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  55534. var formatRegExp = /%[sdj%]/g;
  55535. exports.format = function (f) {
  55536. if (!isString(f)) {
  55537. var objects = [];
  55538. for (var i = 0; i < arguments.length; i++) {
  55539. objects.push(inspect(arguments[i]));
  55540. }
  55541. return objects.join(' ');
  55542. }
  55543. var i = 1;
  55544. var args = arguments;
  55545. var len = args.length;
  55546. var str = String(f).replace(formatRegExp, function (x) {
  55547. if (x === '%%') return '%';
  55548. if (i >= len) return x;
  55549. switch (x) {
  55550. case '%s':
  55551. return String(args[i++]);
  55552. case '%d':
  55553. return Number(args[i++]);
  55554. case '%j':
  55555. try {
  55556. return JSON.stringify(args[i++]);
  55557. } catch (_) {
  55558. return '[Circular]';
  55559. }
  55560. default:
  55561. return x;
  55562. }
  55563. });
  55564. for (var x = args[i]; i < len; x = args[++i]) {
  55565. if (isNull(x) || !isObject(x)) {
  55566. str += ' ' + x;
  55567. } else {
  55568. str += ' ' + inspect(x);
  55569. }
  55570. }
  55571. return str;
  55572. };
  55573. // Mark that a method should not be used.
  55574. // Returns a modified function which warns once by default.
  55575. // If --no-deprecation is set, then it is a no-op.
  55576. exports.deprecate = function (fn, msg) {
  55577. // Allow for deprecating things in the process of starting up.
  55578. if (isUndefined(global.process)) {
  55579. return function () {
  55580. return exports.deprecate(fn, msg).apply(this, arguments);
  55581. };
  55582. }
  55583. if (process.noDeprecation === true) {
  55584. return fn;
  55585. }
  55586. var warned = false;
  55587. function deprecated() {
  55588. if (!warned) {
  55589. if (process.throwDeprecation) {
  55590. throw new Error(msg);
  55591. } else if (process.traceDeprecation) {
  55592. console.trace(msg);
  55593. } else {
  55594. console.error(msg);
  55595. }
  55596. warned = true;
  55597. }
  55598. return fn.apply(this, arguments);
  55599. }
  55600. return deprecated;
  55601. };
  55602. var debugs = {};
  55603. var debugEnviron;
  55604. exports.debuglog = function (set) {
  55605. if (isUndefined(debugEnviron)) debugEnviron = process.env.NODE_DEBUG || '';
  55606. set = set.toUpperCase();
  55607. if (!debugs[set]) {
  55608. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  55609. var pid = process.pid;
  55610. debugs[set] = function () {
  55611. var msg = exports.format.apply(exports, arguments);
  55612. console.error('%s %d: %s', set, pid, msg);
  55613. };
  55614. } else {
  55615. debugs[set] = function () {};
  55616. }
  55617. }
  55618. return debugs[set];
  55619. };
  55620. /**
  55621. * Echos the value of a value. Trys to print the value out
  55622. * in the best way possible given the different types.
  55623. *
  55624. * @param {Object} obj The object to print out.
  55625. * @param {Object} opts Optional options object that alters the output.
  55626. */
  55627. /* legacy: obj, showHidden, depth, colors*/
  55628. function inspect(obj, opts) {
  55629. // default options
  55630. var ctx = {
  55631. seen: [],
  55632. stylize: stylizeNoColor
  55633. };
  55634. // legacy...
  55635. if (arguments.length >= 3) ctx.depth = arguments[2];
  55636. if (arguments.length >= 4) ctx.colors = arguments[3];
  55637. if (isBoolean(opts)) {
  55638. // legacy...
  55639. ctx.showHidden = opts;
  55640. } else if (opts) {
  55641. // got an "options" object
  55642. exports._extend(ctx, opts);
  55643. }
  55644. // set default options
  55645. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  55646. if (isUndefined(ctx.depth)) ctx.depth = 2;
  55647. if (isUndefined(ctx.colors)) ctx.colors = false;
  55648. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  55649. if (ctx.colors) ctx.stylize = stylizeWithColor;
  55650. return formatValue(ctx, obj, ctx.depth);
  55651. }
  55652. exports.inspect = inspect;
  55653. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  55654. inspect.colors = {
  55655. 'bold': [1, 22],
  55656. 'italic': [3, 23],
  55657. 'underline': [4, 24],
  55658. 'inverse': [7, 27],
  55659. 'white': [37, 39],
  55660. 'grey': [90, 39],
  55661. 'black': [30, 39],
  55662. 'blue': [34, 39],
  55663. 'cyan': [36, 39],
  55664. 'green': [32, 39],
  55665. 'magenta': [35, 39],
  55666. 'red': [31, 39],
  55667. 'yellow': [33, 39]
  55668. };
  55669. // Don't use 'blue' not visible on cmd.exe
  55670. inspect.styles = {
  55671. 'special': 'cyan',
  55672. 'number': 'yellow',
  55673. 'boolean': 'yellow',
  55674. 'undefined': 'grey',
  55675. 'null': 'bold',
  55676. 'string': 'green',
  55677. 'date': 'magenta',
  55678. // "name": intentionally not styling
  55679. 'regexp': 'red'
  55680. };
  55681. function stylizeWithColor(str, styleType) {
  55682. var style = inspect.styles[styleType];
  55683. if (style) {
  55684. return '\u001b[' + inspect.colors[style][0] + 'm' + str + '\u001b[' + inspect.colors[style][1] + 'm';
  55685. } else {
  55686. return str;
  55687. }
  55688. }
  55689. function stylizeNoColor(str, styleType) {
  55690. return str;
  55691. }
  55692. function arrayToHash(array) {
  55693. var hash = {};
  55694. array.forEach(function (val, idx) {
  55695. hash[val] = true;
  55696. });
  55697. return hash;
  55698. }
  55699. function formatValue(ctx, value, recurseTimes) {
  55700. // Provide a hook for user-specified inspect functions.
  55701. // Check that value is an object with an inspect function on it
  55702. if (ctx.customInspect && value && isFunction(value.inspect) &&
  55703. // Filter out the util module, it's inspect function is special
  55704. value.inspect !== exports.inspect &&
  55705. // Also filter out any prototype objects using the circular check.
  55706. !(value.constructor && value.constructor.prototype === value)) {
  55707. var ret = value.inspect(recurseTimes, ctx);
  55708. if (!isString(ret)) {
  55709. ret = formatValue(ctx, ret, recurseTimes);
  55710. }
  55711. return ret;
  55712. }
  55713. // Primitive types cannot have properties
  55714. var primitive = formatPrimitive(ctx, value);
  55715. if (primitive) {
  55716. return primitive;
  55717. }
  55718. // Look up the keys of the object.
  55719. var keys = Object.keys(value);
  55720. var visibleKeys = arrayToHash(keys);
  55721. if (ctx.showHidden) {
  55722. keys = Object.getOwnPropertyNames(value);
  55723. }
  55724. // IE doesn't make error fields non-enumerable
  55725. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  55726. if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  55727. return formatError(value);
  55728. }
  55729. // Some type of object without properties can be shortcutted.
  55730. if (keys.length === 0) {
  55731. if (isFunction(value)) {
  55732. var name = value.name ? ': ' + value.name : '';
  55733. return ctx.stylize('[Function' + name + ']', 'special');
  55734. }
  55735. if (isRegExp(value)) {
  55736. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  55737. }
  55738. if (isDate(value)) {
  55739. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  55740. }
  55741. if (isError(value)) {
  55742. return formatError(value);
  55743. }
  55744. }
  55745. var base = '',
  55746. array = false,
  55747. braces = ['{', '}'];
  55748. // Make Array say that they are Array
  55749. if (isArray(value)) {
  55750. array = true;
  55751. braces = ['[', ']'];
  55752. }
  55753. // Make functions say that they are functions
  55754. if (isFunction(value)) {
  55755. var n = value.name ? ': ' + value.name : '';
  55756. base = ' [Function' + n + ']';
  55757. }
  55758. // Make RegExps say that they are RegExps
  55759. if (isRegExp(value)) {
  55760. base = ' ' + RegExp.prototype.toString.call(value);
  55761. }
  55762. // Make dates with properties first say the date
  55763. if (isDate(value)) {
  55764. base = ' ' + Date.prototype.toUTCString.call(value);
  55765. }
  55766. // Make error with message first say the error
  55767. if (isError(value)) {
  55768. base = ' ' + formatError(value);
  55769. }
  55770. if (keys.length === 0 && (!array || value.length == 0)) {
  55771. return braces[0] + base + braces[1];
  55772. }
  55773. if (recurseTimes < 0) {
  55774. if (isRegExp(value)) {
  55775. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  55776. } else {
  55777. return ctx.stylize('[Object]', 'special');
  55778. }
  55779. }
  55780. ctx.seen.push(value);
  55781. var output;
  55782. if (array) {
  55783. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  55784. } else {
  55785. output = keys.map(function (key) {
  55786. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  55787. });
  55788. }
  55789. ctx.seen.pop();
  55790. return reduceToSingleString(output, base, braces);
  55791. }
  55792. function formatPrimitive(ctx, value) {
  55793. if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
  55794. if (isString(value)) {
  55795. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
  55796. return ctx.stylize(simple, 'string');
  55797. }
  55798. if (isNumber(value)) return ctx.stylize('' + value, 'number');
  55799. if (isBoolean(value)) return ctx.stylize('' + value, 'boolean');
  55800. // For some reason typeof null is "object", so special case here.
  55801. if (isNull(value)) return ctx.stylize('null', 'null');
  55802. }
  55803. function formatError(value) {
  55804. return '[' + Error.prototype.toString.call(value) + ']';
  55805. }
  55806. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  55807. var output = [];
  55808. for (var i = 0, l = value.length; i < l; ++i) {
  55809. if (hasOwnProperty(value, String(i))) {
  55810. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
  55811. } else {
  55812. output.push('');
  55813. }
  55814. }
  55815. keys.forEach(function (key) {
  55816. if (!key.match(/^\d+$/)) {
  55817. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
  55818. }
  55819. });
  55820. return output;
  55821. }
  55822. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  55823. var name, str, desc;
  55824. desc = Object.getOwnPropertyDescriptor(value, key) || {
  55825. value: value[key]
  55826. };
  55827. if (desc.get) {
  55828. if (desc.set) {
  55829. str = ctx.stylize('[Getter/Setter]', 'special');
  55830. } else {
  55831. str = ctx.stylize('[Getter]', 'special');
  55832. }
  55833. } else {
  55834. if (desc.set) {
  55835. str = ctx.stylize('[Setter]', 'special');
  55836. }
  55837. }
  55838. if (!hasOwnProperty(visibleKeys, key)) {
  55839. name = '[' + key + ']';
  55840. }
  55841. if (!str) {
  55842. if (ctx.seen.indexOf(desc.value) < 0) {
  55843. if (isNull(recurseTimes)) {
  55844. str = formatValue(ctx, desc.value, null);
  55845. } else {
  55846. str = formatValue(ctx, desc.value, recurseTimes - 1);
  55847. }
  55848. if (str.indexOf('\n') > -1) {
  55849. if (array) {
  55850. str = str.split('\n').map(function (line) {
  55851. return ' ' + line;
  55852. }).join('\n').substr(2);
  55853. } else {
  55854. str = '\n' + str.split('\n').map(function (line) {
  55855. return ' ' + line;
  55856. }).join('\n');
  55857. }
  55858. }
  55859. } else {
  55860. str = ctx.stylize('[Circular]', 'special');
  55861. }
  55862. }
  55863. if (isUndefined(name)) {
  55864. if (array && key.match(/^\d+$/)) {
  55865. return str;
  55866. }
  55867. name = JSON.stringify('' + key);
  55868. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  55869. name = name.substr(1, name.length - 2);
  55870. name = ctx.stylize(name, 'name');
  55871. } else {
  55872. name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  55873. name = ctx.stylize(name, 'string');
  55874. }
  55875. }
  55876. return name + ': ' + str;
  55877. }
  55878. function reduceToSingleString(output, base, braces) {
  55879. var numLinesEst = 0;
  55880. var length = output.reduce(function (prev, cur) {
  55881. numLinesEst++;
  55882. if (cur.indexOf('\n') >= 0) numLinesEst++;
  55883. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  55884. }, 0);
  55885. if (length > 60) {
  55886. return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
  55887. }
  55888. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  55889. }
  55890. // NOTE: These type checking functions intentionally don't use `instanceof`
  55891. // because it is fragile and can be easily faked with `Object.create()`.
  55892. function isArray(ar) {
  55893. return Array.isArray(ar);
  55894. }
  55895. exports.isArray = isArray;
  55896. function isBoolean(arg) {
  55897. return typeof arg === 'boolean';
  55898. }
  55899. exports.isBoolean = isBoolean;
  55900. function isNull(arg) {
  55901. return arg === null;
  55902. }
  55903. exports.isNull = isNull;
  55904. function isNullOrUndefined(arg) {
  55905. return arg == null;
  55906. }
  55907. exports.isNullOrUndefined = isNullOrUndefined;
  55908. function isNumber(arg) {
  55909. return typeof arg === 'number';
  55910. }
  55911. exports.isNumber = isNumber;
  55912. function isString(arg) {
  55913. return typeof arg === 'string';
  55914. }
  55915. exports.isString = isString;
  55916. function isSymbol(arg) {
  55917. return typeof arg === 'symbol';
  55918. }
  55919. exports.isSymbol = isSymbol;
  55920. function isUndefined(arg) {
  55921. return arg === void 0;
  55922. }
  55923. exports.isUndefined = isUndefined;
  55924. function isRegExp(re) {
  55925. return isObject(re) && objectToString(re) === '[object RegExp]';
  55926. }
  55927. exports.isRegExp = isRegExp;
  55928. function isObject(arg) {
  55929. return typeof arg === 'object' && arg !== null;
  55930. }
  55931. exports.isObject = isObject;
  55932. function isDate(d) {
  55933. return isObject(d) && objectToString(d) === '[object Date]';
  55934. }
  55935. exports.isDate = isDate;
  55936. function isError(e) {
  55937. return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
  55938. }
  55939. exports.isError = isError;
  55940. function isFunction(arg) {
  55941. return typeof arg === 'function';
  55942. }
  55943. exports.isFunction = isFunction;
  55944. function isPrimitive(arg) {
  55945. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || typeof arg === 'symbol' ||
  55946. // ES6 symbol
  55947. typeof arg === 'undefined';
  55948. }
  55949. exports.isPrimitive = isPrimitive;
  55950. exports.isBuffer = require('./support/isBuffer');
  55951. function objectToString(o) {
  55952. return Object.prototype.toString.call(o);
  55953. }
  55954. function pad(n) {
  55955. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  55956. }
  55957. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  55958. // 26 Feb 16:19:34
  55959. function timestamp() {
  55960. var d = new Date();
  55961. var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
  55962. return [d.getDate(), months[d.getMonth()], time].join(' ');
  55963. }
  55964. // log is just a thin wrapper to console.log that prepends a timestamp
  55965. exports.log = function () {
  55966. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  55967. };
  55968. /**
  55969. * Inherit the prototype methods from one constructor into another.
  55970. *
  55971. * The Function.prototype.inherits from lang.js rewritten as a standalone
  55972. * function (not on Function.prototype). NOTE: If this file is to be loaded
  55973. * during bootstrapping this function needs to be rewritten using some native
  55974. * functions as prototype setup using normal JavaScript does not work as
  55975. * expected during bootstrapping (see mirror.js in r114903).
  55976. *
  55977. * @param {function} ctor Constructor function which needs to inherit the
  55978. * prototype.
  55979. * @param {function} superCtor Constructor function to inherit prototype from.
  55980. */
  55981. exports.inherits = require('inherits');
  55982. exports._extend = function (origin, add) {
  55983. // Don't do anything if add isn't an object
  55984. if (!add || !isObject(add)) return origin;
  55985. var keys = Object.keys(add);
  55986. var i = keys.length;
  55987. while (i--) {
  55988. origin[keys[i]] = add[keys[i]];
  55989. }
  55990. return origin;
  55991. };
  55992. function hasOwnProperty(obj, prop) {
  55993. return Object.prototype.hasOwnProperty.call(obj, prop);
  55994. }
  55995. }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  55996. },{"./support/isBuffer":526,"_process":467,"inherits":525}],528:[function(require,module,exports){
  55997. "use strict";
  55998. Object.defineProperty(exports, "__esModule", {
  55999. value: true
  56000. });
  56001. Object.defineProperty(exports, "v1", {
  56002. enumerable: true,
  56003. get: function () {
  56004. return _v.default;
  56005. }
  56006. });
  56007. Object.defineProperty(exports, "v3", {
  56008. enumerable: true,
  56009. get: function () {
  56010. return _v2.default;
  56011. }
  56012. });
  56013. Object.defineProperty(exports, "v4", {
  56014. enumerable: true,
  56015. get: function () {
  56016. return _v3.default;
  56017. }
  56018. });
  56019. Object.defineProperty(exports, "v5", {
  56020. enumerable: true,
  56021. get: function () {
  56022. return _v4.default;
  56023. }
  56024. });
  56025. Object.defineProperty(exports, "NIL", {
  56026. enumerable: true,
  56027. get: function () {
  56028. return _nil.default;
  56029. }
  56030. });
  56031. Object.defineProperty(exports, "version", {
  56032. enumerable: true,
  56033. get: function () {
  56034. return _version.default;
  56035. }
  56036. });
  56037. Object.defineProperty(exports, "validate", {
  56038. enumerable: true,
  56039. get: function () {
  56040. return _validate.default;
  56041. }
  56042. });
  56043. Object.defineProperty(exports, "stringify", {
  56044. enumerable: true,
  56045. get: function () {
  56046. return _stringify.default;
  56047. }
  56048. });
  56049. Object.defineProperty(exports, "parse", {
  56050. enumerable: true,
  56051. get: function () {
  56052. return _parse.default;
  56053. }
  56054. });
  56055. var _v = _interopRequireDefault(require("./v1.js"));
  56056. var _v2 = _interopRequireDefault(require("./v3.js"));
  56057. var _v3 = _interopRequireDefault(require("./v4.js"));
  56058. var _v4 = _interopRequireDefault(require("./v5.js"));
  56059. var _nil = _interopRequireDefault(require("./nil.js"));
  56060. var _version = _interopRequireDefault(require("./version.js"));
  56061. var _validate = _interopRequireDefault(require("./validate.js"));
  56062. var _stringify = _interopRequireDefault(require("./stringify.js"));
  56063. var _parse = _interopRequireDefault(require("./parse.js"));
  56064. function _interopRequireDefault(obj) {
  56065. return obj && obj.__esModule ? obj : {
  56066. default: obj
  56067. };
  56068. }
  56069. },{"./nil.js":530,"./parse.js":531,"./stringify.js":535,"./v1.js":536,"./v3.js":537,"./v4.js":539,"./v5.js":540,"./validate.js":541,"./version.js":542}],529:[function(require,module,exports){
  56070. "use strict";
  56071. Object.defineProperty(exports, "__esModule", {
  56072. value: true
  56073. });
  56074. exports.default = void 0;
  56075. /*
  56076. * Browser-compatible JavaScript MD5
  56077. *
  56078. * Modification of JavaScript MD5
  56079. * https://github.com/blueimp/JavaScript-MD5
  56080. *
  56081. * Copyright 2011, Sebastian Tschan
  56082. * https://blueimp.net
  56083. *
  56084. * Licensed under the MIT license:
  56085. * https://opensource.org/licenses/MIT
  56086. *
  56087. * Based on
  56088. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  56089. * Digest Algorithm, as defined in RFC 1321.
  56090. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
  56091. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  56092. * Distributed under the BSD License
  56093. * See http://pajhome.org.uk/crypt/md5 for more info.
  56094. */
  56095. function md5(bytes) {
  56096. if (typeof bytes === 'string') {
  56097. const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  56098. bytes = new Uint8Array(msg.length);
  56099. for (let i = 0; i < msg.length; ++i) {
  56100. bytes[i] = msg.charCodeAt(i);
  56101. }
  56102. }
  56103. return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
  56104. }
  56105. /*
  56106. * Convert an array of little-endian words to an array of bytes
  56107. */
  56108. function md5ToHexEncodedArray(input) {
  56109. const output = [];
  56110. const length32 = input.length * 32;
  56111. const hexTab = '0123456789abcdef';
  56112. for (let i = 0; i < length32; i += 8) {
  56113. const x = input[i >> 5] >>> i % 32 & 0xff;
  56114. const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
  56115. output.push(hex);
  56116. }
  56117. return output;
  56118. }
  56119. /**
  56120. * Calculate output length with padding and bit length
  56121. */
  56122. function getOutputLength(inputLength8) {
  56123. return (inputLength8 + 64 >>> 9 << 4) + 14 + 1;
  56124. }
  56125. /*
  56126. * Calculate the MD5 of an array of little-endian words, and a bit length.
  56127. */
  56128. function wordsToMd5(x, len) {
  56129. /* append padding */
  56130. x[len >> 5] |= 0x80 << len % 32;
  56131. x[getOutputLength(len) - 1] = len;
  56132. let a = 1732584193;
  56133. let b = -271733879;
  56134. let c = -1732584194;
  56135. let d = 271733878;
  56136. for (let i = 0; i < x.length; i += 16) {
  56137. const olda = a;
  56138. const oldb = b;
  56139. const oldc = c;
  56140. const oldd = d;
  56141. a = md5ff(a, b, c, d, x[i], 7, -680876936);
  56142. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
  56143. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
  56144. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
  56145. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
  56146. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
  56147. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
  56148. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
  56149. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
  56150. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
  56151. c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
  56152. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
  56153. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
  56154. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
  56155. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
  56156. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
  56157. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
  56158. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
  56159. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
  56160. b = md5gg(b, c, d, a, x[i], 20, -373897302);
  56161. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
  56162. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
  56163. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
  56164. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
  56165. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
  56166. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
  56167. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
  56168. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
  56169. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
  56170. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
  56171. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
  56172. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
  56173. a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
  56174. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
  56175. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
  56176. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
  56177. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
  56178. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
  56179. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
  56180. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
  56181. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
  56182. d = md5hh(d, a, b, c, x[i], 11, -358537222);
  56183. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
  56184. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
  56185. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
  56186. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
  56187. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
  56188. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
  56189. a = md5ii(a, b, c, d, x[i], 6, -198630844);
  56190. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
  56191. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
  56192. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
  56193. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
  56194. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
  56195. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
  56196. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
  56197. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
  56198. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
  56199. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
  56200. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
  56201. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
  56202. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
  56203. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
  56204. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
  56205. a = safeAdd(a, olda);
  56206. b = safeAdd(b, oldb);
  56207. c = safeAdd(c, oldc);
  56208. d = safeAdd(d, oldd);
  56209. }
  56210. return [a, b, c, d];
  56211. }
  56212. /*
  56213. * Convert an array bytes to an array of little-endian words
  56214. * Characters >255 have their high-byte silently ignored.
  56215. */
  56216. function bytesToWords(input) {
  56217. if (input.length === 0) {
  56218. return [];
  56219. }
  56220. const length8 = input.length * 8;
  56221. const output = new Uint32Array(getOutputLength(length8));
  56222. for (let i = 0; i < length8; i += 8) {
  56223. output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
  56224. }
  56225. return output;
  56226. }
  56227. /*
  56228. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  56229. * to work around bugs in some JS interpreters.
  56230. */
  56231. function safeAdd(x, y) {
  56232. const lsw = (x & 0xffff) + (y & 0xffff);
  56233. const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  56234. return msw << 16 | lsw & 0xffff;
  56235. }
  56236. /*
  56237. * Bitwise rotate a 32-bit number to the left.
  56238. */
  56239. function bitRotateLeft(num, cnt) {
  56240. return num << cnt | num >>> 32 - cnt;
  56241. }
  56242. /*
  56243. * These functions implement the four basic operations the algorithm uses.
  56244. */
  56245. function md5cmn(q, a, b, x, s, t) {
  56246. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
  56247. }
  56248. function md5ff(a, b, c, d, x, s, t) {
  56249. return md5cmn(b & c | ~b & d, a, b, x, s, t);
  56250. }
  56251. function md5gg(a, b, c, d, x, s, t) {
  56252. return md5cmn(b & d | c & ~d, a, b, x, s, t);
  56253. }
  56254. function md5hh(a, b, c, d, x, s, t) {
  56255. return md5cmn(b ^ c ^ d, a, b, x, s, t);
  56256. }
  56257. function md5ii(a, b, c, d, x, s, t) {
  56258. return md5cmn(c ^ (b | ~d), a, b, x, s, t);
  56259. }
  56260. var _default = md5;
  56261. exports.default = _default;
  56262. },{}],530:[function(require,module,exports){
  56263. "use strict";
  56264. Object.defineProperty(exports, "__esModule", {
  56265. value: true
  56266. });
  56267. exports.default = void 0;
  56268. var _default = '00000000-0000-0000-0000-000000000000';
  56269. exports.default = _default;
  56270. },{}],531:[function(require,module,exports){
  56271. "use strict";
  56272. Object.defineProperty(exports, "__esModule", {
  56273. value: true
  56274. });
  56275. exports.default = void 0;
  56276. var _validate = _interopRequireDefault(require("./validate.js"));
  56277. function _interopRequireDefault(obj) {
  56278. return obj && obj.__esModule ? obj : {
  56279. default: obj
  56280. };
  56281. }
  56282. function parse(uuid) {
  56283. if (!(0, _validate.default)(uuid)) {
  56284. throw TypeError('Invalid UUID');
  56285. }
  56286. let v;
  56287. const arr = new Uint8Array(16); // Parse ########-....-....-....-............
  56288. arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
  56289. arr[1] = v >>> 16 & 0xff;
  56290. arr[2] = v >>> 8 & 0xff;
  56291. arr[3] = v & 0xff; // Parse ........-####-....-....-............
  56292. arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
  56293. arr[5] = v & 0xff; // Parse ........-....-####-....-............
  56294. arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
  56295. arr[7] = v & 0xff; // Parse ........-....-....-####-............
  56296. arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
  56297. arr[9] = v & 0xff; // Parse ........-....-....-....-############
  56298. // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
  56299. arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
  56300. arr[11] = v / 0x100000000 & 0xff;
  56301. arr[12] = v >>> 24 & 0xff;
  56302. arr[13] = v >>> 16 & 0xff;
  56303. arr[14] = v >>> 8 & 0xff;
  56304. arr[15] = v & 0xff;
  56305. return arr;
  56306. }
  56307. var _default = parse;
  56308. exports.default = _default;
  56309. },{"./validate.js":541}],532:[function(require,module,exports){
  56310. "use strict";
  56311. Object.defineProperty(exports, "__esModule", {
  56312. value: true
  56313. });
  56314. exports.default = void 0;
  56315. var _default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
  56316. exports.default = _default;
  56317. },{}],533:[function(require,module,exports){
  56318. "use strict";
  56319. Object.defineProperty(exports, "__esModule", {
  56320. value: true
  56321. });
  56322. exports.default = rng;
  56323. // Unique ID creation requires a high quality random # generator. In the browser we therefore
  56324. // require the crypto API and do not support built-in fallback to lower quality random number
  56325. // generators (like Math.random()).
  56326. let getRandomValues;
  56327. const rnds8 = new Uint8Array(16);
  56328. function rng() {
  56329. // lazy load so that environments that need to polyfill have a chance to do so
  56330. if (!getRandomValues) {
  56331. // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
  56332. // find the complete implementation of crypto (msCrypto) on IE11.
  56333. getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
  56334. if (!getRandomValues) {
  56335. throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
  56336. }
  56337. }
  56338. return getRandomValues(rnds8);
  56339. }
  56340. },{}],534:[function(require,module,exports){
  56341. "use strict";
  56342. Object.defineProperty(exports, "__esModule", {
  56343. value: true
  56344. });
  56345. exports.default = void 0;
  56346. // Adapted from Chris Veness' SHA1 code at
  56347. // http://www.movable-type.co.uk/scripts/sha1.html
  56348. function f(s, x, y, z) {
  56349. switch (s) {
  56350. case 0:
  56351. return x & y ^ ~x & z;
  56352. case 1:
  56353. return x ^ y ^ z;
  56354. case 2:
  56355. return x & y ^ x & z ^ y & z;
  56356. case 3:
  56357. return x ^ y ^ z;
  56358. }
  56359. }
  56360. function ROTL(x, n) {
  56361. return x << n | x >>> 32 - n;
  56362. }
  56363. function sha1(bytes) {
  56364. const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
  56365. const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  56366. if (typeof bytes === 'string') {
  56367. const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
  56368. bytes = [];
  56369. for (let i = 0; i < msg.length; ++i) {
  56370. bytes.push(msg.charCodeAt(i));
  56371. }
  56372. } else if (!Array.isArray(bytes)) {
  56373. // Convert Array-like to Array
  56374. bytes = Array.prototype.slice.call(bytes);
  56375. }
  56376. bytes.push(0x80);
  56377. const l = bytes.length / 4 + 2;
  56378. const N = Math.ceil(l / 16);
  56379. const M = new Array(N);
  56380. for (let i = 0; i < N; ++i) {
  56381. const arr = new Uint32Array(16);
  56382. for (let j = 0; j < 16; ++j) {
  56383. arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
  56384. }
  56385. M[i] = arr;
  56386. }
  56387. M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
  56388. M[N - 1][14] = Math.floor(M[N - 1][14]);
  56389. M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
  56390. for (let i = 0; i < N; ++i) {
  56391. const W = new Uint32Array(80);
  56392. for (let t = 0; t < 16; ++t) {
  56393. W[t] = M[i][t];
  56394. }
  56395. for (let t = 16; t < 80; ++t) {
  56396. W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
  56397. }
  56398. let a = H[0];
  56399. let b = H[1];
  56400. let c = H[2];
  56401. let d = H[3];
  56402. let e = H[4];
  56403. for (let t = 0; t < 80; ++t) {
  56404. const s = Math.floor(t / 20);
  56405. const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
  56406. e = d;
  56407. d = c;
  56408. c = ROTL(b, 30) >>> 0;
  56409. b = a;
  56410. a = T;
  56411. }
  56412. H[0] = H[0] + a >>> 0;
  56413. H[1] = H[1] + b >>> 0;
  56414. H[2] = H[2] + c >>> 0;
  56415. H[3] = H[3] + d >>> 0;
  56416. H[4] = H[4] + e >>> 0;
  56417. }
  56418. return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff];
  56419. }
  56420. var _default = sha1;
  56421. exports.default = _default;
  56422. },{}],535:[function(require,module,exports){
  56423. "use strict";
  56424. Object.defineProperty(exports, "__esModule", {
  56425. value: true
  56426. });
  56427. exports.default = void 0;
  56428. var _validate = _interopRequireDefault(require("./validate.js"));
  56429. function _interopRequireDefault(obj) {
  56430. return obj && obj.__esModule ? obj : {
  56431. default: obj
  56432. };
  56433. }
  56434. /**
  56435. * Convert array of 16 byte values to UUID string format of the form:
  56436. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  56437. */
  56438. const byteToHex = [];
  56439. for (let i = 0; i < 256; ++i) {
  56440. byteToHex.push((i + 0x100).toString(16).substr(1));
  56441. }
  56442. function stringify(arr) {
  56443. let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  56444. // Note: Be careful editing this code! It's been tuned for performance
  56445. // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  56446. const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
  56447. // of the following:
  56448. // - One or more input array values don't map to a hex octet (leading to
  56449. // "undefined" in the uuid)
  56450. // - Invalid input values for the RFC `version` or `variant` fields
  56451. if (!(0, _validate.default)(uuid)) {
  56452. throw TypeError('Stringified UUID is invalid');
  56453. }
  56454. return uuid;
  56455. }
  56456. var _default = stringify;
  56457. exports.default = _default;
  56458. },{"./validate.js":541}],536:[function(require,module,exports){
  56459. "use strict";
  56460. Object.defineProperty(exports, "__esModule", {
  56461. value: true
  56462. });
  56463. exports.default = void 0;
  56464. var _rng = _interopRequireDefault(require("./rng.js"));
  56465. var _stringify = _interopRequireDefault(require("./stringify.js"));
  56466. function _interopRequireDefault(obj) {
  56467. return obj && obj.__esModule ? obj : {
  56468. default: obj
  56469. };
  56470. }
  56471. // **`v1()` - Generate time-based UUID**
  56472. //
  56473. // Inspired by https://github.com/LiosK/UUID.js
  56474. // and http://docs.python.org/library/uuid.html
  56475. let _nodeId;
  56476. let _clockseq; // Previous uuid creation time
  56477. let _lastMSecs = 0;
  56478. let _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
  56479. function v1(options, buf, offset) {
  56480. let i = buf && offset || 0;
  56481. const b = buf || new Array(16);
  56482. options = options || {};
  56483. let node = options.node || _nodeId;
  56484. let clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
  56485. // specified. We do this lazily to minimize issues related to insufficient
  56486. // system entropy. See #189
  56487. if (node == null || clockseq == null) {
  56488. const seedBytes = options.random || (options.rng || _rng.default)();
  56489. if (node == null) {
  56490. // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
  56491. node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
  56492. }
  56493. if (clockseq == null) {
  56494. // Per 4.2.2, randomize (14 bit) clockseq
  56495. clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
  56496. }
  56497. } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
  56498. // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
  56499. // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
  56500. // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
  56501. let msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
  56502. // cycle to simulate higher resolution clock
  56503. let nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
  56504. const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
  56505. if (dt < 0 && options.clockseq === undefined) {
  56506. clockseq = clockseq + 1 & 0x3fff;
  56507. } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
  56508. // time interval
  56509. if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
  56510. nsecs = 0;
  56511. } // Per 4.2.1.2 Throw error if too many uuids are requested
  56512. if (nsecs >= 10000) {
  56513. throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
  56514. }
  56515. _lastMSecs = msecs;
  56516. _lastNSecs = nsecs;
  56517. _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
  56518. msecs += 12219292800000; // `time_low`
  56519. const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
  56520. b[i++] = tl >>> 24 & 0xff;
  56521. b[i++] = tl >>> 16 & 0xff;
  56522. b[i++] = tl >>> 8 & 0xff;
  56523. b[i++] = tl & 0xff; // `time_mid`
  56524. const tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
  56525. b[i++] = tmh >>> 8 & 0xff;
  56526. b[i++] = tmh & 0xff; // `time_high_and_version`
  56527. b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
  56528. b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
  56529. b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
  56530. b[i++] = clockseq & 0xff; // `node`
  56531. for (let n = 0; n < 6; ++n) {
  56532. b[i + n] = node[n];
  56533. }
  56534. return buf || (0, _stringify.default)(b);
  56535. }
  56536. var _default = v1;
  56537. exports.default = _default;
  56538. },{"./rng.js":533,"./stringify.js":535}],537:[function(require,module,exports){
  56539. "use strict";
  56540. Object.defineProperty(exports, "__esModule", {
  56541. value: true
  56542. });
  56543. exports.default = void 0;
  56544. var _v = _interopRequireDefault(require("./v35.js"));
  56545. var _md = _interopRequireDefault(require("./md5.js"));
  56546. function _interopRequireDefault(obj) {
  56547. return obj && obj.__esModule ? obj : {
  56548. default: obj
  56549. };
  56550. }
  56551. const v3 = (0, _v.default)('v3', 0x30, _md.default);
  56552. var _default = v3;
  56553. exports.default = _default;
  56554. },{"./md5.js":529,"./v35.js":538}],538:[function(require,module,exports){
  56555. "use strict";
  56556. Object.defineProperty(exports, "__esModule", {
  56557. value: true
  56558. });
  56559. exports.default = _default;
  56560. exports.URL = exports.DNS = void 0;
  56561. var _stringify = _interopRequireDefault(require("./stringify.js"));
  56562. var _parse = _interopRequireDefault(require("./parse.js"));
  56563. function _interopRequireDefault(obj) {
  56564. return obj && obj.__esModule ? obj : {
  56565. default: obj
  56566. };
  56567. }
  56568. function stringToBytes(str) {
  56569. str = unescape(encodeURIComponent(str)); // UTF8 escape
  56570. const bytes = [];
  56571. for (let i = 0; i < str.length; ++i) {
  56572. bytes.push(str.charCodeAt(i));
  56573. }
  56574. return bytes;
  56575. }
  56576. const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
  56577. exports.DNS = DNS;
  56578. const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
  56579. exports.URL = URL;
  56580. function _default(name, version, hashfunc) {
  56581. function generateUUID(value, namespace, buf, offset) {
  56582. if (typeof value === 'string') {
  56583. value = stringToBytes(value);
  56584. }
  56585. if (typeof namespace === 'string') {
  56586. namespace = (0, _parse.default)(namespace);
  56587. }
  56588. if (namespace.length !== 16) {
  56589. throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
  56590. } // Compute hash of namespace and value, Per 4.3
  56591. // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
  56592. // hashfunc([...namespace, ... value])`
  56593. let bytes = new Uint8Array(16 + value.length);
  56594. bytes.set(namespace);
  56595. bytes.set(value, namespace.length);
  56596. bytes = hashfunc(bytes);
  56597. bytes[6] = bytes[6] & 0x0f | version;
  56598. bytes[8] = bytes[8] & 0x3f | 0x80;
  56599. if (buf) {
  56600. offset = offset || 0;
  56601. for (let i = 0; i < 16; ++i) {
  56602. buf[offset + i] = bytes[i];
  56603. }
  56604. return buf;
  56605. }
  56606. return (0, _stringify.default)(bytes);
  56607. } // Function#name is not settable on some platforms (#270)
  56608. try {
  56609. generateUUID.name = name; // eslint-disable-next-line no-empty
  56610. } catch (err) {} // For CommonJS default export support
  56611. generateUUID.DNS = DNS;
  56612. generateUUID.URL = URL;
  56613. return generateUUID;
  56614. }
  56615. },{"./parse.js":531,"./stringify.js":535}],539:[function(require,module,exports){
  56616. "use strict";
  56617. Object.defineProperty(exports, "__esModule", {
  56618. value: true
  56619. });
  56620. exports.default = void 0;
  56621. var _rng = _interopRequireDefault(require("./rng.js"));
  56622. var _stringify = _interopRequireDefault(require("./stringify.js"));
  56623. function _interopRequireDefault(obj) {
  56624. return obj && obj.__esModule ? obj : {
  56625. default: obj
  56626. };
  56627. }
  56628. function v4(options, buf, offset) {
  56629. options = options || {};
  56630. const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  56631. rnds[6] = rnds[6] & 0x0f | 0x40;
  56632. rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
  56633. if (buf) {
  56634. offset = offset || 0;
  56635. for (let i = 0; i < 16; ++i) {
  56636. buf[offset + i] = rnds[i];
  56637. }
  56638. return buf;
  56639. }
  56640. return (0, _stringify.default)(rnds);
  56641. }
  56642. var _default = v4;
  56643. exports.default = _default;
  56644. },{"./rng.js":533,"./stringify.js":535}],540:[function(require,module,exports){
  56645. "use strict";
  56646. Object.defineProperty(exports, "__esModule", {
  56647. value: true
  56648. });
  56649. exports.default = void 0;
  56650. var _v = _interopRequireDefault(require("./v35.js"));
  56651. var _sha = _interopRequireDefault(require("./sha1.js"));
  56652. function _interopRequireDefault(obj) {
  56653. return obj && obj.__esModule ? obj : {
  56654. default: obj
  56655. };
  56656. }
  56657. const v5 = (0, _v.default)('v5', 0x50, _sha.default);
  56658. var _default = v5;
  56659. exports.default = _default;
  56660. },{"./sha1.js":534,"./v35.js":538}],541:[function(require,module,exports){
  56661. "use strict";
  56662. Object.defineProperty(exports, "__esModule", {
  56663. value: true
  56664. });
  56665. exports.default = void 0;
  56666. var _regex = _interopRequireDefault(require("./regex.js"));
  56667. function _interopRequireDefault(obj) {
  56668. return obj && obj.__esModule ? obj : {
  56669. default: obj
  56670. };
  56671. }
  56672. function validate(uuid) {
  56673. return typeof uuid === 'string' && _regex.default.test(uuid);
  56674. }
  56675. var _default = validate;
  56676. exports.default = _default;
  56677. },{"./regex.js":532}],542:[function(require,module,exports){
  56678. "use strict";
  56679. Object.defineProperty(exports, "__esModule", {
  56680. value: true
  56681. });
  56682. exports.default = void 0;
  56683. var _validate = _interopRequireDefault(require("./validate.js"));
  56684. function _interopRequireDefault(obj) {
  56685. return obj && obj.__esModule ? obj : {
  56686. default: obj
  56687. };
  56688. }
  56689. function version(uuid) {
  56690. if (!(0, _validate.default)(uuid)) {
  56691. throw TypeError('Invalid UUID');
  56692. }
  56693. return parseInt(uuid.substr(14, 1), 16);
  56694. }
  56695. var _default = version;
  56696. exports.default = _default;
  56697. },{"./validate.js":541}],543:[function(require,module,exports){
  56698. "use strict";
  56699. /**
  56700. * Character classes and associated utilities for the 5th edition of XML 1.0.
  56701. *
  56702. * @author Louis-Dominique Dubeau
  56703. * @license MIT
  56704. * @copyright Louis-Dominique Dubeau
  56705. */
  56706. Object.defineProperty(exports, "__esModule", {
  56707. value: true
  56708. });
  56709. //
  56710. // Fragments.
  56711. //
  56712. exports.CHAR = "\t\n\r -\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
  56713. exports.S = " \t\r\n";
  56714. // tslint:disable-next-line:max-line-length
  56715. exports.NAME_START_CHAR = ":A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
  56716. exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\u00B7\u0300-\u036F\u203F-\u2040";
  56717. //
  56718. // Regular expressions.
  56719. //
  56720. exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
  56721. exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
  56722. exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
  56723. exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
  56724. exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
  56725. exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
  56726. var TAB = 9;
  56727. var NL = 0xA;
  56728. var CR = 0xD;
  56729. var SPACE = 0x20;
  56730. //
  56731. // Lists.
  56732. //
  56733. /** All characters in the ``S`` production. */
  56734. exports.S_LIST = [SPACE, NL, CR, TAB];
  56735. /**
  56736. * Determines whether a codepoint matches the ``CHAR`` production.
  56737. *
  56738. * @param c The code point.
  56739. *
  56740. * @returns ``true`` if the codepoint matches ``CHAR``.
  56741. */
  56742. function isChar(c) {
  56743. return c >= SPACE && c <= 0xD7FF || c === NL || c === CR || c === TAB || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  56744. }
  56745. exports.isChar = isChar;
  56746. /**
  56747. * Determines whether a codepoint matches the ``S`` (space) production.
  56748. *
  56749. * @param c The code point.
  56750. *
  56751. * @returns ``true`` if the codepoint matches ``S``.
  56752. */
  56753. function isS(c) {
  56754. return c === SPACE || c === NL || c === CR || c === TAB;
  56755. }
  56756. exports.isS = isS;
  56757. /**
  56758. * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
  56759. *
  56760. * @param c The code point.
  56761. *
  56762. * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
  56763. */
  56764. function isNameStartChar(c) {
  56765. return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A || c === 0x3A || c === 0x5F || c === 0x200C || c === 0x200D || c >= 0xC0 && c <= 0xD6 || c >= 0xD8 && c <= 0xF6 || c >= 0x00F8 && c <= 0x02FF || c >= 0x0370 && c <= 0x037D || c >= 0x037F && c <= 0x1FFF || c >= 0x2070 && c <= 0x218F || c >= 0x2C00 && c <= 0x2FEF || c >= 0x3001 && c <= 0xD7FF || c >= 0xF900 && c <= 0xFDCF || c >= 0xFDF0 && c <= 0xFFFD || c >= 0x10000 && c <= 0xEFFFF;
  56766. }
  56767. exports.isNameStartChar = isNameStartChar;
  56768. /**
  56769. * Determines whether a codepoint matches the ``NAME_CHAR`` production.
  56770. *
  56771. * @param c The code point.
  56772. *
  56773. * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
  56774. */
  56775. function isNameChar(c) {
  56776. return isNameStartChar(c) || c >= 0x30 && c <= 0x39 || c === 0x2D || c === 0x2E || c === 0xB7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  56777. }
  56778. exports.isNameChar = isNameChar;
  56779. },{}],544:[function(require,module,exports){
  56780. "use strict";
  56781. /**
  56782. * Character classes and associated utilities for the 2nd edition of XML 1.1.
  56783. *
  56784. * @author Louis-Dominique Dubeau
  56785. * @license MIT
  56786. * @copyright Louis-Dominique Dubeau
  56787. */
  56788. Object.defineProperty(exports, "__esModule", {
  56789. value: true
  56790. });
  56791. //
  56792. // Fragments.
  56793. //
  56794. exports.CHAR = "\u0001-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF";
  56795. exports.RESTRICTED_CHAR = "\u0001-\u0008\u000B\u000C\u000E-\u001F\u007F-\u0084\u0086-\u009F";
  56796. exports.S = " \t\r\n";
  56797. // tslint:disable-next-line:max-line-length
  56798. exports.NAME_START_CHAR = ":A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
  56799. exports.NAME_CHAR = "-" + exports.NAME_START_CHAR + ".0-9\u00B7\u0300-\u036F\u203F-\u2040";
  56800. //
  56801. // Regular expressions.
  56802. //
  56803. exports.CHAR_RE = new RegExp("^[" + exports.CHAR + "]$", "u");
  56804. exports.RESTRICTED_CHAR_RE = new RegExp("^[" + exports.RESTRICTED_CHAR + "]$", "u");
  56805. exports.S_RE = new RegExp("^[" + exports.S + "]+$", "u");
  56806. exports.NAME_START_CHAR_RE = new RegExp("^[" + exports.NAME_START_CHAR + "]$", "u");
  56807. exports.NAME_CHAR_RE = new RegExp("^[" + exports.NAME_CHAR + "]$", "u");
  56808. exports.NAME_RE = new RegExp("^[" + exports.NAME_START_CHAR + "][" + exports.NAME_CHAR + "]*$", "u");
  56809. exports.NMTOKEN_RE = new RegExp("^[" + exports.NAME_CHAR + "]+$", "u");
  56810. var TAB = 9;
  56811. var NL = 0xA;
  56812. var CR = 0xD;
  56813. var SPACE = 0x20;
  56814. //
  56815. // Lists.
  56816. //
  56817. /** All characters in the ``S`` production. */
  56818. exports.S_LIST = [SPACE, NL, CR, TAB];
  56819. /**
  56820. * Determines whether a codepoint matches the ``CHAR`` production.
  56821. *
  56822. * @param c The code point.
  56823. *
  56824. * @returns ``true`` if the codepoint matches ``CHAR``.
  56825. */
  56826. function isChar(c) {
  56827. return c >= 0x0001 && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  56828. }
  56829. exports.isChar = isChar;
  56830. /**
  56831. * Determines whether a codepoint matches the ``RESTRICTED_CHAR`` production.
  56832. *
  56833. * @param c The code point.
  56834. *
  56835. * @returns ``true`` if the codepoint matches ``RESTRICTED_CHAR``.
  56836. */
  56837. function isRestrictedChar(c) {
  56838. return c >= 0x1 && c <= 0x8 || c === 0xB || c === 0xC || c >= 0xE && c <= 0x1F || c >= 0x7F && c <= 0x84 || c >= 0x86 && c <= 0x9F;
  56839. }
  56840. exports.isRestrictedChar = isRestrictedChar;
  56841. /**
  56842. * Determines whether a codepoint matches the ``CHAR`` production and does not
  56843. * match the ``RESTRICTED_CHAR`` production. ``isCharAndNotRestricted(x)`` is
  56844. * equivalent to ``isChar(x) && !isRestrictedChar(x)``. This function is faster
  56845. * than running the two-call equivalent.
  56846. *
  56847. * @param c The code point.
  56848. *
  56849. * @returns ``true`` if the codepoint matches ``CHAR`` and does not match
  56850. * ``RESTRICTED_CHAR``.
  56851. */
  56852. function isCharAndNotRestricted(c) {
  56853. return c === 0x9 || c === 0xA || c === 0xD || c > 0x1F && c < 0x7F || c === 0x85 || c > 0x9F && c <= 0xD7FF || c >= 0xE000 && c <= 0xFFFD || c >= 0x10000 && c <= 0x10FFFF;
  56854. }
  56855. exports.isCharAndNotRestricted = isCharAndNotRestricted;
  56856. /**
  56857. * Determines whether a codepoint matches the ``S`` (space) production.
  56858. *
  56859. * @param c The code point.
  56860. *
  56861. * @returns ``true`` if the codepoint matches ``S``.
  56862. */
  56863. function isS(c) {
  56864. return c === SPACE || c === NL || c === CR || c === TAB;
  56865. }
  56866. exports.isS = isS;
  56867. /**
  56868. * Determines whether a codepoint matches the ``NAME_START_CHAR`` production.
  56869. *
  56870. * @param c The code point.
  56871. *
  56872. * @returns ``true`` if the codepoint matches ``NAME_START_CHAR``.
  56873. */
  56874. // tslint:disable-next-line:cyclomatic-complexity
  56875. function isNameStartChar(c) {
  56876. return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A || c === 0x3A || c === 0x5F || c === 0x200C || c === 0x200D || c >= 0xC0 && c <= 0xD6 || c >= 0xD8 && c <= 0xF6 || c >= 0x00F8 && c <= 0x02FF || c >= 0x0370 && c <= 0x037D || c >= 0x037F && c <= 0x1FFF || c >= 0x2070 && c <= 0x218F || c >= 0x2C00 && c <= 0x2FEF || c >= 0x3001 && c <= 0xD7FF || c >= 0xF900 && c <= 0xFDCF || c >= 0xFDF0 && c <= 0xFFFD || c >= 0x10000 && c <= 0xEFFFF;
  56877. }
  56878. exports.isNameStartChar = isNameStartChar;
  56879. /**
  56880. * Determines whether a codepoint matches the ``NAME_CHAR`` production.
  56881. *
  56882. * @param c The code point.
  56883. *
  56884. * @returns ``true`` if the codepoint matches ``NAME_CHAR``.
  56885. */
  56886. function isNameChar(c) {
  56887. return isNameStartChar(c) || c >= 0x30 && c <= 0x39 || c === 0x2D || c === 0x2E || c === 0xB7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  56888. }
  56889. exports.isNameChar = isNameChar;
  56890. },{}],545:[function(require,module,exports){
  56891. "use strict";
  56892. /**
  56893. * Character class utilities for XML NS 1.0 edition 3.
  56894. *
  56895. * @author Louis-Dominique Dubeau
  56896. * @license MIT
  56897. * @copyright Louis-Dominique Dubeau
  56898. */
  56899. Object.defineProperty(exports, "__esModule", {
  56900. value: true
  56901. });
  56902. //
  56903. // Fragments.
  56904. //
  56905. // tslint:disable-next-line:max-line-length
  56906. exports.NC_NAME_START_CHAR = "A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\uD800\uDC00-\uDB7F\uDFFF";
  56907. exports.NC_NAME_CHAR = "-" + exports.NC_NAME_START_CHAR + ".0-9\u00B7\u0300-\u036F\u203F-\u2040";
  56908. //
  56909. // Regular expressions.
  56910. //
  56911. exports.NC_NAME_START_CHAR_RE = new RegExp("^[" + exports.NC_NAME_START_CHAR + "]$", "u");
  56912. exports.NC_NAME_CHAR_RE = new RegExp("^[" + exports.NC_NAME_CHAR + "]$", "u");
  56913. exports.NC_NAME_RE = new RegExp("^[" + exports.NC_NAME_START_CHAR + "][" + exports.NC_NAME_CHAR + "]*$", "u");
  56914. /**
  56915. * Determines whether a codepoint matches [[NC_NAME_START_CHAR]].
  56916. *
  56917. * @param c The code point.
  56918. *
  56919. * @returns ``true`` if the codepoint matches.
  56920. */
  56921. // tslint:disable-next-line:cyclomatic-complexity
  56922. function isNCNameStartChar(c) {
  56923. return c >= 0x41 && c <= 0x5A || c === 0x5F || c >= 0x61 && c <= 0x7A || c >= 0xC0 && c <= 0xD6 || c >= 0xD8 && c <= 0xF6 || c >= 0x00F8 && c <= 0x02FF || c >= 0x0370 && c <= 0x037D || c >= 0x037F && c <= 0x1FFF || c >= 0x200C && c <= 0x200D || c >= 0x2070 && c <= 0x218F || c >= 0x2C00 && c <= 0x2FEF || c >= 0x3001 && c <= 0xD7FF || c >= 0xF900 && c <= 0xFDCF || c >= 0xFDF0 && c <= 0xFFFD || c >= 0x10000 && c <= 0xEFFFF;
  56924. }
  56925. exports.isNCNameStartChar = isNCNameStartChar;
  56926. /**
  56927. * Determines whether a codepoint matches [[NC_NAME_CHAR]].
  56928. *
  56929. * @param c The code point.
  56930. *
  56931. * @returns ``true`` if the codepoint matches.
  56932. */
  56933. function isNCNameChar(c) {
  56934. return isNCNameStartChar(c) || c === 0x2D || c === 0x2E || c >= 0x30 && c <= 0x39 || c === 0x00B7 || c >= 0x0300 && c <= 0x036F || c >= 0x203F && c <= 0x2040;
  56935. }
  56936. exports.isNCNameChar = isNCNameChar;
  56937. },{}]},{},[15])(15)
  56938. });
  56939. //# sourceMappingURL=exceljs.js.map